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
358b1a68
Commit
358b1a68
authored
Jan 04, 2013
by
Ivan Chepurnyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
! Refactored test runners, fixture loaders, yaml file path resolvers
parent
0f3ea314
Changes
32
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
32 changed files
with
1835 additions
and
625 deletions
+1835
-625
UnitTests.php
UnitTests.php
+0
-11
app/code/community/EcomDev/PHPUnit/Model/App.php
app/code/community/EcomDev/PHPUnit/Model/App.php
+6
-24
app/code/community/EcomDev/PHPUnit/Model/Expectation.php
app/code/community/EcomDev/PHPUnit/Model/Expectation.php
+10
-9
app/code/community/EcomDev/PHPUnit/Model/Fixture.php
app/code/community/EcomDev/PHPUnit/Model/Fixture.php
+122
-312
app/code/community/EcomDev/PHPUnit/Model/Fixture/Interface.php
...ode/community/EcomDev/PHPUnit/Model/Fixture/Interface.php
+17
-0
app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Cache.php
...mmunity/EcomDev/PHPUnit/Model/Fixture/Processor/Cache.php
+87
-0
app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Config.php
...munity/EcomDev/PHPUnit/Model/Fixture/Processor/Config.php
+167
-0
app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Eav.php
...community/EcomDev/PHPUnit/Model/Fixture/Processor/Eav.php
+135
-0
app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Interface.php
...ity/EcomDev/PHPUnit/Model/Fixture/Processor/Interface.php
+50
-0
app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Scope.php
...mmunity/EcomDev/PHPUnit/Model/Fixture/Processor/Scope.php
+209
-0
app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Tables.php
...munity/EcomDev/PHPUnit/Model/Fixture/Processor/Tables.php
+117
-0
app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Vfs.php
...community/EcomDev/PHPUnit/Model/Fixture/Processor/Vfs.php
+62
-0
app/code/community/EcomDev/PHPUnit/Model/Yaml/Loader.php
app/code/community/EcomDev/PHPUnit/Model/Yaml/Loader.php
+114
-0
app/code/community/EcomDev/PHPUnit/Model/Yaml/Loader/Abstract.php
.../community/EcomDev/PHPUnit/Model/Yaml/Loader/Abstract.php
+54
-0
app/code/community/EcomDev/PHPUnit/Model/Yaml/Loader/Default.php
...e/community/EcomDev/PHPUnit/Model/Yaml/Loader/Default.php
+35
-0
app/code/community/EcomDev/PHPUnit/Model/Yaml/Loader/Global.php
...de/community/EcomDev/PHPUnit/Model/Yaml/Loader/Global.php
+47
-0
app/code/community/EcomDev/PHPUnit/Model/Yaml/Loader/Interface.php
...community/EcomDev/PHPUnit/Model/Yaml/Loader/Interface.php
+31
-0
app/code/community/EcomDev/PHPUnit/Model/Yaml/Loader/Module.php
...de/community/EcomDev/PHPUnit/Model/Yaml/Loader/Module.php
+42
-0
app/code/community/EcomDev/PHPUnit/Test/Case.php
app/code/community/EcomDev/PHPUnit/Test/Case.php
+18
-107
app/code/community/EcomDev/PHPUnit/Test/Case/Util.php
app/code/community/EcomDev/PHPUnit/Test/Case/Util.php
+376
-102
app/code/community/EcomDev/PHPUnit/Test/Listener.php
app/code/community/EcomDev/PHPUnit/Test/Listener.php
+35
-16
app/code/community/EcomDev/PHPUnit/Test/Suite.php
app/code/community/EcomDev/PHPUnit/Test/Suite.php
+2
-24
app/code/community/EcomDev/PHPUnit/Test/Suite/Group.php
app/code/community/EcomDev/PHPUnit/Test/Suite/Group.php
+1
-1
app/code/community/EcomDev/PHPUnit/bootstrap.php
app/code/community/EcomDev/PHPUnit/bootstrap.php
+24
-0
app/code/community/EcomDev/PHPUnit/etc/config.xml
app/code/community/EcomDev/PHPUnit/etc/config.xml
+17
-0
lib/EcomDev/PHPUnit/Constraint/Abstract.php
lib/EcomDev/PHPUnit/Constraint/Abstract.php
+1
-1
lib/EcomDev/PHPUnit/Constraint/Json.php
lib/EcomDev/PHPUnit/Constraint/Json.php
+6
-3
lib/EcomDev/PHPUnit/Constraint/Layout/Block.php
lib/EcomDev/PHPUnit/Constraint/Layout/Block.php
+1
-1
lib/EcomDev/Utils/Reflection.php
lib/EcomDev/Utils/Reflection.php
+20
-3
modman
modman
+2
-8
phpunit.xml.dist
phpunit.xml.dist
+7
-3
shell/ecomdev-phpunit-install.php
shell/ecomdev-phpunit-install.php
+20
-0
No files found.
UnitTests.php
deleted
100644 → 0
View file @
0f3ea314
<?php
/* @depracated since 0.3.0 */
require_once
'app/code/community/EcomDev/PHPUnit/Test/bootstrap.php'
;
class
UnitTests
extends
EcomDev_PHPUnit_Test_Suite
{
}
app/code/community/EcomDev/PHPUnit/Model/App.php
View file @
358b1a68
...
...
@@ -131,6 +131,7 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
* List of module names stored by class name
*
* @var array
* @deprecated since 0.3.0
*/
protected
$_moduleNameByClassName
=
array
();
...
...
@@ -402,7 +403,7 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
{
$className
=
(
string
)
$this
->
getConfig
()
->
getNode
(
$configPath
);
$reflection
=
EcomDev_Utils_Reflection
::
getRe
l
flection
(
$className
);
$reflection
=
EcomDev_Utils_Reflection
::
getReflection
(
$className
);
if
(
$interface
!==
null
&&
!
$reflection
->
implementsInterface
(
$interface
))
{
throw
new
RuntimeException
(
sprintf
(
'Invalid class name defined in configuration path %s, because %s does not implement %s interface'
,
...
...
@@ -443,31 +444,11 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
* @param string|object $className
* @throws RuntimeException if module name was not found for the passed class name
* @return string
* @deprecated since 0.3.0
*/
public
function
getModuleNameByClassName
(
$className
)
{
if
(
is_object
(
$className
))
{
$className
=
get_class
(
$className
);
}
if
(
!
isset
(
$this
->
_moduleNameByClassName
[
$className
]))
{
// Try to find the module name by class name
$moduleName
=
false
;
foreach
(
$this
->
getConfig
()
->
getNode
(
'modules'
)
->
children
()
as
$module
)
{
if
(
strpos
(
$className
,
$module
->
getName
())
===
0
)
{
$moduleName
=
$module
->
getName
();
break
;
}
}
if
(
!
$moduleName
)
{
throw
new
RuntimeException
(
'Cannot to find the module name for class name: '
.
$className
);
}
$this
->
setModuleNameForClassName
(
$className
,
$moduleName
);
}
return
$this
->
_moduleNameByClassName
[
$className
];
return
EcomDev_PHPUnit_Test_Case_Util
::
getModuleNameByClassName
(
$className
);
}
/**
...
...
@@ -478,10 +459,11 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
* @param string $className
* @param string $moduleName
* @return EcomDev_PHPUnit_Model_App
* @deprecated since 0.3.0
*/
public
function
setModuleNameForClassName
(
$className
,
$moduleName
)
{
$this
->
_moduleNameByClassName
[
$className
]
=
$moduleName
;
EcomDev_PHPUnit_Test_Case_Util
::
setModuleNameForClassName
(
$className
,
$moduleName
)
;
return
$this
;
}
...
...
app/code/community/EcomDev/PHPUnit/Model/Expectation.php
View file @
358b1a68
<?php
// Loading Spyc yaml parser,
// becuase Symfony component is not working propertly with nested
require_once
'Spyc/spyc.php'
;
class
EcomDev_PHPUnit_Model_Expectation
implements
EcomDev_PHPUnit_Model_Expectation_Interface
{
...
...
@@ -124,20 +120,25 @@ class EcomDev_PHPUnit_Model_Expectation
*/
public
function
loadByTestCase
(
PHPUnit_Framework_TestCase
$testCase
)
{
$expectations
=
$testCase
->
getAnnotationByName
(
'loadExpectation'
);
$expectations
=
EcomDev_PHPUnit_Test_Case_Util
::
getAnnotationByNameFromClass
(
get_class
(
$testCase
),
'loadExpectation'
,
array
(
'class'
,
'method'
),
$testCase
->
getName
(
false
)
);
if
(
!
$expectations
)
{
$expectations
[]
=
null
;
$expectations
[]
=
$testCase
->
getName
(
false
)
;
}
$expectationData
=
array
();
foreach
(
$expectations
as
$expectation
)
{
if
(
empty
(
$expectation
))
{
$expectation
=
null
;
$expectation
=
$testCase
->
getName
(
false
)
;
}
$expectationFile
=
$testCase
->
getYamlFilePath
(
'expectations'
,
$expectation
);
$expectationFile
=
EcomDev_PHPUnit_Test_Case_Util
::
getYamlLoader
(
get_class
(
$testCase
))
->
resolveFilePath
(
get_class
(
$testCase
),
EcomDev_PHPUnit_Model_Yaml_Loader
::
TYPE_EXPECTATION
,
$expectation
);
if
(
!
$expectationFile
)
{
$text
=
'There was no expectation defined for current test case'
;
...
...
@@ -148,7 +149,7 @@ class EcomDev_PHPUnit_Model_Expectation
}
$expectationData
=
array_merge_recursive
(
$expectationData
,
Spyc
::
YAMLL
oad
(
$expectationFile
)
$expectationData
,
EcomDev_PHPUnit_Test_Case_Util
::
getYamlLoader
()
->
l
oad
(
$expectationFile
)
);
}
...
...
app/code/community/EcomDev/PHPUnit/Model/Fixture.php
View file @
358b1a68
This diff is collapsed.
Click to expand it.
app/code/community/EcomDev/PHPUnit/Model/Fixture/Interface.php
View file @
358b1a68
...
...
@@ -36,6 +36,13 @@ interface EcomDev_PHPUnit_Model_Fixture_Interface extends EcomDev_PHPUnit_Model_
*/
public
function
setOptions
(
array
$options
);
/**
* Sets fixture options
*
* @return array
*/
public
function
getOptions
();
/**
* Sets storage for fixtures
*
...
...
@@ -106,6 +113,16 @@ interface EcomDev_PHPUnit_Model_Fixture_Interface extends EcomDev_PHPUnit_Model_
*/
public
function
loadForClass
(
$className
);
/**
* Sets fixture value
*
* @param string $key
* @param array[] $value
*
* @return EcomDev_PHPUnit_Model_Fixture_Interface
*/
public
function
setFixtureValue
(
$key
,
$value
);
/**
* Returns VFS wrapper instance
*
...
...
app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Cache.php
0 → 100644
View file @
358b1a68
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2012 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
class
EcomDev_PHPUnit_Model_Fixture_Processor_Cache
implements
EcomDev_PHPUnit_Model_Fixture_Processor_Interface
{
const
STORAGE_KEY
=
'cache_options'
;
/**
* Initializes cache options
*
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Cache
*/
public
function
initialize
(
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
$options
=
$fixture
->
getOptions
();
if
(
isset
(
$options
[
'cache'
]))
{
$cacheOptions
=
array
();
foreach
(
$options
[
'cache'
]
as
$annotation
)
{
list
(
$action
,
$cacheType
)
=
preg_split
(
'/\s+/'
,
trim
(
$annotation
));
$flag
=
(
$action
===
'off'
?
0
:
1
);
if
(
$cacheType
===
'all'
)
{
foreach
(
Mage
::
app
()
->
getCacheInstance
()
->
getTypes
()
as
$type
)
{
$cacheOptions
[
$type
->
getId
()]
=
$flag
;
}
}
else
{
$cacheOptions
[
$cacheType
]
=
$flag
;
}
}
$fixture
->
setFixtureValue
(
'cache_options'
,
$cacheOptions
);
}
return
$this
;
}
/**
* Apply cache options from the fixture data
*
* @param array $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Cache
*/
public
function
apply
(
array
$data
,
$key
,
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
$originalOptions
=
EcomDev_PHPUnit_Test_Case_Util
::
app
()
->
getCacheOptions
();
$fixture
->
setStorageData
(
self
::
STORAGE_KEY
,
$originalOptions
);
$data
+=
$originalOptions
;
EcomDev_PHPUnit_Test_Case_Util
::
app
()
->
setCacheOptions
(
$data
);
return
$this
;
}
/**
* Discard applied cache options
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Cache
*/
public
function
discard
(
array
$data
,
$key
,
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
EcomDev_PHPUnit_Test_Case_Util
::
app
()
->
setCacheOptions
(
$fixture
->
getStorageData
(
self
::
STORAGE_KEY
)
);
return
$this
;
}
}
\ No newline at end of file
app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Config.php
0 → 100644
View file @
358b1a68
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2012 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
class
EcomDev_PHPUnit_Model_Fixture_Processor_Config
implements
EcomDev_PHPUnit_Model_Fixture_Processor_Interface
{
/**
* Does nothing
*
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Config
*/
public
function
initialize
(
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
return
$this
;
}
/**
* Apply cache options from the fixture data
*
* @param array $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Config
*/
public
function
apply
(
array
$data
,
$key
,
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
$key
===
'config_xml'
?
$this
->
_applyConfigXml
(
$data
)
:
$this
->
_applyConfig
(
$data
);
return
$this
;
}
/**
* Applies fixture configuration values into Mage_Core_Model_Config
*
* @param array $configuration
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Config
* @throws InvalidArgumentException
*/
protected
function
_applyConfig
(
$configuration
)
{
if
(
!
is_array
(
$configuration
))
{
throw
new
InvalidArgumentException
(
'Configuration part should be an associative list'
);
}
Mage
::
getConfig
()
->
loadScopeSnapshot
();
foreach
(
$configuration
as
$path
=>
$value
)
{
$this
->
_setConfigNodeValue
(
$path
,
$value
);
}
Mage
::
getConfig
()
->
loadDb
();
// Flush website and store configuration caches
foreach
(
Mage
::
app
()
->
getWebsites
(
true
)
as
$website
)
{
EcomDev_Utils_Reflection
::
setRestrictedPropertyValue
(
$website
,
'_configCache'
,
array
()
);
}
foreach
(
Mage
::
app
()
->
getStores
(
true
)
as
$store
)
{
EcomDev_Utils_Reflection
::
setRestrictedPropertyValue
(
$store
,
'_configCache'
,
array
()
);
}
return
$this
;
}
/**
* Applies raw xml data to config node
*
* @param array $configuration
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Config
* @throws InvalidArgumentException
*/
protected
function
_applyConfigXml
(
$configuration
)
{
if
(
!
is_array
(
$configuration
))
{
throw
new
InvalidArgumentException
(
'Configuration part should be an associative list'
);
}
foreach
(
$configuration
as
$path
=>
$value
)
{
if
(
!
is_string
(
$value
))
{
throw
new
InvalidArgumentException
(
'Configuration value should be a valid xml string'
);
}
try
{
$xmlElement
=
new
Varien_Simplexml_Element
(
$value
);
}
catch
(
Exception
$e
)
{
throw
new
InvalidArgumentException
(
'Configuration value should be a valid xml string'
,
0
,
$e
);
}
$node
=
Mage
::
getConfig
()
->
getNode
(
$path
);
if
(
!
$node
)
{
throw
new
InvalidArgumentException
(
'Configuration value should be a valid xml string'
);
}
$node
->
extend
(
$xmlElement
,
true
);
}
return
$this
;
}
/**
* Discard applied cache options
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Config
*/
public
function
discard
(
array
$data
,
$key
,
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
$this
->
_restoreConfig
();
return
$this
;
}
/**
* Restores config to a previous configuration scope
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Config
*/
protected
function
_restoreConfig
()
{
Mage
::
getConfig
()
->
loadScopeSnapshot
();
Mage
::
getConfig
()
->
loadDb
();
return
$this
;
}
/**
* Sets configuration value
*
* @param string $path
* @param string $value
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Config
*/
protected
function
_setConfigNodeValue
(
$path
,
$value
)
{
if
((
$originalNode
=
Mage
::
getConfig
()
->
getNode
(
$path
))
&&
$originalNode
->
getAttribute
(
'backend_model'
))
{
$backendModel
=
$originalNode
->
getAttribute
(
'backend_model'
);
$backend
=
Mage
::
getModel
((
string
)
$backendModel
);
$backend
->
setPath
(
$path
)
->
setValue
(
$value
);
EcomDev_Utils_Reflection
::
invokeRestrictedMethod
(
$backend
,
'_beforeSave'
);
$value
=
$backend
->
getValue
();
}
Mage
::
getConfig
()
->
setNode
(
$path
,
$value
);
return
$this
;
}
}
\ No newline at end of file
app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Eav.php
0 → 100644
View file @
358b1a68
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2012 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
class
EcomDev_PHPUnit_Model_Fixture_Processor_Eav
extends
Mage_Core_Model_Abstract
implements
EcomDev_PHPUnit_Model_Fixture_Processor_Interface
{
const
STORAGE_KEY
=
'entities'
;
// Configuration path for eav loaders
const
XML_PATH_FIXTURE_EAV_LOADERS
=
'phpunit/suite/fixture/eav'
;
// Default eav loader class node in loaders configuration
const
DEFAULT_EAV_LOADER_NODE
=
'default'
;
// Default eav loader class alias
const
DEFAULT_EAV_LOADER_CLASS
=
'ecomdev_phpunit/fixture_eav_default'
;
/**
* Initialize fixture resource model
*/
protected
function
_construct
()
{
$this
->
_init
(
'ecomdev_phpunit/fixture'
);
}
/**
* Does nothing
*
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Eav
*/
public
function
initialize
(
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
return
$this
;
}
/**
* Retrieves eav loader for a particular entity type
*
* @param string $entityType
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract
*/
protected
function
_getEavLoader
(
$entityType
)
{
$loaders
=
Mage
::
getConfig
()
->
getNode
(
self
::
XML_PATH_FIXTURE_EAV_LOADERS
);
if
(
isset
(
$loaders
->
$entityType
))
{
$classAlias
=
(
string
)
$loaders
->
$entityType
;
}
elseif
(
isset
(
$loaders
->
{
self
::
DEFAULT_EAV_LOADER_NODE
}))
{
$classAlias
=
(
string
)
$loaders
->
{
self
::
DEFAULT_EAV_LOADER_NODE
};
}
else
{
$classAlias
=
self
::
DEFAULT_EAV_LOADER_CLASS
;
}
return
Mage
::
getResourceSingleton
(
$classAlias
);
}
/**
* Apply eav records from fixture file
*
* @param array $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Eav
*/
public
function
apply
(
array
$data
,
$key
,
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
$this
->
getResource
()
->
beginTransaction
();
foreach
(
$data
as
$entityType
=>
$values
)
{
$this
->
_getEavLoader
(
$entityType
)
->
setFixture
(
$fixture
)
->
setOptions
(
$fixture
->
getOptions
())
->
loadEntity
(
$entityType
,
$values
);
}
$this
->
getResource
()
->
commit
();
$fixture
->
setStorageData
(
self
::
STORAGE_KEY
,
array_keys
(
$data
));
return
$this
;
}
/**
* Discard applied eav records
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Eav
*/
public
function
discard
(
array
$data
,
$key
,
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
$ignoreCleanUp
=
array
();
// Ignore cleaning of entities if shared fixture loaded something for them
if
(
$fixture
->
isScopeLocal
()
&&
$fixture
->
getStorageData
(
self
::
STORAGE_KEY
,
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_SHARED
))
{
$ignoreCleanUp
=
$fixture
->
getStorageData
(
self
::
STORAGE_KEY
,
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_SHARED
);
}
$this
->
getResource
()
->
beginTransaction
();
foreach
(
array_keys
(
$data
)
as
$entityType
)
{
if
(
in_array
(
$entityType
,
$ignoreCleanUp
))
{
continue
;
}
$this
->
_getEavLoader
(
$entityType
)
->
cleanEntity
(
$entityType
);
}
$this
->
getResource
()
->
commit
();
return
$this
;
}
}
\ No newline at end of file
app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Interface.php
0 → 100644
View file @
358b1a68
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2012 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
interface
EcomDev_PHPUnit_Model_Fixture_Processor_Interface
{
/**
* Applies data from fixture file
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Interface
*/
public
function
apply
(
array
$data
,
$key
,
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
);
/**
* Discards data from fixture file
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Interface
*/
public
function
discard
(
array
$data
,
$key
,
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
);
/**
* Initializes fixture processor before applying data
*
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Interface
*/
public
function
initialize
(
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
);
}
app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Scope.php
0 → 100644
View file @
358b1a68
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2012 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
class
EcomDev_PHPUnit_Model_Fixture_Processor_Scope
implements
EcomDev_PHPUnit_Model_Fixture_Processor_Interface
{
const
STORAGE_KEY
=
'scope'
;
/**
* Model aliases by type of scope
*
* @var array
*/
protected
$modelByType
=
array
(
'store'
=>
'core/store'
,
'group'
=>
'core/store_group'
,
'website'
=>
'core/website'
);
/**
* Does nothing
*
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Scope
*/
public
function
initialize
(
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
return
$this
;
}
/**
* Handle scope row data
*
* @param string $type
* @param array $row
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @return boolean|Mage_Core_Model_Abstract
*/
protected
function
_handleScopeRow
(
$type
,
$row
,
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
$previousScope
=
array
();
if
(
$fixture
->
isScopeLocal
()
&&
$fixture
->
getStorageData
(
self
::
STORAGE_KEY
,
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_SHARED
)
!==
null
)
{
$previousScope
=
$fixture
->
getStorageData
(
self
::
STORAGE_KEY
,
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_SHARED
);
}
if
(
isset
(
$previousScope
[
$type
][
$row
[
$type
.
'_id'
]]))
{
return
false
;
}
$scopeModel
=
Mage
::
getModel
(
$this
->
modelByType
[
$type
]);
$scopeModel
->
setData
(
$row
);
// Change property for saving new objects with specified ids
EcomDev_Utils_Reflection
::
setRestrictedPropertyValues
(
$scopeModel
->
getResource
(),
array
(
'_isPkAutoIncrement'
=>
false
)
);
try
{
$scopeModel
->
isObjectNew
(
true
);
$scopeModel
->
save
();
}
catch
(
Exception
$e
)
{
Mage
::
logException
(
$e
);
// Skip duplicated key violation, since it might be a problem
// of previous run with fatal error
// Revert changed property
EcomDev_Utils_Reflection
::
setRestrictedPropertyValues
(
$scopeModel
->
getResource
(),
array
(
'_isPkAutoIncrement'
=>
true
)
);
// Load to make possible deletion
$scopeModel
->
load
(
$row
[
$type
.
'_id'
]);
}
// Revert changed property
EcomDev_Utils_Reflection
::
setRestrictedPropertyValues
(
$scopeModel
->
getResource
(),
array
(
'_isPkAutoIncrement'
=>
true
)
);
return
$scopeModel
;
}
/**
* Validate scope data
*
* @param array $types
* @throws RuntimeException
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Scope
*/
protected
function
_validateScope
(
$types
)
{
foreach
(
$types
as
$type
=>
$rows
)
{
if
(
!
isset
(
$this
->
modelByType
[
$type
]))
{
throw
new
RuntimeException
(
sprintf
(
'Unknown "%s" scope type specified'
,
$type
));
}
foreach
(
$rows
as
$rowNumber
=>
$row
)
{
if
(
!
isset
(
$row
[
$type
.
'_id'
]))
{
throw
new
RuntimeException
(
sprintf
(
'Missing primary key for "%s" scope entity at #%d row'
,
$type
,
$rowNumber
+
1
));
}
}
}
return
$this
;
}
/**
* Apply scoped data (store, website, group)
*
* @param array $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
*
* @throws RuntimeException
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Scope
*/
public
function
apply
(
array
$data
,
$key
,
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
EcomDev_PHPUnit_Test_Case_Util
::
app
()
->
disableEvents
();
// Validate received fixture data
$this
->
_validateScope
(
$data
);
if
(
$fixture
->
getStorageData
(
self
::
STORAGE_KEY
)
!==
null
)
{
throw
new
RuntimeException
(
'Scope data was not cleared after previous test'
);
}
$scopeModels
=
array
();
foreach
(
$data
as
$type
=>
$rows
)
{
foreach
(
$rows
as
$row
)
{
$model
=
$this
->
_handleScopeRow
(
$type
,
$row
,
$fixture
);
if
(
$model
)
{
$scopeModels
[
$type
][
$model
->
getId
()]
=
$model
;
}
}
}
$fixture
->
setStorageData
(
self
::
STORAGE_KEY
,
$scopeModels
);
EcomDev_PHPUnit_Test_Case_Util
::
app
()
->
enableEvents
();
EcomDev_PHPUnit_Test_Case_Util
::
app
()
->
reinitStores
();
return
$this
;
}
/**
* Discard applied scope models
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Scope
*/
public
function
discard
(
array
$data
,
$key
,
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
if
(
$fixture
->
getStorageData
(
self
::
STORAGE_KEY
)
===
null
)
{
return
$this
;
}
EcomDev_PHPUnit_Test_Case_Util
::
app
()
->
disableEvents
();
$scope
=
array_reverse
(
$fixture
->
getStorageData
(
self
::
STORAGE_KEY
));
foreach
(
$scope
as
$models
)
{
foreach
(
$models
as
$model
)
{
$model
->
delete
();
}
}
$fixture
->
setStorageData
(
self
::
STORAGE_KEY
,
null
);
EcomDev_PHPUnit_Test_Case_Util
::
app
()
->
getCache
()
->
clean
(
Zend_Cache
::
CLEANING_MODE_MATCHING_ANY_TAG
,
array
(
Mage_Core_Model_Store
::
CACHE_TAG
,
Mage_Core_Model_Store_Group
::
CACHE_TAG
,
Mage_Core_Model_Website
::
CACHE_TAG
)
);
EcomDev_PHPUnit_Test_Case_Util
::
app
()
->
enableEvents
();
EcomDev_PHPUnit_Test_Case_Util
::
app
()
->
reinitStores
();
return
$this
;
}
}
\ No newline at end of file
app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Tables.php
0 → 100644
View file @
358b1a68
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2012 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
class
EcomDev_PHPUnit_Model_Fixture_Processor_Tables
extends
Mage_Core_Model_Abstract
implements
EcomDev_PHPUnit_Model_Fixture_Processor_Interface
{
const
STORAGE_KEY
=
'tables'
;
/**
* Initialize fixture resource model
*/
protected
function
_construct
()
{
$this
->
_init
(
'ecomdev_phpunit/fixture'
);
}
/**
* Does nothing
*
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Tables
*/
public
function
initialize
(
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
return
$this
;
}
/**
* Apply tables records from fixture file
*
* @param array $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Tables
*/
public
function
apply
(
array
$data
,
$key
,
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
$ignoreCleanUp
=
array
();
// Ignore cleaning of tables if shared fixture loaded something
if
(
$fixture
->
isScopeLocal
()
&&
$fixture
->
getStorageData
(
self
::
STORAGE_KEY
,
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_SHARED
))
{
$ignoreCleanUp
=
array_keys
(
$fixture
->
getStorageData
(
self
::
STORAGE_KEY
,
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_SHARED
));
}
$this
->
getResource
()
->
beginTransaction
();
foreach
(
$data
as
$tableEntity
=>
$tableData
)
{
if
(
!
in_array
(
$tableEntity
,
$ignoreCleanUp
))
{
$this
->
getResource
()
->
cleanTable
(
$tableEntity
);
}
if
(
!
empty
(
$tableData
))
{
$this
->
getResource
()
->
loadTableData
(
$tableEntity
,
$tableData
);
}
}
$this
->
getResource
()
->
commit
();
$fixture
->
setStorageData
(
self
::
STORAGE_KEY
,
$data
);
return
$this
;
}
/**
* Discard applied table records
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Tables
*/
public
function
discard
(
array
$data
,
$key
,
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
$restoreTableData
=
array
();
// Data for tables used in shared fixture
if
(
$fixture
->
isScopeLocal
()
&&
$fixture
->
getStorageData
(
self
::
STORAGE_KEY
,
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_SHARED
))
{
$restoreTableData
=
$fixture
->
getStorageData
(
self
::
STORAGE_KEY
,
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_SHARED
);
}
$this
->
getResource
()
->
beginTransaction
();
foreach
(
array_keys
(
$data
)
as
$tableEntity
)
{
$this
->
getResource
()
->
cleanTable
(
$tableEntity
);
if
(
isset
(
$restoreTableData
[
$tableEntity
]))
{
$this
->
getResource
()
->
loadTableData
(
$tableEntity
,
$restoreTableData
[
$tableEntity
]);
}
}
$this
->
getResource
()
->
commit
();
$fixture
->
setStorageData
(
self
::
STORAGE_KEY
,
null
);
return
$this
;
}
}
\ No newline at end of file
app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Vfs.php
0 → 100644
View file @
358b1a68
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2012 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
class
EcomDev_PHPUnit_Model_Fixture_Processor_Vfs
implements
EcomDev_PHPUnit_Model_Fixture_Processor_Interface
{
/**
* Does nothing
*
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Cache
*/
public
function
initialize
(
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
return
$this
;
}
/**
* Apply virtual file system structure
*
* @param array $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Cache
*/
public
function
apply
(
array
$data
,
$key
,
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
$fixture
->
getVfs
()
->
apply
(
$data
,
$fixture
->
isScopeLocal
());
return
$this
;
}
/**
* Discard applied virtual file system structure
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Cache
*/
public
function
discard
(
array
$data
,
$key
,
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
$fixture
->
getVfs
()
->
discard
();
return
$this
;
}
}
\ No newline at end of file
app/code/community/EcomDev/PHPUnit/Model/Yaml/Loader.php
0 → 100644
View file @
358b1a68
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2012 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
// Loading Spyc yaml parser,
// because Symfony component is not working properly with nested structures
require_once
'Spyc/spyc.php'
;
class
EcomDev_PHPUnit_Model_Yaml_Loader
{
const
XML_PATH_YAML_FILE_LOADERS
=
'phpunit/suite/yaml/loaders'
;
const
TYPE_FIXTURE
=
'fixtures'
;
const
TYPE_PROVIDER
=
'providers'
;
const
TYPE_EXPECTATION
=
'expectations'
;
/**
* YAML file loaders
*
* @var EcomDev_PHPUnit_Model_Yaml_Loader_Interface[]
*/
protected
$_loaders
=
array
();
/**
* Returns arrays of loaders
*
* @return EcomDev_PHPUnit_Model_Yaml_Loader_Interface[]
*/
public
function
getLoaders
()
{
if
(
empty
(
$this
->
_loaders
))
{
$this
->
_initLoaders
();
}
return
$this
->
_loaders
;
}
/**
* Adds a loader to list of loders
*
* @param EcomDev_PHPUnit_Model_Yaml_Loader_Interface $loader
* @return EcomDev_PHPUnit_Model_Yaml_Loader
*/
public
function
addLoader
(
EcomDev_PHPUnit_Model_Yaml_Loader_Interface
$loader
)
{
$this
->
_loaders
[]
=
$loader
;
return
$this
;
}
/**
* Initializes current loaders from configuration
*
* @return EcomDev_PHPUnit_Model_Yaml_Loader
*/
protected
function
_initLoaders
()
{
if
(
$loadersNode
=
Mage
::
getConfig
()
->
getNode
(
self
::
XML_PATH_YAML_FILE_LOADERS
))
{
foreach
(
$loadersNode
->
children
()
as
$loader
)
{
$loaderInstance
=
Mage
::
getSingleton
((
string
)
$loader
);
$this
->
addLoader
(
$loaderInstance
);
}
}
return
$this
;
}
/**
* Finds YAML file or returns false
*
* It invokes all added loaders for loading a yaml file
*
* @param string $className
* @param string $type
* @param string $name
* @return string|bool
*/
public
function
resolveFilePath
(
$className
,
$type
,
$name
)
{
$filePath
=
false
;
foreach
(
$this
->
getLoaders
()
as
$loader
)
{
// Break load file resolve path on first found file
if
(
$filePath
=
$loader
->
resolveFilePath
(
$name
,
$className
,
$type
))
{
break
;
}
}
return
$filePath
;
}
/**
* Loads YAML file content
*
* @param string $filePath
* @return array
*/
public
function
load
(
$filePath
)
{
return
Spyc
::
YAMLLoad
(
$filePath
);
}
}
app/code/community/EcomDev/PHPUnit/Model/Yaml/Loader/Abstract.php
0 → 100644
View file @
358b1a68
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2012 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
abstract
class
EcomDev_PHPUnit_Model_Yaml_Loader_Abstract
implements
EcomDev_PHPUnit_Model_Yaml_Loader_Interface
{
/**
* Resolves YAML file path based on its filename,
* if file is not found, it should return false
*
* @param string $fileName name of the file
* @param string $relatedClassName class name from which load of yaml file is invoked
* @param string $type type of Yaml file (provider, fixture, expectation)
* @return string|bool
*/
public
function
resolveFilePath
(
$fileName
,
$relatedClassName
,
$type
)
{
if
(
strrpos
(
$fileName
,
'.yaml'
)
!==
strlen
(
$fileName
)
-
5
)
{
$fileName
.=
'.yaml'
;
}
$filePath
=
$this
->
_getFilePath
(
$fileName
,
$relatedClassName
,
$type
);
if
(
$filePath
&&
file_exists
(
$filePath
))
{
return
$filePath
;
}
return
false
;
}
/**
* Returns processed file path
*
* @param string $fileName
* @param string $relatedClassName
* @param string $type
* @return string
*/
abstract
protected
function
_getFilePath
(
$fileName
,
$relatedClassName
,
$type
);
}
\ No newline at end of file
app/code/community/EcomDev/PHPUnit/Model/Yaml/Loader/Default.php
0 → 100644
View file @
358b1a68
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2012 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
class
EcomDev_PHPUnit_Model_Yaml_Loader_Default
extends
EcomDev_PHPUnit_Model_Yaml_Loader_Abstract
{
/**
* Returns processed file path
*
* @param string $fileName
* @param string $relatedClassName
* @param string $type
* @return string|bool
*/
protected
function
_getFilePath
(
$fileName
,
$relatedClassName
,
$type
)
{
$reflection
=
EcomDev_Utils_Reflection
::
getReflection
(
$relatedClassName
);
$fileObject
=
new
SplFileInfo
(
$reflection
->
getFileName
());
return
$fileObject
->
getPath
()
.
DS
.
$fileObject
->
getBasename
(
'.php'
)
.
DS
.
$type
.
DS
.
$fileName
;
}
}
\ No newline at end of file
app/code/community/EcomDev/PHPUnit/Model/Yaml/Loader/Global.php
0 → 100644
View file @
358b1a68
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2012 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
class
EcomDev_PHPUnit_Model_Yaml_Loader_Global
extends
EcomDev_PHPUnit_Model_Yaml_Loader_Abstract
{
/**
* Returns processed file path
*
* @param string $fileName
* @param string $relatedClassName
* @param string $type
* @return string|bool
*/
protected
function
_getFilePath
(
$fileName
,
$relatedClassName
,
$type
)
{
$reflection
=
EcomDev_Utils_Reflection
::
getReflection
(
$relatedClassName
);
$fileObject
=
new
SplFileInfo
(
$reflection
->
getFileName
());
$basePath
=
$fileObject
->
getPath
();
// While base path is within a base directory of Magento installment
while
(
strpos
(
$basePath
,
Mage
::
getBaseDir
())
&&
!
is_dir
(
$basePath
.
DS
.
$type
))
{
$basePath
=
dirname
(
$basePath
);
}
if
(
basename
(
$basePath
))
{
return
$basePath
.
DS
.
$type
.
DS
.
$fileName
;
}
return
false
;
}
}
\ No newline at end of file
app/code/community/EcomDev/PHPUnit/Model/Yaml/Loader/Interface.php
0 → 100644
View file @
358b1a68
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2012 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
interface
EcomDev_PHPUnit_Model_Yaml_Loader_Interface
{
/**
* Resolves YAML file path based on its filename,
* if file is not found, it should return false
*
* @param string $fileName name of the file
* @param string $relatedClassName class name from which load of yaml file is invoked
* @param string $type type of Yaml file (provider, fixture, expectation)
* @return string|bool
*/
public
function
resolveFilePath
(
$fileName
,
$relatedClassName
,
$type
);
}
\ No newline at end of file
app/code/community/EcomDev/PHPUnit/Model/Yaml/Loader/Module.php
0 → 100644
View file @
358b1a68
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
* @author Colin Mollenhour <http://colin.mollenhour.com>
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
class
EcomDev_PHPUnit_Model_Yaml_Loader_Module
extends
EcomDev_PHPUnit_Model_Yaml_Loader_Abstract
{
/**
* Returns processed file path based on module test directory
*
* @param string $fileName
* @param string $relatedClassName
* @param string $type
* @return string|bool
*/
protected
function
_getFilePath
(
$fileName
,
$relatedClassName
,
$type
)
{
$moduleName
=
EcomDev_PHPUnit_Test_Case_Util
::
getModuleNameByClassName
(
$relatedClassName
);
if
(
preg_match
(
'#^~(?<module>[^/]*)/(?<fileName>.*)$#'
,
$fileName
,
$matches
))
{
$fileName
=
$matches
[
'fileName'
];
if
(
!
empty
(
$matches
[
'module'
]))
{
$moduleName
=
$matches
[
'module'
];
}
}
$filePath
=
Mage
::
getModuleDir
(
''
,
$moduleName
)
.
DS
.
'Test'
.
DS
.
$type
.
DS
.
$fileName
;
return
false
;
}
}
app/code/community/EcomDev/PHPUnit/Test/Case.php
View file @
358b1a68
...
...
@@ -16,10 +16,6 @@
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
// Loading Spyc yaml parser,
// becuase Symfony component is not working propertly with nested associations
require_once
'Spyc/spyc.php'
;
/**
* Basic test case class
*
...
...
@@ -42,6 +38,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
* List of system registry values replaced by test case
*
* @var array
* @deprecated since 0.3.0
*/
protected
$_replacedRegistry
=
array
();
...
...
@@ -58,6 +55,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
* if was set in test method
*
* @var Mage_Core_Model_Store
* @deprecated since 0.3.0
*/
protected
$_originalStore
=
null
;
...
...
@@ -90,8 +88,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
/**
* Asserts that event was dispatched at least once
*
* @param string|array $event
* @param string $message
* @param array|string $eventName
*/
public
static
function
assertEventDispatched
(
$eventName
)
{
...
...
@@ -110,8 +107,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
/**
* Asserts that event was not dispatched
*
* @param string|array $event
* @param string $message
* @param string|array $eventName
*/
public
static
function
assertEventNotDispatched
(
$eventName
)
{
...
...
@@ -178,7 +174,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
* is matched expected JSON structure
*
* @param array $expectedValue
* @param stri
gn
$matchType
* @param stri
ng
$matchType
* @return EcomDev_PHPUnit_Constraint_Json
*/
public
static
function
matchesJson
(
array
$expectedValue
,
$matchType
=
EcomDev_PHPUnit_Constraint_Json
::
MATCH_AND
)
...
...
@@ -219,7 +215,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
* @param string $string
* @param array $expectedValue
* @param string $message
* @param stri
gn
$matchType
* @param stri
ng
$matchType
*/
public
static
function
assertJsonMatch
(
$string
,
array
$expectedValue
,
$message
=
''
,
$matchType
=
EcomDev_PHPUnit_Constraint_Json
::
MATCH_AND
)
...
...
@@ -327,35 +323,10 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
* @param string $type
* @param string $classAlias
* @param PHPUnit_Framework_MockObject_MockObject|PHPUnit_Framework_MockObject_MockBuilder $mock
* @return EcomDev_PHPUnit_Test_Case
*/
protected
function
replaceByMock
(
$type
,
$classAlias
,
$mock
)
{
if
(
$mock
instanceof
PHPUnit_Framework_MockObject_MockBuilder
)
{
$mock
=
$mock
->
getMock
();
}
elseif
(
!
$mock
instanceof
PHPUnit_Framework_MockObject_MockObject
)
{
throw
PHPUnit_Util_InvalidArgumentHelper
::
factory
(
1
,
'PHPUnit_Framework_MockObject_MockObject'
);
}
// Remove addition of /data suffix if version is more than 1.6.x
if
(
version_compare
(
Mage
::
getVersion
(),
'1.6.0.0'
,
'<'
)
&&
$type
==
'helper'
&&
strpos
(
$classAlias
,
'/'
)
===
false
)
{
$classAlias
.=
'/data'
;
}
if
(
in_array
(
$type
,
array
(
'model'
,
'resource_model'
)))
{
$this
->
app
()
->
getConfig
()
->
replaceInstanceCreation
(
$type
,
$classAlias
,
$mock
);
$type
=
str_replace
(
'model'
,
'singleton'
,
$type
);
}
elseif
(
$type
==
'block'
)
{
$this
->
app
()
->
getLayout
()
->
replaceBlockCreation
(
$classAlias
,
$mock
);
}
if
(
in_array
(
$type
,
array
(
'singleton'
,
'resource_singleton'
,
'helper'
)))
{
$registryPath
=
'_'
.
$type
.
'/'
.
$classAlias
;
$this
->
replaceRegistry
(
$registryPath
,
$mock
);
}
EcomDev_PHPUnit_Test_Case_Util
::
replaceByMock
(
$type
,
$classAlias
,
$mock
);
return
$this
;
}
...
...
@@ -364,14 +335,11 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
*
* @param string $key
* @param mixed $value
* @return EcomDev_PHPUnit_Test_Case
*/
protected
function
replaceRegistry
(
$key
,
$value
)
{
$oldValue
=
Mage
::
registry
(
$key
);
$this
->
app
()
->
replaceRegistry
(
$key
,
$value
);
$this
->
_replacedRegistry
[
$key
]
=
$oldValue
;
EcomDev_PHPUnit_Test_Case_Util
::
replaceRegistry
(
$key
,
$value
);
return
$this
;
}
...
...
@@ -379,31 +347,20 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
* Shortcut for expectation data object retrieval
* Can be called with arguments array or in usual method
*
* @param string|array $
pathForma
t
* @param mixed $arg1
* @param mixed $arg2 ...
* @param string|array $
firstArgumen
t
* @
optional @
param mixed $arg1
* @
optional @
param mixed $arg2 ...
* @return Varien_Object
*/
protected
function
expected
(
$firstArgument
=
null
)
{
if
(
!
$this
->
getExpectation
()
->
isLoaded
())
{
$this
->
getExpectation
()
->
loadByTestCase
(
$this
);
$this
->
getExpectation
()
->
apply
();
}
if
(
!
is_array
(
$firstArgument
))
{
$arguments
=
func_get_args
();
}
else
{
$arguments
=
$firstArgument
;
}
$pathFormat
=
null
;
if
(
$arguments
)
{
$pathFormat
=
array_shift
(
$arguments
);
}
return
$this
->
getExpectation
()
->
getDataObject
(
$pathFormat
,
$arguments
);
return
EcomDev_PHPUnit_Test_Case_Util
::
expected
(
$this
,
$arguments
);
}
/**
...
...
@@ -640,6 +597,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
* Retrieves fixture model singleton
*
* @return EcomDev_PHPUnit_Model_Fixture
* @deprecated since 0.3.0
*/
protected
static
function
getFixture
()
{
...
...
@@ -650,6 +608,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
* Returns expectation model singleton
*
* @return EcomDev_PHPUnit_Model_Expectation
* @deprecated since 0.3.0
*/
protected
function
getExpectation
()
{
...
...
@@ -668,7 +627,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
*/
protected
static
function
getLoadableClassAlias
(
$type
,
$configPath
)
{
return
EcomDev_PHPUnit_Test_Case
::
getLoadableClassAlias
(
get_called_class
(),
$type
,
$configPath
);
return
EcomDev_PHPUnit_Test_Case
_Util
::
getLoadableClassAlias
(
get_called_class
(),
$type
,
$configPath
);
}
/**
...
...
@@ -720,18 +679,6 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
return
EcomDev_PHPUnit_Test_Case_Util
::
getYamlFilePath
(
$className
,
$type
,
$name
);
}
/**
* Initializes a particular test environment
*
* (non-PHPdoc)
* @see PHPUnit_Framework_TestCase::setUp()
*/
protected
function
setUp
()
{
$this
->
app
()
->
resetDispatchedEvents
();
parent
::
setUp
();
}
/**
* Implements default data provider functionality,
* returns array data loaded from Yaml file with the same name as test method
...
...
@@ -741,15 +688,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
*/
public
function
dataProvider
(
$testName
)
{
$this
->
setName
(
$testName
);
$filePath
=
$this
->
getYamlFilePath
(
'providers'
);
$this
->
setName
(
null
);
if
(
!
$filePath
)
{
throw
new
RuntimeException
(
'Unable to load data provider for the current test'
);
}
return
Spyc
::
YAMLLoad
(
$filePath
);
return
EcomDev_PHPUnit_Test_Case_Util
::
dataProvider
(
get_called_class
(),
$testName
);
}
/**
...
...
@@ -760,35 +699,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
*/
public
function
setCurrentStore
(
$store
)
{
if
(
!
$this
->
_originalStore
)
{
$this
->
_originalStore
=
$this
->
app
()
->
getStore
();
}
$this
->
app
()
->
setCurrentStore
(
$this
->
app
()
->
getStore
(
$store
)
);
EcomDev_PHPUnit_Test_Case_Util
::
setCurrentStore
(
$store
);
return
$this
;
}
/**
* Performs a clean up after a particular test was run
* (non-PHPdoc)
* @see PHPUnit_Framework_TestCase::tearDown()
*/
protected
function
tearDown
()
{
if
(
$this
->
_originalStore
)
{
// Remove store scope, that was set in test
$this
->
app
()
->
setCurrentStore
(
$this
->
_originalStore
);
$this
->
_originalStore
=
null
;
}
$this
->
app
()
->
getConfig
()
->
flushReplaceInstanceCreation
();
$this
->
app
()
->
getLayout
()
->
flushReplaceBlockCreation
();
foreach
(
$this
->
_replacedRegistry
as
$registryPath
=>
$originalValue
)
{
$this
->
app
()
->
replaceRegistry
(
$registryPath
,
$originalValue
);
parent
::
tearDown
();
}
}
app/code/community/EcomDev/PHPUnit/Test/Case/Util.php
View file @
358b1a68
This diff is collapsed.
Click to expand it.
app/code/community/EcomDev/PHPUnit/Test/Listener.php
View file @
358b1a68
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2012 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
class
EcomDev_PHPUnit_Test_Listener
implements
PHPUnit_Framework_TestListener
{
...
...
@@ -20,7 +36,7 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
protected
function
getAppReflection
()
{
$appClass
=
(
string
)
Mage
::
getConfig
()
->
getNode
(
self
::
XML_PATH_UNIT_TEST_APP
);
$reflectionClass
=
EcomDev_Utils_Reflection
::
getRe
l
flection
(
$appClass
);
$reflectionClass
=
EcomDev_Utils_Reflection
::
getReflection
(
$appClass
);
return
$reflectionClass
;
}
...
...
@@ -34,12 +50,12 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
{
if
(
$this
->
firstLevelTestSuite
===
null
)
{
// Apply app substitution for tests
if
(
$this
->
getAppReflection
()
->
hasMethod
(
'applyTestScope'
))
{
$this
->
getAppReflection
()
->
getMethod
(
'applyTestScope'
)
->
invoke
(
null
);
}
$this
->
firstLevelTestSuite
=
$suite
;
echo
'Starting suite...'
.
$suite
->
getName
();
}
if
(
EcomDev_Utils_Reflection
::
getRestrictedPropertyValue
(
$suite
,
'testCase'
))
{
...
...
@@ -64,19 +80,20 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
*/
public
function
endTestSuite
(
PHPUnit_Framework_TestSuite
$suite
)
{
if
(
EcomDev_Utils_Reflection
::
getRestrictedPropertyValue
(
$suite
,
'testCase'
))
{
EcomDev_PHPUnit_Test_Case_Util
::
getFixture
(
$suite
->
getName
())
->
setScope
(
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_SHARED
)
->
discard
();
}
if
(
$this
->
firstLevelTestSuite
===
$suite
)
{
$this
->
firstLevelTestSuite
=
null
;
echo
'Finishing test suite...'
.
$suite
->
getName
();
// Discard test scope app
if
(
$this
->
getAppReflection
()
->
hasMethod
(
'discardTestScope'
))
{
$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
();
}
}
/**
...
...
@@ -87,13 +104,15 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
public
function
startTest
(
PHPUnit_Framework_Test
$test
)
{
if
(
$test
instanceof
PHPUnit_Framework_TestCase
)
{
EcomDev_PHPUnit_Test_Case_Util
::
getFixture
(
$test
->
getName
(
))
EcomDev_PHPUnit_Test_Case_Util
::
getFixture
(
get_class
(
$test
))
->
setScope
(
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_LOCAL
)
->
loadByTestCase
(
$test
);
$annotations
=
$t
his
->
getAnnotations
();
self
::
getFixture
()
$annotations
=
$t
est
->
getAnnotations
();
EcomDev_PHPUnit_Test_Case_Util
::
getFixture
()
->
setOptions
(
$annotations
[
'method'
])
->
apply
();
EcomDev_PHPUnit_Test_Case_Util
::
setUp
();
}
}
...
...
@@ -106,13 +125,15 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
public
function
endTest
(
PHPUnit_Framework_Test
$test
,
$time
)
{
if
(
$test
instanceof
PHPUnit_Framework_TestCase
)
{
EcomDev_PHPUnit_Test_Case_Util
::
getFixture
(
$test
->
getName
(
))
EcomDev_PHPUnit_Test_Case_Util
::
getFixture
(
get_class
(
$test
))
->
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
();
if
(
EcomDev_PHPUnit_Test_Case_Util
::
getExpectation
(
get_class
(
$test
))
->
isLoaded
())
{
EcomDev_PHPUnit_Test_Case_Util
::
getExpectation
(
get_class
(
$test
))
->
discard
();
}
EcomDev_PHPUnit_Test_Case_Util
::
tearDown
();
}
}
...
...
@@ -158,8 +179,6 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
* @param PHPUnit_Framework_Test $test
* @param Exception $e
* @param float $time
*
* @since Method available since Release 3.0.0
*/
public
function
addSkippedTest
(
PHPUnit_Framework_Test
$test
,
Exception
$e
,
$time
)
{
...
...
app/code/community/EcomDev/PHPUnit/Test/Suite.php
View file @
358b1a68
...
...
@@ -16,7 +16,6 @@
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
/**
* Test suite for Magento
*
...
...
@@ -34,27 +33,6 @@ class EcomDev_PHPUnit_Test_Suite extends PHPUnit_Framework_TestSuite
const
CACHE_TAG
=
'ECOMDEV_PHPUNIT'
;
const
CACHE_TYPE
=
'ecomdev_phpunit'
;
/**
* Setting up test scope for Magento
* (non-PHPdoc)
* @see PHPUnit_Framework_TestSuite::setUp()
* @deprecated since 0.3.0
*/
protected
function
setUp
()
{
}
/**
* Returning Magento to the state before suite was run
* (non-PHPdoc)
* @see PHPUnit_Framework_TestSuite::tearDown()
*/
protected
function
tearDown
()
{
}
/**
* This method loads all available test suites for PHPUnit
*
...
...
@@ -64,7 +42,7 @@ class EcomDev_PHPUnit_Test_Suite extends PHPUnit_Framework_TestSuite
{
$groups
=
Mage
::
getConfig
()
->
getNode
(
self
::
XML_PATH_UNIT_TEST_GROUPS
);
$modules
=
Mage
::
getConfig
()
->
getNode
(
self
::
XML_PATH_UNIT_TEST_MODULES
);
$testSuiteClass
=
EcomDev_Utils_Reflection
::
getRe
l
flection
((
string
)
Mage
::
getConfig
()
->
getNode
(
self
::
XML_PATH_UNIT_TEST_SUITE
));
$testSuiteClass
=
EcomDev_Utils_Reflection
::
getReflection
((
string
)
Mage
::
getConfig
()
->
getNode
(
self
::
XML_PATH_UNIT_TEST_SUITE
));
if
(
!
$testSuiteClass
->
isSubclassOf
(
'EcomDev_PHPUnit_Test_Suite_Group'
))
{
new
RuntimeException
(
'Test Suite class should be extended from EcomDev_PHPUnit_Test_Suite_Group'
);
...
...
@@ -146,7 +124,7 @@ class EcomDev_PHPUnit_Test_Suite extends PHPUnit_Framework_TestSuite
// Add unit test case only
// if it is a valid class extended from EcomDev_PHPUnit_Test_Case
if
(
class_exists
(
$className
,
true
))
{
$reflectionClass
=
EcomDev_Utils_Reflection
::
getRe
l
flection
(
$className
);
$reflectionClass
=
EcomDev_Utils_Reflection
::
getReflection
(
$className
);
if
(
!
$reflectionClass
->
isSubclassOf
(
'EcomDev_PHPUnit_Test_Case'
)
||
$reflectionClass
->
isAbstract
())
{
continue
;
...
...
app/code/community/EcomDev/PHPUnit/Test/Suite/Group.php
View file @
358b1a68
...
...
@@ -42,7 +42,7 @@ class EcomDev_PHPUnit_Test_Suite_Group extends PHPUnit_Framework_TestSuite
public
function
__construct
(
$theClass
=
''
,
$groups
=
array
())
{
if
(
!
$theClass
instanceof
ReflectionClass
)
{
$theClass
=
EcomDev_Utils_Reflection
::
getRe
l
flection
(
$theClass
);
$theClass
=
EcomDev_Utils_Reflection
::
getReflection
(
$theClass
);
}
// Check annotations for test case name
...
...
app/code/community/EcomDev/PHPUnit/
Test/
bootstrap.php
→
app/code/community/EcomDev/PHPUnit/bootstrap.php
View file @
358b1a68
<?php
if
(
version_compare
(
PHP_VERSION
,
'5.3'
,
'<'
))
{
exit
(
'Magento Unit Tests can run only on PHP version higher then 5.3'
);
echo
'Magento Unit Tests can run only on PHP version higher then 5.3'
;
exit
(
1
);
}
$_baseDir
=
getcwd
();
$fileDir
=
dirname
(
__FILE__
);
// Include Mage file by detecting app root
require_once
substr
(
$fileDir
,
0
,
strpos
(
$fileDir
,
'app'
.
DIRECTORY_SEPARATOR
))
.
'app/
Mage.php'
;
require_once
$_baseDir
.
DIRECTORY_SEPARATOR
.
'app'
.
DIRECTORY_SEPARATOR
.
'
Mage.php'
;
if
(
!
Mage
::
isInstalled
())
{
exit
(
'Magento Unit Tests can run only on installed version'
);
echo
'Magento Unit Tests can run only on installed version'
;
exit
(
1
);
}
/* Replace server variables for proper file naming */
$_SERVER
[
'SCRIPT_NAME'
]
=
dirname
(
__FILE__
)
.
DS
.
'index.php'
;
$_SERVER
[
'SCRIPT_FILENAME'
]
=
dirname
(
__FILE__
)
.
DS
.
'index.php'
;
$_SERVER
[
'SCRIPT_NAME'
]
=
$_baseDir
.
DS
.
'index.php'
;
$_SERVER
[
'SCRIPT_FILENAME'
]
=
$_baseDir
.
DS
.
'index.php'
;
Mage
::
app
(
'admin'
);
Mage
::
getConfig
()
->
init
();
app/code/community/EcomDev/PHPUnit/etc/config.xml
View file @
358b1a68
...
...
@@ -45,6 +45,14 @@
</global>
<phpunit>
<suite>
<yaml>
<model>
ecomdev_phpunit/yaml_loader
</model>
<loaders>
<default>
ecomdev_phpunit/yaml_loader_default
</default>
<module>
ecomdev_phpunit/yaml_loader_module
</module>
<global>
ecomdev_phpunit/yaml_loader_global
</global>
</loaders>
</yaml>
<!-- The names of directories inside Test for recognizion of tests per group -->
<groups>
<models>
Model
</models>
...
...
@@ -70,6 +78,15 @@
<fixture>
<!-- Default model for loading of fixtures -->
<model>
ecomdev_phpunit/fixture
</model>
<processors>
<scope>
ecomdev_phpunit/fixture_processor_scope
</scope>
<config>
ecomdev_phpunit/fixture_processor_config
</config>
<config_xml>
ecomdev_phpunit/fixture_processor_config
</config_xml>
<cache_options>
ecomdev_phpunit/fixture_processor_cache
</cache_options>
<eav>
ecomdev_phpunit/fixture_processor_eav
</eav>
<tables>
ecomdev_phpunit/fixture_processor_tables
</tables>
<vfs>
ecomdev_phpunit/fixture_processor_vfs
</vfs>
</processors>
<eav>
<!-- Here goes the list of fixture loaders for EAV
If no fixture loader is specified for entity, then default will be used
...
...
lib/EcomDev/PHPUnit/Constraint/Abstract.php
View file @
358b1a68
...
...
@@ -83,7 +83,7 @@ abstract class EcomDev_PHPUnit_Constraint_Abstract
*/
public
function
__construct
(
$type
,
$expectedValue
=
null
)
{
$reflection
=
EcomDev_Utils_Reflection
::
getRe
l
flection
(
get_class
(
$this
));
$reflection
=
EcomDev_Utils_Reflection
::
getReflection
(
get_class
(
$this
));
$types
=
array
();
foreach
(
$reflection
->
getConstants
()
as
$name
=>
$constant
)
{
if
(
strpos
(
$name
,
'TYPE_'
)
===
0
)
{
...
...
lib/EcomDev/PHPUnit/Constraint/Json.php
View file @
358b1a68
...
...
@@ -103,11 +103,14 @@ class EcomDev_PHPUnit_Constraint_Json extends EcomDev_PHPUnit_Constraint_Abstrac
$decodedJson
=
Zend_Json
::
decode
(
$other
);
$this
->
setActualValue
(
$decodedJson
);
$intersection
=
array_intersect_assoc
(
$this
->
_actualValue
,
$this
->
_expectedValue
$intersection
=
array_intersect
(
array_keys
(
$this
->
_actualValue
),
array_keys
(
$this
->
_expectedValue
)
);
// @todo make it more recursive
switch
(
$this
->
_matchType
)
{
case
self
::
MATCH_OR
:
$matched
=
!
empty
(
$intersection
);
...
...
lib/EcomDev/PHPUnit/Constraint/Layout/Block.php
View file @
358b1a68
...
...
@@ -263,7 +263,7 @@ class EcomDev_PHPUnit_Constraint_Layout_Block extends EcomDev_PHPUnit_Constraint
}
$this
->
setActualValue
(
$blockInfo
[
'class'
]);
$actualReflection
=
EcomDev_Utils_Reflection
::
getRe
l
flection
(
$this
->
_actualValue
);
$actualReflection
=
EcomDev_Utils_Reflection
::
getReflection
(
$this
->
_actualValue
);
return
$this
->
_actualValue
===
$this
->
_expectedValue
||
$actualReflection
->
isSubclassOf
(
$this
->
_expectedValue
);
}
...
...
lib/EcomDev/Utils/Reflection.php
View file @
358b1a68
...
...
@@ -31,6 +31,7 @@ class EcomDev_Utils_Reflection
* @param string|object $object class name
* @param string $property
* @param mixed $value
* @throws RuntimeException
*/
public
static
function
setRestrictedPropertyValue
(
$object
,
$property
,
$value
)
{
...
...
@@ -38,7 +39,7 @@ class EcomDev_Utils_Reflection
throw
new
RuntimeException
(
'For setting of restricted properties via Reflection, PHP version should be 5.3.0 or later'
);
}
$reflectionObject
=
self
::
getRe
l
flection
(
$object
);
$reflectionObject
=
self
::
getReflection
(
$object
);
$reflectionProperty
=
$reflectionObject
->
getProperty
(
$property
);
$reflectionProperty
->
setAccessible
(
true
);
$reflectionProperty
->
setValue
((
is_string
(
$object
)
?
null
:
$object
),
$value
);
...
...
@@ -49,6 +50,7 @@ class EcomDev_Utils_Reflection
*
* @param string|object $object class name
* @param array $properties
* @throws RuntimeException
*/
public
static
function
setRestrictedPropertyValues
(
$object
,
array
$properties
)
{
...
...
@@ -67,6 +69,7 @@ class EcomDev_Utils_Reflection
* @param string|object $object class name
* @param string $property
* @return mixed
* @throws RuntimeException
*/
public
static
function
getRestrictedPropertyValue
(
$object
,
$property
)
{
...
...
@@ -74,7 +77,7 @@ class EcomDev_Utils_Reflection
throw
new
RuntimeException
(
'For getting of restricted properties via Reflection, PHP version should be 5.3.0 or later'
);
}
$reflectionObject
=
self
::
getRe
l
flection
(
$object
);
$reflectionObject
=
self
::
getReflection
(
$object
);
$reflectionProperty
=
$reflectionObject
->
getProperty
(
$property
);
$reflectionProperty
->
setAccessible
(
true
);
return
$reflectionProperty
->
getValue
((
is_string
(
$object
)
?
null
:
$object
));
...
...
@@ -88,6 +91,7 @@ class EcomDev_Utils_Reflection
* @param string $method
* @param array $args
* @return mixed
* @throws RuntimeException
*/
public
static
function
invokeRestrictedMethod
(
$object
,
$method
,
$args
=
array
())
{
...
...
@@ -95,7 +99,7 @@ class EcomDev_Utils_Reflection
throw
new
RuntimeException
(
'For invoking restricted methods via Reflection, PHP version should be 5.3.2 or later'
);
}
$reflectionObject
=
self
::
getRe
l
flection
(
$object
);
$reflectionObject
=
self
::
getReflection
(
$object
);
$reflectionMethod
=
$reflectionObject
->
getMethod
(
$method
);
$reflectionMethod
->
setAccessible
(
true
);
...
...
@@ -111,8 +115,21 @@ class EcomDev_Utils_Reflection
*
* @param string|object $object
* @return ReflectionClass|ReflectionObject
* @deprecated since 0.3.0 deprecated because of typo
*/
public
static
function
getRelflection
(
$object
)
{
return
self
::
getReflection
(
$object
);
}
/**
* Returns reflection object from instance or class name
*
* @param string|object $object
* @return ReflectionClass|ReflectionObject
* @throws InvalidArgumentException
*/
public
static
function
getReflection
(
$object
)
{
// If object is a class name
if
(
is_string
(
$object
)
&&
class_exists
(
$object
))
{
...
...
modman
View file @
358b1a68
# EcomDev_PHPUnit definition
UnitTests.php UnitTests.php
app/etc/modules/EcomDev_PHPUnit.xml app/etc/modules/EcomDev_PHPUnit.xml
app/code/community/EcomDev/PHPUnit app/code/community/EcomDev/PHPUnit
lib/EcomDev/PHPUnit lib/EcomDev/PHPUnit
...
...
@@ -8,10 +7,5 @@ lib/Spyc lib/Spyc
lib/vfsStream lib/vfsStream
shell/ecomdev-phpunit-install.php shell/ecomdev-phpunit-install.php
# Copy local.xml.phpunit if it doesn't already exist
@shell \
DIR_BEFORE_INSTALL=`pwd` \
cd $PROJECT/shell \
php -f ecomdev-phpunit-install.php --module $MODULE --project $PROJECT \
cd $DIR_BEFORE_INSTALL
# Run shell installer
@shell cd $PROJECT/shell && php -f ecomdev-phpunit-install.php -- --module $MODULE --project $PROJECT
phpunit.xml.dist
View file @
358b1a68
...
...
@@ -11,9 +11,13 @@
stopOnSkipped=
"false"
strict=
"false"
verbose=
"false"
bootstrap=
"app/code/community/EcomDev/PHPUnit/Test/bootstrap.php"
loader=
""
>
bootstrap=
"app/code/community/EcomDev/PHPUnit/bootstrap.php"
>
<listeners>
<listener
file=
"app/code/community/EcomDev/PHPUnit/Test/Listener.php"
class=
"EcomDev_PHPUnit_Test_Listener"
/>
</listeners>
<testsuite
name=
"Magento Test Suite"
>
<file>
app/code/community/EcomDev/PHPUnit/Test/Suite.php
</file>
</testsuite>
<filter>
<blacklist>
<!-- Exclude Magento Core files from code coverage -->
...
...
shell/ecomdev-phpunit-install.php
View file @
358b1a68
...
...
@@ -48,6 +48,7 @@ class EcomDev_PHPUnit_Install extends Mage_Shell_Abstract
$this
->
_copyLocalXml
();
$this
->
_copyPHPUnitXml
();
$this
->
_cleanCache
();
}
/**
...
...
@@ -76,4 +77,23 @@ class EcomDev_PHPUnit_Install extends Mage_Shell_Abstract
$this
->
getArg
(
'project'
)
.
DIRECTORY_SEPARATOR
.
self
::
FILE_PHPUNIT_XML
);
}
}
/**
* Clears cache of the magento project
*
*
*/
protected
function
_cleanCache
()
{
if
(
is_dir
(
$this
->
getArg
(
'project'
)
.
'/var/cache'
))
{
shell_exec
(
'rm -rf '
.
$this
->
getArg
(
'project'
)
.
'/var/cache'
);
}
if
(
is_dir
(
$this
->
getArg
(
'project'
)
.
'/var/phpunit.cache'
))
{
shell_exec
(
'rm -rf '
.
$this
->
getArg
(
'project'
)
.
'/var/phpunit.cache'
);
}
}
}
$shell
=
new
EcomDev_PHPUnit_Install
();
$shell
->
run
();
\ 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