Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
EcomDev_PHPUnit
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Open
EcomDev_PHPUnit
Commits
0d96e0b9
Commit
0d96e0b9
authored
Oct 26, 2013
by
Ivan Chepurnyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Loader container
parent
c4a4aaff
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
225 additions
and
0 deletions
+225
-0
app/code/community/EcomDev/PHPUnit/Model/Fixture/Loader/Container.php
...munity/EcomDev/PHPUnit/Model/Fixture/Loader/Container.php
+64
-0
app/code/community/EcomDev/PHPUnit/Model/Fixture/LoaderInterface.php
...mmunity/EcomDev/PHPUnit/Model/Fixture/LoaderInterface.php
+46
-0
app/code/community/EcomDev/PHPUnitTest/Test/Model/Fixture/Loader/Container.php
...omDev/PHPUnitTest/Test/Model/Fixture/Loader/Container.php
+115
-0
No files found.
app/code/community/EcomDev/PHPUnit/Model/Fixture/Loader/Container.php
0 → 100644
View file @
0d96e0b9
<?php
class
EcomDev_PHPUnit_Model_Fixture_Loader_Container
{
/**
* List of loaders by code
*
* @var EcomDev_PHPUnit_Model_Fixture_LoaderInterface[]
*/
protected
$_loaders
=
array
();
/**
* Returns loader by code
*
* If loader does not exists, it returns false
*
* @param $code
* @return bool|EcomDev_PHPUnit_Model_Fixture_LoaderInterface
*/
public
function
get
(
$code
)
{
if
(
!
$this
->
has
(
$code
))
{
return
false
;
}
return
$this
->
_loaders
[
$code
];
}
/**
* Adds a new loader to the container
*
* @param string $code
* @param EcomDev_PHPUnit_Model_Fixture_LoaderInterface $loader
* @return $this
*/
public
function
add
(
$code
,
EcomDev_PHPUnit_Model_Fixture_LoaderInterface
$loader
)
{
$this
->
_loaders
[
$code
]
=
$loader
;
return
$this
;
}
/**
* Removes a loader by code from container
*
* @param string $code
* @return $this
*/
public
function
remove
(
$code
)
{
unset
(
$this
->
_loaders
[
$code
]);
return
$this
;
}
/**
* Checks existance of the loader by container
*
* @param string $code
* @return bool
*/
public
function
has
(
$code
)
{
return
isset
(
$this
->
_loaders
[
$code
]);
}
}
\ No newline at end of file
app/code/community/EcomDev/PHPUnit/Model/Fixture/LoaderInterface.php
0 → 100644
View file @
0d96e0b9
<?php
/**
* The interface that will provide interface of the loader
* for a fixture processor
*
* This one should work like a single loader for each kind of data
*/
interface
EcomDev_PHPUnit_Model_Fixture_LoaderInterface
{
/**
* Overrides the data in the system for specified data
*
* It should realize default functionality
* for a default fixture processors
*
* @param array $data
* @return $this
* @throws InvalidArgumentException
*/
public
function
override
(
$data
);
/**
* This one should realize possibility to merge data with existing Magento data
*
* @param $data
* @return mixed
*/
public
function
merge
(
$data
);
/**
* Flushes the data that was added before loading
*
* @return mixed
*/
public
function
flush
();
/**
* Restores original data, that was modified by fixture flushing
*
* @return mixed
*/
public
function
restore
();
}
app/code/community/EcomDev/PHPUnitTest/Test/Model/Fixture/Loader/Container.php
0 → 100644
View file @
0d96e0b9
<?php
use
EcomDev_Utils_Reflection
as
ReflectionUtil
;
class
EcomDev_PHPUnitTest_Test_Model_Fixture_Loader_Container
extends
PHPUnit_Framework_TestCase
{
/**
* @var EcomDev_PHPUnit_Model_Fixture_Loader_Container
*/
protected
$_factory
;
protected
function
setUp
()
{
$this
->
_factory
=
new
EcomDev_PHPUnit_Model_Fixture_Loader_Container
();
}
public
function
testItHasLoadersProperty
()
{
$this
->
assertObjectHasAttribute
(
'_loaders'
,
$this
->
_factory
);
}
public
function
testItAddsMultipleLoaders
()
{
$loaders
=
$this
->
_generateLoaders
(
3
);
foreach
(
$loaders
as
$code
=>
$loader
)
{
$this
->
_factory
->
add
(
$code
,
$loader
);
}
$this
->
assertAttributeEquals
(
$loaders
,
'_loaders'
,
$this
->
_factory
);
}
public
function
testItRemovesLoaderByCode
()
{
$loaders
=
$this
->
_stubLoaders
(
3
);
$this
->
_factory
->
remove
(
'my_loader_2'
);
$this
->
assertAttributeEquals
(
array
(
'my_loader_1'
=>
$loaders
[
'my_loader_1'
],
'my_loader_3'
=>
$loaders
[
'my_loader_3'
]
),
'_loaders'
,
$this
->
_factory
);
}
public
function
testItChecksExistanceOfLoaderByCode
()
{
$this
->
_stubLoaders
(
3
);
$this
->
assertTrue
(
$this
->
_factory
->
has
(
'my_loader_1'
));
$this
->
assertTrue
(
$this
->
_factory
->
has
(
'my_loader_2'
));
$this
->
assertTrue
(
$this
->
_factory
->
has
(
'my_loader_3'
));
$this
->
_factory
->
remove
(
'my_loader_2'
);
$this
->
assertTrue
(
$this
->
_factory
->
has
(
'my_loader_1'
));
$this
->
assertFalse
(
$this
->
_factory
->
has
(
'my_loader_2'
));
$this
->
assertTrue
(
$this
->
_factory
->
has
(
'my_loader_3'
));
}
public
function
testItReturnsLoaderByCode
()
{
$loaders
=
$this
->
_stubLoaders
(
3
);
$this
->
assertSame
(
$loaders
[
'my_loader_3'
],
$this
->
_factory
->
get
(
'my_loader_3'
)
);
}
public
function
testItReturnsFalseIfLoaderDoesNotExist
()
{
$this
->
assertFalse
(
$this
->
_factory
->
get
(
'my_loader_1'
)
);
}
/**
* Generates loaders for tests
*
* @param int $count
* @return EcomDev_PHPUnit_Model_Fixture_Loader_Interface[]
*/
protected
function
_generateLoaders
(
$count
)
{
$loaders
=
array
();
for
(
$i
=
1
;
$i
<=
$count
;
$i
++
)
{
$loaders
[
'my_loader_'
.
$i
]
=
$this
->
getMockForAbstractClass
(
'EcomDev_PHPUnit_Model_Fixture_LoaderInterface'
);
}
return
$loaders
;
}
/**
* Generates and stubs loaders for tests
*
* @param int $count
* @return EcomDev_PHPUnit_Model_Fixture_LoaderInterface[]
*/
protected
function
_stubLoaders
(
$count
)
{
$loaders
=
$this
->
_generateLoaders
(
$count
);
ReflectionUtil
::
setRestrictedPropertyValue
(
$this
->
_factory
,
'_loaders'
,
$loaders
);
return
$loaders
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment