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
975e184b
Commit
975e184b
authored
Sep 10, 2012
by
Ivan Chepurnyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
! Some additional refactoring that is touching fixture models
parent
2cde68ad
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
105 additions
and
146 deletions
+105
-146
app/code/community/EcomDev/PHPUnit/Model/Expectation.php
app/code/community/EcomDev/PHPUnit/Model/Expectation.php
+1
-1
app/code/community/EcomDev/PHPUnit/Model/Fixture.php
app/code/community/EcomDev/PHPUnit/Model/Fixture.php
+20
-38
app/code/community/EcomDev/PHPUnit/Model/Test/Loadable/Interface.php
...mmunity/EcomDev/PHPUnit/Model/Test/Loadable/Interface.php
+2
-2
app/code/community/EcomDev/PHPUnit/Test/Case.php
app/code/community/EcomDev/PHPUnit/Test/Case.php
+4
-103
app/code/community/EcomDev/PHPUnit/Test/Case/Util.php
app/code/community/EcomDev/PHPUnit/Test/Case/Util.php
+44
-0
app/code/community/EcomDev/PHPUnit/Test/Listener.php
app/code/community/EcomDev/PHPUnit/Test/Listener.php
+34
-2
No files found.
app/code/community/EcomDev/PHPUnit/Model/Expectation.php
View file @
975e184b
...
...
@@ -122,7 +122,7 @@ class EcomDev_PHPUnit_Model_Expectation
*
* @see EcomDev_PHPUnit_Model_Test_Loadable_Interface::loadByTestCase()
*/
public
function
loadByTestCase
(
EcomDev_PHPUnit_Test_
Case
$testCase
)
public
function
loadByTestCase
(
PHPUnit_Framework_Test
Case
$testCase
)
{
$expectations
=
$testCase
->
getAnnotationByName
(
'loadExpectation'
);
...
...
app/code/community/EcomDev/PHPUnit/Model/Fixture.php
View file @
975e184b
...
...
@@ -278,23 +278,22 @@ class EcomDev_PHPUnit_Model_Fixture
/**
* Loads fixture files from test case annotations
*
* @param
EcomDev_PHPUnit_Test_
Case $testCase
* @return
EcomDev_PHPUnit_Model_Fixtur
e
* @param
PHPUnit_Framework_Test
Case $testCase
* @return
PHPUnit_Framework_TestCas
e
*/
public
function
loadByTestCase
(
EcomDev_PHPUnit_Test_
Case
$testCase
)
public
function
loadByTestCase
(
PHPUnit_Framework_Test
Case
$testCase
)
{
$fixtures
=
$testCase
->
getAnnotationByName
(
'loadFixture'
,
array
(
'class'
,
'method'
)
$cacheOptions
=
EcomDev_PHPUnit_Test_Case_Util
::
getAnnotationByNameFromClass
(
get_class
(
$testCase
),
'cache'
,
'method'
,
$testCase
->
getName
(
false
)
);
$cacheOptions
=
$testCase
->
getAnnotationByName
(
'cache'
,
'method'
);
$this
->
_parseCacheOptions
(
$cacheOptions
);
$this
->
_loadFixtureFiles
(
$fixtures
,
$testCase
);
$fixtures
=
EcomDev_PHPUnit_Test_Case_Util
::
getAnnotationByNameFromClass
(
get_class
(
$testCase
),
'loadFixture'
,
array
(
'class'
,
'method'
),
$testCase
->
getName
(
false
)
);
$this
->
_loadFixtureFiles
(
$fixtures
,
$testCase
);
return
$this
;
}
...
...
@@ -306,24 +305,16 @@ class EcomDev_PHPUnit_Model_Fixture
*/
public
function
loadForClass
(
$className
)
{
$
reflection
=
EcomDev_Utils_Reflection
::
getRelflection
(
$className
);
$method
=
$reflection
->
getMethod
(
'getAnnotationByNameFromClass'
);
$
cacheOptions
=
EcomDev_PHPUnit_Test_Case_Util
::
getAnnotationByNameFromClass
(
$className
,
'cache'
,
'class'
);
if
(
!
$method
instanceof
ReflectionMethod
)
{
throw
new
RuntimeException
(
'Unable to read class annotations, because it is not extended from EcomDev_PHPUnit_Test_Case'
);
}
$this
->
_parseCacheOptions
(
$cacheOptions
);
$fixtures
=
$method
->
invokeArg
s
(
null
,
array
(
$className
,
'loadSharedFixture'
,
'class'
)
$fixtures
=
EcomDev_PHPUnit_Test_Case_Util
::
getAnnotationByNameFromClas
s
(
$className
,
'loadSharedFixture'
,
'class'
);
$cacheOptions
=
$method
->
invokeArgs
(
null
,
array
(
$className
,
'cache'
,
'class'
)
);
$this
->
_parseCacheOptions
(
$cacheOptions
);
$this
->
_loadFixtureFiles
(
$fixtures
,
$className
);
return
$this
;
}
...
...
@@ -364,25 +355,16 @@ class EcomDev_PHPUnit_Model_Fixture
*/
protected
function
_loadFixtureFiles
(
array
$fixtures
,
$classOrInstance
)
{
$isShared
=
(
$this
->
isScopeShared
()
||
!
$classOrInstance
instanceof
EcomDev_PHPUnit_Test_
Case
);
$isShared
=
(
$this
->
isScopeShared
()
||
!
$classOrInstance
instanceof
PHPUnit_Framework_Test
Case
);
foreach
(
$fixtures
as
$fixture
)
{
if
(
empty
(
$fixture
)
&&
$isShared
)
{
$fixture
=
self
::
DEFAULT_SHARED_FIXTURE_NAME
;
}
elseif
(
empty
(
$fixture
))
{
$fixture
=
null
;
$fixture
=
$classOrInstance
->
getName
(
false
)
;
}
$filePath
=
false
;
if
(
$isShared
)
{
$reflection
=
EcomDev_Utils_Reflection
::
getRelflection
(
$classOrInstance
);
$method
=
$reflection
->
getMethod
(
'getYamlFilePathByClass'
);
if
(
$method
instanceof
ReflectionMethod
)
{
$filePath
=
$method
->
invokeArgs
(
null
,
array
(
$classOrInstance
,
'fixtures'
,
$fixture
));
}
}
else
{
$filePath
=
$classOrInstance
->
getYamlFilePath
(
'fixtures'
,
$fixture
);
}
$className
=
(
is_string
(
$classOrInstance
)
?
$classOrInstance
:
get_class
(
$classOrInstance
));
$filePath
=
EcomDev_PHPUnit_Test_Case_Util
::
getYamlFilePath
(
$className
,
'fixtures'
,
$fixture
);
if
(
!
$filePath
)
{
throw
new
RuntimeException
(
'Unable to load fixture for test'
);
...
...
app/code/community/EcomDev/PHPUnit/Model/Test/Loadable/Interface.php
View file @
975e184b
...
...
@@ -25,10 +25,10 @@ interface EcomDev_PHPUnit_Model_Test_Loadable_Interface
/**
* Loads external data by test case instance
*
* @param
EcomDev_PHPUnit_Test_
Case $testCase
* @param
PHPUnit_Framework_Test
Case $testCase
* @return EcomDev_PHPUnit_Model_Test_Loadable_Interface
*/
public
function
loadByTestCase
(
EcomDev_PHPUnit_Test_
Case
$testCase
);
public
function
loadByTestCase
(
PHPUnit_Framework_Test
Case
$testCase
);
/**
* Applies external data
...
...
app/code/community/EcomDev/PHPUnit/Test/Case.php
View file @
975e184b
...
...
@@ -643,28 +643,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
*/
protected
static
function
getFixture
()
{
$fixture
=
Mage
::
getSingleton
(
self
::
getLoadableClassAlias
(
'fixture'
,
self
::
XML_PATH_DEFAULT_FIXTURE_MODEL
)
);
if
(
!
$fixture
instanceof
EcomDev_PHPUnit_Model_Fixture_Interface
)
{
throw
new
RuntimeException
(
'Fixture model should implement EcomDev_PHPUnit_Model_Fixture_Interface interface'
);
}
$storage
=
Mage
::
registry
(
EcomDev_PHPUnit_Model_App
::
REGISTRY_PATH_SHARED_STORAGE
);
if
(
!
$storage
instanceof
Varien_Object
)
{
throw
new
RuntimeException
(
'Fixture storage object was not initialized during test application setup'
);
}
$fixture
->
setStorage
(
Mage
::
registry
(
EcomDev_PHPUnit_Model_App
::
REGISTRY_PATH_SHARED_STORAGE
)
);
return
$fixture
;
return
EcomDev_PHPUnit_Test_Case_Util
::
getFixture
(
get_called_class
());
}
/**
...
...
@@ -722,7 +701,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
$name
=
$this
->
getName
(
false
);
}
return
self
::
getYamlFilePathByClass
(
get_called_class
(),
$type
,
$name
);
return
EcomDev_PHPUnit_Test_Case_Util
::
getYamlFilePath
(
get_called_class
(),
$type
,
$name
);
}
/**
...
...
@@ -734,39 +713,11 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
* @param string $type type of YAML data (fixtures,expectations,dataproviders)
* @param string $name the file name for loading
* @return string|boolean
* @depracated since 0.3.0
*/
public
static
function
getYamlFilePathByClass
(
$className
,
$type
,
$name
)
{
if
(
strrpos
(
$name
,
'.yaml'
)
!==
strlen
(
$name
)
-
5
)
{
$name
.=
'.yaml'
;
}
$classFileObject
=
new
SplFileInfo
(
EcomDev_Utils_Reflection
::
getRelflection
(
$className
)
->
getFileName
()
);
// When prefixed with ~/ or ~My_Module/, load from the module's Test/<type> directory
if
(
preg_match
(
'#^~(?<module>[^/]*)/(?<path>.*)$#'
,
$name
,
$matches
))
{
$name
=
$matches
[
'path'
];
if
(
!
empty
(
$matches
[
'module'
]))
{
$moduleName
=
$matches
[
'module'
];
}
else
{
$moduleName
=
substr
(
$className
,
0
,
strpos
(
$className
,
'_Test_'
));;
}
$filePath
=
Mage
::
getModuleDir
(
''
,
$moduleName
)
.
DS
.
'Test'
.
DS
;
}
// Otherwise load from the Class/<type> directory
else
{
$filePath
=
$classFileObject
->
getPath
()
.
DS
.
$classFileObject
->
getBasename
(
'.php'
)
.
DS
;
}
$filePath
.=
$type
.
DS
.
$name
;
if
(
file_exists
(
$filePath
))
{
return
$filePath
;
}
return
false
;
return
EcomDev_PHPUnit_Test_Case_Util
::
getYamlFilePath
(
$className
,
$type
,
$name
);
}
/**
...
...
@@ -777,38 +728,10 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
*/
protected
function
setUp
()
{
self
::
getFixture
()
->
setScope
(
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_LOCAL
)
->
loadByTestCase
(
$this
);
$annotations
=
$this
->
getAnnotations
();
self
::
getFixture
()
->
setOptions
(
$annotations
[
'method'
])
->
apply
();
$this
->
app
()
->
resetDispatchedEvents
();
parent
::
setUp
();
}
/**
* Initializes test environment for subset of tests
*
*/
public
static
function
setUpBeforeClass
()
{
self
::
getFixture
()
->
setScope
(
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_SHARED
)
->
loadForClass
(
get_called_class
());
$annotations
=
PHPUnit_Util_Test
::
parseTestMethodAnnotations
(
get_called_class
()
);
self
::
getFixture
()
->
setOptions
(
$annotations
[
'class'
])
->
apply
();
parent
::
setUpBeforeClass
();
}
/**
* Implements default data provider functionality,
* returns array data loaded from Yaml file with the same name as test method
...
...
@@ -859,35 +782,13 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
$this
->
_originalStore
=
null
;
}
if
(
$this
->
getExpectation
()
->
isLoaded
())
{
$this
->
getExpectation
()
->
discard
();
}
$this
->
app
()
->
getConfig
()
->
flushReplaceInstanceCreation
();
$this
->
app
()
->
getLayout
()
->
flushReplaceBlockCreation
();
foreach
(
$this
->
_replacedRegistry
as
$registryPath
=>
$originalValue
)
{
$this
->
app
()
->
replaceRegistry
(
$registryPath
,
$originalValue
);
}
self
::
getFixture
()
->
setScope
(
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_LOCAL
)
->
discard
();
// Clear applied fixture
parent
::
tearDown
();
}
/**
* Clean up all the shared fixture data
*
* @return void
*/
public
static
function
tearDownAfterClass
()
{
self
::
getFixture
()
->
setScope
(
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_SHARED
)
->
discard
();
parent
::
tearDownAfterClass
();
}
}
app/code/community/EcomDev/PHPUnit/Test/Case/Util.php
View file @
975e184b
...
...
@@ -169,6 +169,50 @@ class EcomDev_PHPUnit_Test_Case_Util
return
$fixture
;
}
/**
* Loads YAML file from directory inside of the unit test class or
* the directory inside the module directory if name is prefixed with ~/
* or from another module if name is prefixed with ~My_Module/
*
* @param string $className class name for looking fixture files
* @param string $type type of YAML data (fixtures,expectations,dataproviders)
* @param string $name the file name for loading
* @return string|boolean
*/
public
static
function
getYamlFilePath
(
$className
,
$type
,
$name
)
{
if
(
strrpos
(
$name
,
'.yaml'
)
!==
strlen
(
$name
)
-
5
)
{
$name
.=
'.yaml'
;
}
$classFileObject
=
new
SplFileInfo
(
EcomDev_Utils_Reflection
::
getRelflection
(
$className
)
->
getFileName
()
);
// When prefixed with ~/ or ~My_Module/, load from the module's Test/<type> directory
if
(
preg_match
(
'#^~(?<module>[^/]*)/(?<path>.*)$#'
,
$name
,
$matches
))
{
$name
=
$matches
[
'path'
];
if
(
!
empty
(
$matches
[
'module'
]))
{
$moduleName
=
$matches
[
'module'
];
}
else
{
$moduleName
=
substr
(
$className
,
0
,
strpos
(
$className
,
'_Test_'
));;
}
$filePath
=
Mage
::
getModuleDir
(
''
,
$moduleName
)
.
DS
.
'Test'
.
DS
;
}
// Otherwise load from the Class/<type> directory
else
{
$filePath
=
$classFileObject
->
getPath
()
.
DS
.
$classFileObject
->
getBasename
(
'.php'
)
.
DS
;
}
$filePath
.=
$type
.
DS
.
$name
;
if
(
file_exists
(
$filePath
))
{
return
$filePath
;
}
return
false
;
}
}
\ No newline at end of file
app/code/community/EcomDev/PHPUnit/Test/Listener.php
View file @
975e184b
...
...
@@ -43,7 +43,17 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
}
if
(
EcomDev_Utils_Reflection
::
getRestrictedPropertyValue
(
$suite
,
'testCase'
))
{
EcomDev_PHPUnit_Test_Case_Util
::
getFixture
(
$suite
->
getName
())
->
setScope
(
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_SHARED
)
->
loadForClass
(
$suite
->
getName
());
$annotations
=
PHPUnit_Util_Test
::
parseTestMethodAnnotations
(
$suite
->
getName
()
);
EcomDev_PHPUnit_Test_Case_Util
::
getFixture
(
$suite
->
getName
())
->
setOptions
(
$annotations
[
'class'
])
->
apply
();
}
}
...
...
@@ -61,6 +71,12 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
$this
->
getAppReflection
()
->
getMethod
(
'discardTestScope'
)
->
invoke
(
null
);
}
}
if
(
EcomDev_Utils_Reflection
::
getRestrictedPropertyValue
(
$suite
,
'testCase'
))
{
EcomDev_PHPUnit_Test_Case_Util
::
getFixture
(
$suite
->
getName
())
->
setScope
(
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_SHARED
)
->
discard
();
}
}
/**
...
...
@@ -70,7 +86,15 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
*/
public
function
startTest
(
PHPUnit_Framework_Test
$test
)
{
// No action is required for now
if
(
$test
instanceof
PHPUnit_Framework_TestCase
)
{
EcomDev_PHPUnit_Test_Case_Util
::
getFixture
(
$test
->
getName
())
->
setScope
(
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_LOCAL
)
->
loadByTestCase
(
$test
);
$annotations
=
$this
->
getAnnotations
();
self
::
getFixture
()
->
setOptions
(
$annotations
[
'method'
])
->
apply
();
}
}
/**
...
...
@@ -81,7 +105,15 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
*/
public
function
endTest
(
PHPUnit_Framework_Test
$test
,
$time
)
{
// No action is required for now
if
(
$test
instanceof
PHPUnit_Framework_TestCase
)
{
EcomDev_PHPUnit_Test_Case_Util
::
getFixture
(
$test
->
getName
())
->
setScope
(
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_LOCAL
)
->
discard
();
// Clear applied fixture
if
(
EcomDev_PHPUnit_Test_Case_Util
::
getExpectation
(
$test
->
getName
())
->
isLoaded
())
{
EcomDev_PHPUnit_Test_Case_Util
::
getExpectation
(
$test
->
getName
())
->
discard
();
}
}
}
/**
...
...
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