We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) in our country

Commit 62c4bdf6 authored by Ivan Chepurnyi's avatar Ivan Chepurnyi

Merge branch 'release/0.3.2'

parents 9b85f00e 2a12b679
......@@ -7,19 +7,21 @@ env:
- MAGE=1.6.2.0
- MAGE=1.5.1.0
before_script:
# Fixing Magento hackathon installer
- mkdir -p tests/magento
# Installing required composer packages
- composer update --dev
- MAGE_DIR=tests/magento
# Copying travis composer.json to test only module
- cp -f .travis/composer.json composer.json
# Installing dependencies
- composer install
# Installing magento version with prepared DB dump
- bin/mage-ci install tests/magento $MAGE magento -c -t -r http://mage-ci.ecomdev.org
- bin/mage-ci install $MAGE_DIR $MAGE magento -c -r http://mage-ci.ecomdev.org
# Installing EcomDev_PHPUnit module
- bin/mage-ci install-module tests/magento $(pwd)
- bin/mage-ci install-module $MAGE_DIR $(pwd)
# Configuring EcomDev_PHPUnit module
- CURRENT_DIR=$(pwd)
- cd tests/magento/shell
- php ecomdev-phpunit.php -a magento-config --db-name magento --same-db 1 --base_url http://test.magento.com/
- php ecomdev-phpunit.php -a change-status --enable
- cd $CURRENT_DIR
- bin/mage-ci shell $MAGE_DIR ecomdev-phpunit.php -a magento-config --db-name magento --same-db 1 --base-url http://test.magento.com/
# Configuring test suite
- bin/mage-ci shell $MAGE_DIR ecomdev-phpunit.php -a change-status --enable
# Copying phpunit.xml for travis builds
- cp .travis/phpunit.xml $MAGE_DIR/phpunit.xml
script:
- bin/mage-ci phpunit tests/magento --colors --coverage-text
# output php ini info for checking the problem
- bin/mage-ci phpunit $MAGE_DIR --colors --coverage-text -d display_errors=1
{
"require": {
"ecomdev/mage-ci": "*",
"mikey179/vfsStream": "*"
},
"config": {
"bin-dir": "bin"
},
"extra":{
"magento-root-dir": "tests/magento"
}
}
<?xml version="1.0"?>
<!-- initial phpunit configuration file, that you can modify for your project needs -->
<phpunit cacheTokens="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
strict="false"
verbose="false"
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 -->
<directory suffix=".php">app/code/core</directory>
<!-- Exclude EcomDev_PHPUnit classes from code coverage -->
<directory suffix=".php">app/code/community/EcomDev/PHPUnitTest</directory>
<directory suffix=".php">lib/Spyc</directory>
<directory suffix=".php">lib/vfsStream</directory>
<!-- Exclude Mage.php file from code coverage -->
<file>app/Mage.php</file>
<!-- Exclude template files -->
<directory suffix=".phtml">app/design</directory>
<!-- Exclude Varien & Zend libraries -->
<directory suffix=".php">lib/Varien</directory>
<directory suffix=".php">lib/Zend</directory>
<directory suffix=".php">../../vendor/</directory>
</blacklist>
</filter>
</phpunit>
......@@ -11,6 +11,12 @@ System Requirements
* PHPUnit 3.7.x
* Magento CE1.4.x-1.7.x/PE1.9.x-PE1.10.x/EE1.9.x-1.12.x
Build Status
------------
* Latest Release: [![Master Branch](https://travis-ci.org/EcomDev/EcomDev_PHPUnit.png?branch=master)](https://travis-ci.org/EcomDev/EcomDev_PHPUnit)
* Development Branch: [![Development Branch](https://travis-ci.org/EcomDev/EcomDev_PHPUnit.png?branch=dev)](https://travis-ci.org/EcomDev/EcomDev_PHPUnit)
Documentation
-------------
......@@ -22,29 +28,38 @@ Installation
------------
### Git Repository
1. Checkout extension
$ git clone git://github.com/IvanChepurnyi/EcomDev_PHPUnit.git
2. Copy extension files into Magento root folder or use [Module Manager](https://github.com/colinmollenhour/modman) for auto-updating of the extension on all your installments
3. Open app/etc/local.xml.phpunit in editor that you are comfortable with:
1. Specify database credentials that will be used for test suite in
**global/resources/default_setup/connection** node
2. Specify **base_url** for **secure** and **unsecure** requests in **default/web** node. It is
required for proper controller tests.
1. There are two ways of obtaining the extension:
* Use [Module Manager](https://github.com/colinmollenhour/modman)
```bash
modman clone git://github.com/EcomDev/EcomDev_PHPUnit.git
```
* Add extension as dependency in your composer.json to install it from [Magento Composer Repository](http://packages.firegento.com/)
```json
{
"require": {
"ecomdev/ecomdev_phpunit": "*"
}
}
```
3. Open your terminal and navigate to your magento directory for performing the following command, they are required to configure system for running the test suite
```bash
# Shell scripts needs to be run from this directory
cd $YOUR_MAGENTO_DIRECTORY/shell
# Specify your test database name and base url for controller tests
php ecomdev-phpunit.php -a magento-config --db-name $DB_NAME --base-url http://your.magento.url/
```
If you receive a warning on PHPUnit checks for optional packages, run the following command
```bash
php ecomdev-phpunit.php -a fix-autoloader
```
4. Run the unit tests first time for installing test database. It will take about 3 minutes.
$ phpunit
$ phpunit
5. If it shows that there was no tests found, it means that extension was successfully
installed. If it shows some errors than it means that your customizations has install
scripts that relay on your current database data so you should fix them.
5. If it shows that there was no tests found, it means that extension was successfully installed. If it shows some errors, then it means, that your customizations has install scripts that relay on your current database data and you should fix them. Or use your dev database as a base for the tests, but prior first time running the suite.
Issue Tracker
......
......@@ -23,18 +23,17 @@
class EcomDev_PHPUnit_Controller_Front extends Mage_Core_Controller_Varien_Front
{
/**
* Overriden for getting rid
* of initialization of routers for each test case
* Resets initialized routers before front controller re-initialization
* on test cases
*
* (non-PHPdoc)
* @see Mage_Core_Controller_Varien_Front::init()
*/
public function init()
{
if (!$this->_routers) {
parent::init();
if ($this->_routers) {
$this->_routers = array();
}
return $this;
return parent::init();
}
}
\ No newline at end of file
}
......@@ -26,8 +26,8 @@
*/
class EcomDev_PHPUnit_Controller_Request_Http
extends Mage_Core_Controller_Request_Http
implements EcomDev_PHPUnit_Isolation_Interface,
EcomDev_PHPUnit_Controller_Request_Interface
implements EcomDev_PHPUnit_IsolationInterface,
EcomDev_PHPUnit_Controller_RequestInterface
{
/**
* List of $_SERVER variable changes
......@@ -47,7 +47,6 @@ class EcomDev_PHPUnit_Controller_Request_Http
/**
* Initializes forward data
*
* (non-PHPdoc)
* @see Mage_Core_Controller_Request_Http::initForward()
*/
public function initForward()
......@@ -63,7 +62,7 @@ class EcomDev_PHPUnit_Controller_Request_Http
/**
* Returns only request uri that was set before
* (non-PHPdoc)
*
* @see Zend_Controller_Request_Http::getRequestUri()
*/
public function getRequestUri()
......@@ -119,7 +118,7 @@ class EcomDev_PHPUnit_Controller_Request_Http
}
/**
* Resets $_POST superglobal for test request
* Resets $_POST super global for test request
*
* @return EcomDev_PHPUnit_Controller_Request_Http
*/
......@@ -225,7 +224,6 @@ class EcomDev_PHPUnit_Controller_Request_Http
/**
* Returns header from test request parameters
*
* (non-PHPdoc)
* @see Zend_Controller_Request_Http::getHeader()
*/
public function getHeader($header)
......@@ -261,7 +259,7 @@ class EcomDev_PHPUnit_Controller_Request_Http
}
/**
* Sets value for a particular $_SERVER superglobal array key for test request
* Sets value for a particular $_SERVER super global array key for test request
*
* Saves original value for returning it back
*
......@@ -281,7 +279,7 @@ class EcomDev_PHPUnit_Controller_Request_Http
}
/**
* Sets multiple values for $_SERVER superglobal in test request
* Sets multiple values for $_SERVER super global in test request
*
* @param array $values
* @return EcomDev_PHPUnit_Controller_Request_Http
......@@ -295,7 +293,7 @@ class EcomDev_PHPUnit_Controller_Request_Http
}
/**
* Resets $_SERVER superglobal to previous state
* Resets $_SERVER super global to previous state
*
* @return EcomDev_PHPUnit_Controller_Request_Http
*/
......@@ -306,7 +304,7 @@ class EcomDev_PHPUnit_Controller_Request_Http
$_SERVER[$name] = $value;
} elseif (isset($_SERVER[$name])) {
// If original value was not set,
// then unsetting the changed value
// then unset the changed value
unset($_SERVER[$name]);
}
}
......@@ -343,12 +341,18 @@ class EcomDev_PHPUnit_Controller_Request_Http
/**
* Returns HTTP host from base url that were set in the controller
*
* (non-PHPdoc)
* @see Mage_Core_Controller_Request_Http::getHttpHost()
*/
public function getHttpHost($trimPort = false)
{
$baseUrl = $this->getBaseUrl();
if (!$baseUrl) {
$baseUrl = Mage::app()->getConfig()->getNode(
EcomDev_PHPUnit_Model_Config::XML_PATH_UNSECURE_BASE_URL
);
}
$parts = parse_url($baseUrl);
if (!isset($parts['host'])) {
......@@ -366,7 +370,6 @@ class EcomDev_PHPUnit_Controller_Request_Http
/**
* Returns only base url that was set before
*
* (non-PHPdoc)
* @see Mage_Core_Controller_Request_Http::getBaseUrl()
*/
public function getBaseUrl()
......
......@@ -26,8 +26,8 @@
*/
class EcomDev_PHPUnit_Controller_Response_Http
extends Mage_Core_Controller_Response_Http
implements EcomDev_PHPUnit_Isolation_Interface,
EcomDev_PHPUnit_Controller_Response_Interface
implements EcomDev_PHPUnit_IsolationInterface,
EcomDev_PHPUnit_Controller_ResponseInterface
{
const LINE_ENDING = "\r\n";
......@@ -39,7 +39,7 @@ class EcomDev_PHPUnit_Controller_Response_Http
protected $_sentHeaders = null;
/**
* Response that was sent via sendRespose()
* Response that was sent via sendResponse()
* or sendHeaders() or outputBody() methods
*
* @var string
......@@ -80,7 +80,6 @@ class EcomDev_PHPUnit_Controller_Response_Http
/**
* Implementation of sending the headers to output
*
* (non-PHPdoc)
* @see Mage_Core_Controller_Response_Http::sendHeaders()
*/
public function sendHeaders()
......@@ -91,6 +90,7 @@ class EcomDev_PHPUnit_Controller_Response_Http
$this->_sentHeaders[null] = 'HTTP/1.1 ' . $this->_httpResponseCode;
foreach ($this->_headersRaw as $headerRaw) {
if (strpos($headerRaw, ':') === false) { continue; }
list($headerName, $headerValue) = explode(':', $headerRaw, 2);
$headerName = $this->_normalizeHeader($headerName);
if (isset($this->_sentHeaders[$headerName])) {
......@@ -155,7 +155,7 @@ class EcomDev_PHPUnit_Controller_Response_Http
/**
* Implementation of sending response for test case
* (non-PHPdoc)
*
* @see Mage_Core_Controller_Response_Http::sendResponse()
*/
public function sendResponse()
......@@ -212,7 +212,7 @@ class EcomDev_PHPUnit_Controller_Response_Http
/**
* Can send headers implementation for test case
*
* (non-PHPdoc)
*
* @see Zend_Controller_Response_Abstract::canSendHeaders()
*/
public function canSendHeaders($throw = false)
......@@ -224,4 +224,4 @@ class EcomDev_PHPUnit_Controller_Response_Http
return $this->_sentHeaders === null;
}
}
\ No newline at end of file
}
......@@ -43,7 +43,7 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
const AREA_PART_TRANSLATE = EcomDev_PHPUnit_Model_App_Area::PART_TRANSLATE;
const AREA_PART_CONFIG = EcomDev_PHPUnit_Model_App_Area::PART_CONFIG;
const INTERFACE_ISOLATION = 'EcomDev_PHPUnit_Isolation_Interface';
const INTERFACE_ISOLATION = 'EcomDev_PHPUnit_IsolationInterface';
const REGISTRY_PATH_LAYOUT_SINGLETON = '_singleton/core/layout';
const REGISTRY_PATH_DESIGN_PACKAGE_SINGLETON = '_singleton/core/design_package';
......@@ -253,13 +253,14 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
'_allowedCacheOptions'
);
}
/**
* Retrieves a model from config and checks it on interface implementation
*
* @param string $configPath
* @param string $interface
* @param string $modelName
* @throws RuntimeException
* @return Mage_Core_Model_Abstract
*/
protected function _getModelFromConfig($configPath, $interface, $modelName = 'Model')
......@@ -330,6 +331,7 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
*
* @param string $key
* @param string $value
* @return $this
*/
public function replaceRegistry($key, $value)
{
......@@ -356,7 +358,7 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
/**
* Returns request for test suite
* (non-PHPdoc)
*
* @see Mage_Core_Model_App::getRequest()
* @return EcomDev_PHPUnit_Controller_Request_Http
*/
......@@ -374,7 +376,7 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
/**
* Returns response for test suite
* (non-PHPdoc)
*
* @see Mage_Core_Model_App::getResponse()
* @return EcomDev_PHPUnit_Controller_Response_Http
*/
......@@ -397,6 +399,7 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
*
* @param string $configPath
* @param string $interface
* @throws RuntimeException
* @return string
*/
protected function _getClassNameFromConfig($configPath, $interface = null)
......
......@@ -24,7 +24,7 @@
class EcomDev_PHPUnit_Model_App_Area
extends Mage_Core_Model_App_Area
implements EcomDev_PHPUnit_Isolation_Interface
implements EcomDev_PHPUnit_IsolationInterface
{
const AREA_TEST = 'test';
const AREA_ADMINHTML = 'adminhtml';
......
......@@ -17,7 +17,7 @@
*/
/**
* Configution model extended to make unit tests to be available
* Configuration model extended to make unit tests to be available
* at separate configuration scope
*
*/
......@@ -56,6 +56,13 @@ class EcomDev_PHPUnit_Model_Config extends Mage_Core_Model_Config
*/
protected $_cacheSections = array();
/**
* Object containing parsed local.xml.phpunit
*
* @var null
*/
protected $_localXmlForTest = null;
/**
* Load config data from DB
*
......@@ -111,9 +118,8 @@ class EcomDev_PHPUnit_Model_Config extends Mage_Core_Model_Config
}
/**
* Overriden for test case model instance creation mocking
* Overridden for test case model instance creation mocking
*
* (non-PHPdoc)
* @see Mage_Core_Model_Config::getModelInstance()
*/
public function getModelInstance($modelClass='', $constructArguments=array())
......@@ -126,7 +132,7 @@ class EcomDev_PHPUnit_Model_Config extends Mage_Core_Model_Config
}
/**
* Overriden for test case model instance creation mocking
* Overridden for test case model instance creation mocking
*
* (non-PHPdoc)
* @see Mage_Core_Model_Config::getModelInstance()
......@@ -163,6 +169,7 @@ class EcomDev_PHPUnit_Model_Config extends Mage_Core_Model_Config
/**
* Loads scope snapshot
*
* @throws RuntimeException
* @return EcomDev_PHPUnit_Model_Config
*/
public function loadScopeSnapshot()
......@@ -215,6 +222,33 @@ class EcomDev_PHPUnit_Model_Config extends Mage_Core_Model_Config
return $this;
}
/**
* Define if module is allowed
*
* Magento core allows use of a whitelist of modules supplied via the
* addAllowedModules method. EcomDev_PHPUnit extends this to allow a
* blacklist of modules to be supplied via local.xml.phpunit.
*
* @see Mage_Core_Model_Config::_isAllowedModule()
* @param string $moduleName
* @return bool
*/
protected function _isAllowedModule($moduleName)
{
if (!parent::_isAllowedModule($moduleName)) {
return false;
}
$localXml = $this->_loadLocalXmlForTest();
if ($localXml) {
$node = $localXml->getNode("phpunit/disable_modules/$moduleName");
return $node === false;
}
return true;
}
/**
* (non-PHPdoc)
* @see Mage_Core_Model_Config::loadModules()
......@@ -235,10 +269,8 @@ class EcomDev_PHPUnit_Model_Config extends Mage_Core_Model_Config
*/
protected function _loadTestConfig()
{
$merge = clone $this->_prototype;
try {
if ($merge->loadFile($this->_getLocalXmlForTest())) {
if ($merge = $this->_loadLocalXmlForTest()) {
$this->_checkDbCredentialForDuplicate($this, $merge);
$this->_checkBaseUrl($this, $merge);
$this->extend($merge);
......@@ -253,6 +285,20 @@ class EcomDev_PHPUnit_Model_Config extends Mage_Core_Model_Config
return $this;
}
/**
* Parse the phpunit specific local configuration. This may be loaded by
* and used by _isAllowedModule before it's merged into the merged config.
*
* @return Mage_Core_Model_Config_Base|null
*/
protected function _loadLocalXmlForTest() {
if ($this->_localXmlForTest === null) {
$this->_localXmlForTest = clone $this->_prototype;
$this->_localXmlForTest->loadFile($this->_getLocalXmlForTest());
}
return $this->_localXmlForTest;
}
/**
* Loads cache configuration for PHPUnit tests scope
*
......
......@@ -2,13 +2,13 @@
class EcomDev_PHPUnit_Model_Design_Package
extends Mage_Core_Model_Design_Package
implements EcomDev_PHPUnit_Design_Package_Interface,
EcomDev_PHPUnit_Isolation_Interface
implements EcomDev_PHPUnit_Design_PackageInterface,
EcomDev_PHPUnit_IsolationInterface
{
/**
* Asserts layout file existance in design packages,
* and returns actual and expected filenames as result
* Asserts layout file existence in design packages,
* and returns actual and expected file names as result
*
* @param string $fileName
* @param string $area
......
<?php
class EcomDev_PHPUnit_Model_Expectation
implements EcomDev_PHPUnit_Model_Expectation_Interface
implements EcomDev_PHPUnit_Model_ExpectationInterface
{
/**
* List of created data object ids by path format
......@@ -38,7 +38,7 @@ class EcomDev_PHPUnit_Model_Expectation
/**
* Retrieves data object for a particular path format
*
* @see EcomDev_PHPUnit_Model_Expectation_Interface::getDataObject()
* @see EcomDev_PHPUnit_Model_ExpectationInterface::getDataObject()
*/
public function getDataObject($pathFormat = null, $args = array())
{
......@@ -77,7 +77,7 @@ class EcomDev_PHPUnit_Model_Expectation
/**
* Applies loaded data
*
* @see EcomDev_PHPUnit_Model_Test_Loadable_Interface::apply()
* @see EcomDev_PHPUnit_Model_Test_LoadableInterface::apply()
*/
public function apply()
{
......@@ -89,7 +89,7 @@ class EcomDev_PHPUnit_Model_Expectation
* Removes objects created in object cache
* Clears loaded data property
*
* @see EcomDev_PHPUnit_Model_Test_Loadable_Interface::discard()
* @see EcomDev_PHPUnit_Model_Test_LoadableInterface::discard()
*/
public function discard()
{
......@@ -116,7 +116,7 @@ class EcomDev_PHPUnit_Model_Expectation
/**
* Loads expected data from test case annotations
*
* @see EcomDev_PHPUnit_Model_Test_Loadable_Interface::loadByTestCase()
* @see EcomDev_PHPUnit_Model_Test_LoadableInterface::loadByTestCase()
*/
public function loadByTestCase(PHPUnit_Framework_TestCase $testCase)
{
......
......@@ -18,27 +18,10 @@
*/
/**
* Interface for fixture model
* Can be used for creation of
* absolutely different implementation of fixture,
* then current one.
* @deprecated since 0.4.0
*
*/
interface EcomDev_PHPUnit_Model_Expectation_Interface extends EcomDev_PHPUnit_Model_Test_Loadable_Interface
interface EcomDev_PHPUnit_Model_Expectation_Interface
extends EcomDev_PHPUnit_Model_ExpectationInterface
{
/**
* Returns data object with expectations
*
* @param string $pathFormat
* @param array $args arguments for format function
* @return EcomDev_PHPUnit_Model_Expectation_Object
*/
public function getDataObject($pathFormat = null, $args = array());
/**
* Check is expectation loaded
*
* @return boolean
*/
public function isLoaded();
}
\ No newline at end of file
......@@ -59,7 +59,7 @@ class EcomDev_PHPUnit_Model_Expectation_Object
return $current;
}
/* (non-PHPdoc)
/**
* @see Iterator::key()
*/
public function key()
......@@ -67,7 +67,7 @@ class EcomDev_PHPUnit_Model_Expectation_Object
return current($this->_iterationKeys);
}
/* (non-PHPdoc)
/**
* @see Iterator::next()
*/
public function next()
......@@ -75,7 +75,7 @@ class EcomDev_PHPUnit_Model_Expectation_Object
next($this->_iterationKeys);
}
/* (non-PHPdoc)
/**
* @see Iterator::rewind()
*/
public function rewind()
......@@ -83,7 +83,7 @@ class EcomDev_PHPUnit_Model_Expectation_Object
$this->_iterationKeys = $this->keys();
}
/* (non-PHPdoc)
/**
* @see Iterator::valid()
*/
public function valid()
......
<?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) 2013 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 for fixture model
* Can be used for creation of
* absolutely different implementation of fixture,
* then current one.
*
*/
interface EcomDev_PHPUnit_Model_ExpectationInterface extends EcomDev_PHPUnit_Model_LoadableInterface
{
/**
* Returns data object with expectations
*
* @param string $pathFormat
* @param array $args arguments for format function
* @return EcomDev_PHPUnit_Model_Expectation_Object
*/
public function getDataObject($pathFormat = null, $args = array());
/**
* Check is expectation loaded
*
* @return boolean
*/
public function isLoaded();
}
\ No newline at end of file
......@@ -25,7 +25,7 @@
*/
class EcomDev_PHPUnit_Model_Fixture
extends Varien_Object
implements EcomDev_PHPUnit_Model_Fixture_Interface
implements EcomDev_PHPUnit_Model_FixtureInterface
{
// Configuration path for eav loaders
/* @deprecated since 0.3.0 */
......@@ -36,6 +36,8 @@ class EcomDev_PHPUnit_Model_Fixture
// Configuration path for attribute loaders
const XML_PATH_FIXTURE_ATTRIBUTE_LOADERS = 'phpunit/suite/fixture/attribute';
// Default attribute loader class alias
const DEFAULT_ATTRIBUTE_LOADER_CLASS = 'ecomdev_phpunit/fixture_attribute_default';
// Default eav loader class node in loaders configuration
/* @deprecated since 0.3.0 */
......@@ -78,7 +80,7 @@ class EcomDev_PHPUnit_Model_Fixture
* 'node/path' => 'value'
* ),
* 'table' => array(
* 'tablename' => array(
* 'table/name' => array(
* array(
* 'column1' => 'value'
* 'column2' => 'value'
......@@ -123,7 +125,7 @@ class EcomDev_PHPUnit_Model_Fixture
/**
* Processors list
*
* @var EcomDev_PHPUnit_Model_Fixture_Processor_Interface[]
* @var EcomDev_PHPUnit_Model_Fixture_ProcessorInterface[]
*/
protected $_processors = array();
......@@ -251,7 +253,7 @@ class EcomDev_PHPUnit_Model_Fixture
/**
* Sets current fixture scope
*
* @param string $scope EcomDev_PHPUnit_Model_Fixture_Interface::SCOPE_LOCAL|EcomDev_PHPUnit_Model_Fixture_Interface::SCOPE_SHARED
* @param string $scope EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_LOCAL|EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED
* @return EcomDev_PHPUnit_Model_Fixture
*/
public function setScope($scope)
......@@ -387,7 +389,7 @@ class EcomDev_PHPUnit_Model_Fixture
->resolveFilePath($className, EcomDev_PHPUnit_Model_Yaml_Loader::TYPE_FIXTURE, $fixture);
if (!$filePath) {
throw new RuntimeException('Unable to load fixture for test');
throw new RuntimeException('Unable to load fixture for test: '.$fixture);
}
$this->loadYaml($filePath);
......@@ -419,7 +421,7 @@ class EcomDev_PHPUnit_Model_Fixture
/**
* Returns list of available processors for fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Interface[]
* @return EcomDev_PHPUnit_Model_Fixture_ProcessorInterface[]
*/
public function getProcessors()
{
......@@ -427,7 +429,7 @@ class EcomDev_PHPUnit_Model_Fixture
$processorsNode = Mage::getConfig()->getNode(self::XML_PATH_FIXTURE_PROCESSORS);
foreach ($processorsNode->children() as $code => $processorAlias) {
$processor = Mage::getSingleton((string)$processorAlias);
if ($processor instanceof EcomDev_PHPUnit_Model_Fixture_Processor_Interface) {
if ($processor instanceof EcomDev_PHPUnit_Model_Fixture_ProcessorInterface) {
$this->_processors[$code] = $processor;
}
}
......@@ -611,7 +613,7 @@ class EcomDev_PHPUnit_Model_Fixture
* Retrieves eav loader for a particular entity type
*
* @param string $entityType
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_AbstractEav
* @deprecated since 0.3.0
*/
protected function _getEavLoader($entityType)
......@@ -634,7 +636,7 @@ class EcomDev_PHPUnit_Model_Fixture
throw new InvalidArgumentException('Must specify a data type for the loader');
}
$reflection = EcomDev_Utils_Reflection::getRelflection($this);
$reflection = EcomDev_Utils_Reflection::getReflection($this);
$loaders = Mage::getConfig()->getNode($reflection->getConstant("XML_PATH_FIXTURE_{$dataType}_LOADERS"));
......@@ -735,8 +737,12 @@ class EcomDev_PHPUnit_Model_Fixture
return $this->_vfs;
}
if (is_dir(Mage::getBaseDir('lib') . DS . 'vfsStream' . DS . 'src')) {
if (!class_exists('\org\bovigo\vfs\vfsStream')
&& is_dir(Mage::getBaseDir('lib') . DS . 'vfsStream' . DS . 'src')) {
spl_autoload_register(array($this, 'vfsAutoload'), true, true);
}
if( class_exists('\org\bovigo\vfs\vfsStream') ){
$this->_vfs = Mage::getModel('ecomdev_phpunit/fixture_vfs');
return $this->_vfs;
}
......
......@@ -17,137 +17,10 @@
*/
/**
* Interface for fixture model
* Can be used for creation of
* absolutely different implementation of fixture,
* then current one.
*
* @deprecated since 0.4.0
*/
interface EcomDev_PHPUnit_Model_Fixture_Interface extends EcomDev_PHPUnit_Model_Test_Loadable_Interface
interface EcomDev_PHPUnit_Model_Fixture_Interface
extends EcomDev_PHPUnit_Model_FixtureInterface
{
/** Local scope - used for fixtures that apply only to the current test */
const SCOPE_LOCAL = 'local';
/** Shared scope - used for fixtures that apply to the current test class */
const SCOPE_SHARED = 'shared';
/** Default scope - used for storing data that exists in database before tests are run */
const SCOPE_DEFAULT = 'default';
/**
* Sets fixture options
*
* @param array $options
* @return EcomDev_PHPUnit_Model_Fixture_Interface
*/
public function setOptions(array $options);
/**
* Sets fixture options
*
* @return array
*/
public function getOptions();
/**
* Sets storage for fixtures
*
* @param Varien_Object $storage
* @return EcomDev_PHPUnit_Model_Fixture_Interface
*/
public function setStorage(Varien_Object $storage);
/**
* Retrieve fixture storage
*
* @return Varien_Object
*/
public function getStorage();
/**
* Retrieves storage data for a particular fixture scope
*
* @param string $key
* @param string|null $scope
*/
public function getStorageData($key, $scope = null);
/**
* Sets storage data for a particular fixture scope
*
* @param string $key
* @param mixed $value
* @param string|null $scope
*/
public function setStorageData($key, $value, $scope = null);
/**
* Returns current fixture scope
*
* @return string
*/
public function getScope();
/**
* Sets current fixture scope
*
*
* @param string $scope EcomDev_PHPUnit_Model_Fixture_Interface::SCOPE_LOCAL|EcomDev_PHPUnit_Model_Fixture_Interface::SCOPE_SHARED
*/
public function setScope($scope);
/**
* Check that current fixture scope is equal to SCOPE_DEFAULT
*
* @abstract
* @return boolean
*/
public function isScopeDefault();
/**
* Check that current fixture scope is equal to SCOPE_SHARED
*
* @return boolean
*/
public function isScopeShared();
/**
* Check that current fixture scope is equal to SCOPE_LOCAL
*
* @return boolean
*/
public function isScopeLocal();
/**
* Loads fixture files from test class annotations
*
* @param string $className
* @return EcomDev_PHPUnit_Model_Fixture_Interface
*/
public function loadForClass($className);
/**
* Sets fixture value
*
* @param string $key
* @param array[] $value
*
* @return EcomDev_PHPUnit_Model_Fixture_Interface
*/
public function setFixtureValue($key, $value);
/**
* Retrieves fixture value
*
* @param string $key
*
* @return array[]
*/
public function getFixtureValue($key);
/**
* Returns VFS wrapper instance
*
* @return EcomDev_PHPUnit_Model_Fixture_Vfs
*/
public function getVfs();
}
<?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) 2013 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>
* @author Steve Rice <srice@endertech.com>
* @author Jonathan Day <jonathan@aligent.com.au>
*/
class EcomDev_PHPUnit_Model_Fixture_Processor_Attributes
extends Mage_Core_Model_Abstract
implements EcomDev_PHPUnit_Model_Fixture_ProcessorInterface
{
const STORAGE_KEY = 'entities';
// Configuration path for attribute loaders
const XML_PATH_FIXTURE_ATTRIBUTE_LOADERS = 'phpunit/suite/fixture/attribute';
// Default attribute loader class node in loaders configuration
const DEFAULT_ATTRIBUTE_LOADER_NODE = 'default';
// Default attribute loader class alias
const DEFAULT_ATTRIBUTE_LOADER_CLASS = 'ecomdev_phpunit/fixture_attribute_default';
/**
* Initialize fixture resource model
*/
protected function _construct()
{
$this->_init('ecomdev_phpunit/fixture');
}
/**
* Does nothing
*
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Attributes
*/
public function initialize(EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
return $this;
}
/**
* Retrieves attribute loader for a particular attribute type
*
* @param string $entityType
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_Attribute_Abstract
*/
protected function _getAttributeLoader($entityType)
{
$loaders = Mage::getConfig()->getNode(self::XML_PATH_FIXTURE_ATTRIBUTE_LOADERS);
if (isset($loaders->$entityType)) {
$classAlias = (string)$loaders->$entityType;
} elseif (isset($loaders->{self::DEFAULT_ATTRIBUTE_LOADER_NODE})) {
$classAlias = (string)$loaders->{self::DEFAULT_ATTRIBUTE_LOADER_NODE};
} else {
$classAlias = self::DEFAULT_ATTRIBUTE_LOADER_CLASS;
}
return Mage::getResourceSingleton($classAlias);
}
/**
* Apply attribute records from fixture file
*
* @param array $data
* @param string $key
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Attributes
*/
public function apply(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
$attributeLoaders = array();
$this->getResource()->beginTransaction();
foreach ($data as $entityType => $values) {
$attributeLoaders[] = $this->_getAttributeLoader($entityType)
->setFixture($fixture)
->setOptions($fixture->getOptions())
->loadAttribute($entityType, $values);
}
$this->getResource()->commit();
foreach ($attributeLoaders as $attributeLoader){
$attributeLoader->runRequiredIndexers();
}
$fixture->setStorageData(self::STORAGE_KEY, array_keys($data));
return $this;
}
/**
* Discard applied attribute records
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Attributes
*/
public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $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_FixtureInterface::SCOPE_SHARED)) {
$ignoreCleanUp = $fixture->getStorageData(self::STORAGE_KEY,
EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED);
}
$this->getResource()->beginTransaction();
foreach (array_keys($data) as $entityType) {
if (in_array($entityType, $ignoreCleanUp)) {
continue;
}
$this->_getAttributeLoader($entityType)
->cleanAttributes($entityType,$data);
}
$this->getResource()->commit();
EcomDev_PHPUnit_Test_Case_Util::replaceRegistry('_singleton/eav/config', null); //clean out the EAV cache
return $this;
}
}
\ No newline at end of file
......@@ -16,17 +16,17 @@
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
class EcomDev_PHPUnit_Model_Fixture_Processor_Cache implements EcomDev_PHPUnit_Model_Fixture_Processor_Interface
class EcomDev_PHPUnit_Model_Fixture_Processor_Cache implements EcomDev_PHPUnit_Model_Fixture_ProcessorInterface
{
const STORAGE_KEY = 'cache_options';
/**
* Initializes cache options
*
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Cache
*/
public function initialize(EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function initialize(EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
$options = $fixture->getOptions();
if (isset($options['cache'])) {
......@@ -54,11 +54,11 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Cache implements EcomDev_PHPUnit_M
*
* @param array $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Cache
*/
public function apply(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function apply(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
$originalOptions = EcomDev_PHPUnit_Test_Case_Util::app()->getCacheOptions();
$fixture->setStorageData(self::STORAGE_KEY, $originalOptions);
......@@ -73,11 +73,11 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Cache implements EcomDev_PHPUnit_M
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Cache
*/
public function discard(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
EcomDev_PHPUnit_Test_Case_Util::app()->setCacheOptions(
$fixture->getStorageData(self::STORAGE_KEY)
......
......@@ -16,15 +16,16 @@
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
class EcomDev_PHPUnit_Model_Fixture_Processor_Config implements EcomDev_PHPUnit_Model_Fixture_Processor_Interface
class EcomDev_PHPUnit_Model_Fixture_Processor_Config
implements EcomDev_PHPUnit_Model_Fixture_ProcessorInterface
{
/**
* Does nothing
*
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Config
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
* @return $this
*/
public function initialize(EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function initialize(EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
return $this;
}
......@@ -34,11 +35,11 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Config implements EcomDev_PHPUnit_
*
* @param array $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Config
* @return $this
*/
public function apply(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function apply(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
$key === 'config_xml' ? $this->_applyConfigXml($data) : $this->_applyConfig($data);
return $this;
......@@ -48,7 +49,7 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Config implements EcomDev_PHPUnit_
* Applies fixture configuration values into Mage_Core_Model_Config
*
* @param array $configuration
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Config
* @return $this
* @throws InvalidArgumentException
*/
protected function _applyConfig($configuration)
......@@ -83,7 +84,7 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Config implements EcomDev_PHPUnit_
* Applies raw xml data to config node
*
* @param array $configuration
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Config
* @return $this
* @throws InvalidArgumentException
*/
protected function _applyConfigXml($configuration)
......@@ -119,11 +120,11 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Config implements EcomDev_PHPUnit_
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Config
* @return $this
*/
public function discard(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
$this->_restoreConfig();
return $this;
......@@ -147,7 +148,7 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Config implements EcomDev_PHPUnit_
* @param string $path
* @param string $value
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Config
* @return $this
*/
protected function _setConfigNodeValue($path, $value)
{
......
......@@ -19,7 +19,7 @@
class EcomDev_PHPUnit_Model_Fixture_Processor_Eav
extends Mage_Core_Model_Abstract
implements EcomDev_PHPUnit_Model_Fixture_Processor_Interface
implements EcomDev_PHPUnit_Model_Fixture_ProcessorInterface
{
const STORAGE_KEY = 'entities';
......@@ -43,10 +43,10 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Eav
/**
* Does nothing
*
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Eav
*/
public function initialize(EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function initialize(EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
return $this;
}
......@@ -55,7 +55,7 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Eav
* Retrieves eav loader for a particular entity type
*
* @param string $entityType
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_AbstractEav
*/
protected function _getEavLoader($entityType)
{
......@@ -78,11 +78,11 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Eav
*
* @param array $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Eav
*/
public function apply(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function apply(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
$eavLoaders = array();
......@@ -110,20 +110,20 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Eav
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Eav
*/
public function discard(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $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)) {
EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED)) {
$ignoreCleanUp = $fixture->getStorageData(self::STORAGE_KEY,
EcomDev_PHPUnit_Model_Fixture_Interface::SCOPE_SHARED);
EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED);
}
$this->getResource()->beginTransaction();
......
......@@ -16,35 +16,11 @@
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
interface EcomDev_PHPUnit_Model_Fixture_Processor_Interface
/**
* @deprecated since 0.4.0
*/
interface EcomDev_PHPUnit_Model_Fixture_Processor_Interface
extends EcomDev_PHPUnit_Model_Fixture_ProcessorInterface
{
/**
* 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);
}
......@@ -23,6 +23,7 @@
* @singleton catalog/product_type
* @resource catalog/product
* @helper catalog
* @registry key
*
* or by specifying it in Yaml file:
*
......@@ -36,7 +37,8 @@
* - core/url
*
*/
class EcomDev_PHPUnit_Model_Fixture_Processor_Registry implements EcomDev_PHPUnit_Model_Fixture_Processor_Interface
class EcomDev_PHPUnit_Model_Fixture_Processor_Registry
implements EcomDev_PHPUnit_Model_Fixture_ProcessorInterface
{
const STORAGE_KEY = 'registry';
......@@ -45,17 +47,18 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Registry implements EcomDev_PHPUni
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Registry
* @throws RuntimeException
*/
public function apply(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function apply(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
$typeToKey = array(
'singleton' => '_singleton/',
'resource' => '_resource_singleton/',
'helper' => '_helper/'
'helper' => '_helper/',
'registry' => ''
);
if ($fixture->getStorageData(self::STORAGE_KEY) !== null) {
......@@ -86,11 +89,11 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Registry implements EcomDev_PHPUni
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Interface
* @return EcomDev_PHPUnit_Model_Fixture_ProcessorInterface
*/
public function discard(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
if ($fixture->getStorageData(self::STORAGE_KEY) === null) {
return $this;
......@@ -109,14 +112,14 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Registry implements EcomDev_PHPUni
/**
* Initializes fixture processor before applying data
*
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Registry
*/
public function initialize(EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function initialize(EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
$options = $fixture->getOptions();
$registry = array();
foreach (array('singleton', 'resource', 'helper') as $type) {
foreach (array('singleton', 'resource', 'helper', 'registry') as $type) {
if (!isset($options[$type])) {
continue;
}
......
......@@ -17,7 +17,7 @@
*/
class EcomDev_PHPUnit_Model_Fixture_Processor_Scope
implements EcomDev_PHPUnit_Model_Fixture_Processor_Interface
implements EcomDev_PHPUnit_Model_Fixture_ProcessorInterface
{
const STORAGE_KEY = 'scope';
......@@ -35,10 +35,10 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Scope
/**
* Does nothing
*
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Scope
*/
public function initialize(EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function initialize(EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
return $this;
}
......@@ -48,18 +48,18 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Scope
*
* @param string $type
* @param array $row
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
* @return boolean|Mage_Core_Model_Abstract
*/
protected function _handleScopeRow($type, $row, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
protected function _handleScopeRow($type, $row, EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
$previousScope = array();
if ($fixture->isScopeLocal()
&& $fixture->getStorageData(self::STORAGE_KEY,
EcomDev_PHPUnit_Model_Fixture_Interface::SCOPE_SHARED) !== null) {
EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED) !== null) {
$previousScope = $fixture->getStorageData(self::STORAGE_KEY,
EcomDev_PHPUnit_Model_Fixture_Interface::SCOPE_SHARED);
EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED);
}
if (isset($previousScope[$type][$row[$type . '_id']])) {
......@@ -135,12 +135,12 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Scope
*
* @param array $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
*
* @throws RuntimeException
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Scope
*/
public function apply(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function apply(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
EcomDev_PHPUnit_Test_Case_Util::app()->disableEvents();
// Validate received fixture data
......@@ -173,11 +173,11 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Scope
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Scope
*/
public function discard(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
if ($fixture->getStorageData(self::STORAGE_KEY) === null) {
return $this;
......
......@@ -19,7 +19,7 @@
class EcomDev_PHPUnit_Model_Fixture_Processor_Tables
extends Mage_Core_Model_Abstract
implements EcomDev_PHPUnit_Model_Fixture_Processor_Interface
implements EcomDev_PHPUnit_Model_Fixture_ProcessorInterface
{
const STORAGE_KEY = 'tables';
......@@ -35,10 +35,10 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Tables
/**
* Does nothing
*
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Tables
*/
public function initialize(EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function initialize(EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
return $this;
}
......@@ -48,11 +48,11 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Tables
*
* @param array $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Tables
*/
public function apply(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function apply(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
$ignoreCleanUp = array();
......@@ -60,17 +60,18 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Tables
// Ignore cleaning of tables if shared fixture loaded something
if ($fixture->isScopeLocal()
&& $fixture->getStorageData(self::STORAGE_KEY,
EcomDev_PHPUnit_Model_Fixture_Interface::SCOPE_SHARED)) {
EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED)) {
$ignoreCleanUp = array_keys($fixture->getStorageData(self::STORAGE_KEY,
EcomDev_PHPUnit_Model_Fixture_Interface::SCOPE_SHARED));
EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED));
}
$this->getResource()->beginTransaction();
foreach ($data as $tableEntity => $tableData) {
foreach (array_reverse(array_keys($data)) as $tableEntity) {
if (!in_array($tableEntity, $ignoreCleanUp)) {
$this->getResource()->cleanTable($tableEntity);
}
}
foreach ($data as $tableEntity => $tableData) {
if (!empty($tableData)) {
$this->getResource()->loadTableData($tableEntity, $tableData);
}
......@@ -85,26 +86,27 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Tables
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Tables
*/
public function discard(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $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)) {
EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED)) {
$restoreTableData = $fixture->getStorageData(self::STORAGE_KEY,
EcomDev_PHPUnit_Model_Fixture_Interface::SCOPE_SHARED);
EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED);
}
$this->getResource()->beginTransaction();
foreach (array_keys($data) as $tableEntity) {
foreach (array_reverse(array_keys($data)) as $tableEntity) {
$this->getResource()->cleanTable($tableEntity);
}
foreach (array_keys($data) as $tableEntity) {
if (isset($restoreTableData[$tableEntity])) {
$this->getResource()->loadTableData($tableEntity, $restoreTableData[$tableEntity]);
}
......@@ -114,4 +116,4 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Tables
$fixture->setStorageData(self::STORAGE_KEY, null);
return $this;
}
}
\ No newline at end of file
}
......@@ -17,17 +17,17 @@
*/
class EcomDev_PHPUnit_Model_Fixture_Processor_Vfs implements EcomDev_PHPUnit_Model_Fixture_Processor_Interface
class EcomDev_PHPUnit_Model_Fixture_Processor_Vfs implements EcomDev_PHPUnit_Model_Fixture_ProcessorInterface
{
const STORAGE_KEY = 'vfs';
/**
* Does nothing
*
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Cache
*/
public function initialize(EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function initialize(EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
return $this;
}
......@@ -37,15 +37,15 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Vfs implements EcomDev_PHPUnit_Mod
*
* @param array $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Cache
*/
public function apply(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function apply(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
if ($fixture->isScopeLocal()
&& ($parentData = $fixture->getStorageData(self::STORAGE_KEY,
EcomDev_PHPUnit_Model_Fixture_Interface::SCOPE_SHARED))) {
EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED))) {
$data = array_merge_recursive($parentData, $data);
}
......@@ -60,11 +60,11 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Vfs implements EcomDev_PHPUnit_Mod
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Cache
*/
public function discard(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture)
{
$fixture->getVfs()->discard();
$fixture->setStorageData(self::STORAGE_KEY, null);
......
<?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) 2013 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_ProcessorInterface
{
/**
* Applies data from fixture file
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_ProcessorInterface
*/
public function apply(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture);
/**
* Discards data from fixture file
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
*
* @return $this
*/
public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture);
/**
* Initializes fixture processor before applying data
*
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
* @return $this
*/
public function initialize(EcomDev_PHPUnit_Model_FixtureInterface $fixture);
}
\ No newline at end of file
......@@ -35,26 +35,19 @@ class EcomDev_PHPUnit_Model_Fixture_Vfs
*/
protected $_currentRoot = array();
/**
* Initializes VFS stream wrapper/
*/
public function __construct()
{
Stream::setup();
}
/**
* Applies VFS directory structure
*
* @param $data
* @param bool $cloneCurrent
* @param array $data
*
* @return EcomDev_PHPUnit_Model_Fixture_Vfs
*/
public function apply($data)
{
$this->_currentRoot[] = StreamWrapper::getRoot();
Stream::create($data);
if (StreamWrapper::getRoot()) {
$this->_currentRoot[] = StreamWrapper::getRoot();
}
Stream::setup('root', null, $data);
return $this;
}
......@@ -97,6 +90,10 @@ class EcomDev_PHPUnit_Model_Fixture_Vfs
*/
public function url($path)
{
if (strpos($path, StreamWrapper::getRoot()->getName()) === false) {
$path = StreamWrapper::getRoot()->getName() . '/' . $path;
}
return Stream::url($path);
}
}
<?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) 2013 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 for fixture model
* Can be used for creation of
* absolutely different implementation of fixture,
* then current one.
*
*/
interface EcomDev_PHPUnit_Model_FixtureInterface
extends EcomDev_PHPUnit_Model_LoadableInterface
{
/** Local scope - used for fixtures that apply only to the current test */
const SCOPE_LOCAL = 'local';
/** Shared scope - used for fixtures that apply to the current test class */
const SCOPE_SHARED = 'shared';
/** Default scope - used for storing data that exists in database before tests are run */
const SCOPE_DEFAULT = 'default';
/**
* Sets fixture options
*
* @param array $options
* @return $this
*/
public function setOptions(array $options);
/**
* Sets fixture options
*
* @return array
*/
public function getOptions();
/**
* Sets storage for fixtures
*
* @param Varien_Object $storage
* @return $this
*/
public function setStorage(Varien_Object $storage);
/**
* Retrieve fixture storage
*
* @return Varien_Object
*/
public function getStorage();
/**
* Retrieves storage data for a particular fixture scope
*
* @param string $key
* @param string|null $scope
*/
public function getStorageData($key, $scope = null);
/**
* Sets storage data for a particular fixture scope
*
* @param string $key
* @param mixed $value
* @param string|null $scope
*/
public function setStorageData($key, $value, $scope = null);
/**
* Returns current fixture scope
*
* @return string
*/
public function getScope();
/**
* Sets current fixture scope
*
*
* @param string $scope EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_LOCAL|EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED
*/
public function setScope($scope);
/**
* Check that current fixture scope is equal to SCOPE_DEFAULT
*
* @abstract
* @return boolean
*/
public function isScopeDefault();
/**
* Check that current fixture scope is equal to SCOPE_SHARED
*
* @return boolean
*/
public function isScopeShared();
/**
* Check that current fixture scope is equal to SCOPE_LOCAL
*
* @return boolean
*/
public function isScopeLocal();
/**
* Loads fixture files from test class annotations
*
* @param string $className
* @return $this
*/
public function loadForClass($className);
/**
* Sets fixture value
*
* @param string $key
* @param array[] $value
*
* @return $this
*/
public function setFixtureValue($key, $value);
/**
* Retrieves fixture value
*
* @param string $key
*
* @return array[]
*/
public function getFixtureValue($key);
/**
* Returns VFS wrapper instance
*
* @return EcomDev_PHPUnit_Model_Fixture_Vfs
*/
public function getVfs();
}
......@@ -24,8 +24,8 @@
*/
class EcomDev_PHPUnit_Model_Layout
extends Mage_Core_Model_Layout
implements EcomDev_PHPUnit_Constraint_Layout_Logger_Interface,
EcomDev_PHPUnit_Isolation_Interface
implements EcomDev_PHPUnit_Constraint_Layout_LoggerInterface,
EcomDev_PHPUnit_IsolationInterface
{
/**
* List of replaced blocks creation
......@@ -35,7 +35,7 @@ class EcomDev_PHPUnit_Model_Layout
protected $_replaceBlockCreation = array();
/**
* Records for gethering information about all,
* Records for gathering information about all,
* the actions that was performed
*
*
......@@ -83,8 +83,8 @@ class EcomDev_PHPUnit_Model_Layout
}
/**
* Overriden for possibility of replacing a block by mock object
* (non-PHPdoc)
* Overridden for possibility of replacing a block by mock object
*
* @see Mage_Core_Model_Layout::_getBlockInstance()
*/
protected function _getBlockInstance($block, array $attributes=array())
......@@ -182,6 +182,7 @@ class EcomDev_PHPUnit_Model_Layout
* @param string $action
* @param string $target
* @param array $parameters
* @param string $searchType
* @return boolean
*/
public function findByParameters($action, $target, array $parameters, $searchType = self::SEARCH_TYPE_AND)
......@@ -280,7 +281,6 @@ class EcomDev_PHPUnit_Model_Layout
/**
* Records action call
*
* (non-PHPdoc)
* @see Mage_Core_Model_Layout::_generateAction()
*/
protected function _generateAction($node, $parent)
......@@ -355,7 +355,7 @@ class EcomDev_PHPUnit_Model_Layout
/**
* Records information about new block creation
* (non-PHPdoc)
*
* @see Mage_Core_Model_Layout::_generateBlock()
*/
protected function _generateBlock($node, $parent)
......@@ -392,7 +392,7 @@ class EcomDev_PHPUnit_Model_Layout
/**
* Collects block creation
* (non-PHPdoc)
*
* @see Mage_Core_Model_Layout::addBlock()
*/
public function addBlock($block, $blockName)
......@@ -499,6 +499,8 @@ class EcomDev_PHPUnit_Model_Layout
* Returns block property by getter
*
* @param string $block
* @param $property
* @throws RuntimeException
* @return mixed
*/
public function getBlockProperty($block, $property)
......
<?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) 2013 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 for loadable test environment data
*
*/
interface EcomDev_PHPUnit_Model_LoadableInterface
{
/**
* Loads external data by test case instance
*
* @param PHPUnit_Framework_TestCase $testCase
* @return $this
*/
public function loadByTestCase(PHPUnit_Framework_TestCase $testCase);
/**
* Applies external data
*
* @return $this
*/
public function apply();
/**
* Reverts applied data
*
* @return $this
*/
public function discard();
}
......@@ -27,12 +27,14 @@ class EcomDev_PHPUnit_Model_Mysql4_Fixture extends Mage_Core_Model_Mysql4_Abstra
protected function _construct()
{
$this->_setResource('ecomdev_phpunit');
$this->_resourceModel = NULL;
}
/**
* Cleans table in test database
*
* @param string $tableEntity
* @throws EcomDev_PHPUnit_Model_Mysql4_Fixture_Exception
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture
*/
public function cleanTable($tableEntity)
......@@ -42,7 +44,7 @@ class EcomDev_PHPUnit_Model_Mysql4_Fixture extends Mage_Core_Model_Mysql4_Abstra
->delete($this->getTable($tableEntity));
} catch (Exception $e) {
throw new EcomDev_PHPUnit_Model_Mysql4_Fixture_Exception(
sprintf('Unable to clear records for a table "%s"', $tableEntity),
sprintf('Unable to clear records for a table "%s" - "%s"', $tableEntity, $e->getMessage()),
$e
);
}
......@@ -54,6 +56,8 @@ class EcomDev_PHPUnit_Model_Mysql4_Fixture extends Mage_Core_Model_Mysql4_Abstra
*
* @param string $tableEntity
* @param array $tableData
* @throws EcomDev_PHPUnit_Model_Mysql4_Fixture_Exception
* @return $this
*/
public function loadTableData($tableEntity, $tableData)
{
......@@ -72,7 +76,7 @@ class EcomDev_PHPUnit_Model_Mysql4_Fixture extends Mage_Core_Model_Mysql4_Abstra
);
} catch (Exception $e) {
throw new EcomDev_PHPUnit_Model_Mysql4_Fixture_Exception(
sprintf('Unable to insert/update records for a table "%s"', $tableEntity),
sprintf('Unable to insert/update records for a table "%s" - "%s"', $tableEntity, $e->getMessage()),
$e
);
}
......@@ -91,7 +95,7 @@ class EcomDev_PHPUnit_Model_Mysql4_Fixture extends Mage_Core_Model_Mysql4_Abstra
{
$record = array();
// Fullfil table records with data
// Populate table records with data
foreach ($tableColumns as $columnName => $definition) {
if (isset($row[$columnName])) {
$record[$columnName] = $this->_getTableRecordValue($row[$columnName]);
......@@ -112,6 +116,7 @@ class EcomDev_PHPUnit_Model_Mysql4_Fixture extends Mage_Core_Model_Mysql4_Abstra
*
*
* @param mixed $value
* @throws InvalidArgumentException
* @return string
*/
protected function _getTableRecordValue($value)
......@@ -129,6 +134,6 @@ class EcomDev_PHPUnit_Model_Mysql4_Fixture extends Mage_Core_Model_Mysql4_Abstra
return serialize($value['serialized']);
}
throw new InvalidArgumentException('Unrecognized type for DB column');
throw new InvalidArgumentException('Unrecognized type for DB column: '.print_r($value, 1));
}
}
\ No newline at end of file
}
<?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) 2013 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>
* @author Steve Rice <srice@endertech.com>
* @author Jonathan Day <jonathan@aligent.com.au>
*/
abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_AbstractAttribute
extends EcomDev_PHPUnit_Model_Mysql4_Fixture_AbstractComplex
{
protected $_setupModel = 'Mage_Eav_Model_Entity_Setup';
/**
* List of indexers required to build
*
* @var array
*/
protected $_requiredIndexers = array(
'catalog_product_attribute',
);
/**
* Original list of indexers required to build
*
* @var array
*/
protected $_originalIndexers = array();
/**
* Retrieve required indexers for re-building
*
* @return array
*/
public function getRequiredIndexers()
{
return $this->_requiredIndexers;
}
/**
* Run required indexers and reset to original required indexers
*
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract
*/
public function runRequiredIndexers()
{
if (empty($this->_options['doNotIndexAll'])) {
$indexer = Mage::getSingleton('index/indexer');
foreach ($this->getRequiredIndexers() as $indexerCode) {
if (empty($this->_options['doNotIndex'])
|| !in_array($indexerCode, $this->_options['doNotIndex'])) {
$indexer->getProcessByCode($indexerCode)
->reindexAll();
}
}
}
// Restoring original required indexers for making tests isolated
$this->_requiredIndexers = $this->_originalIndexers;
return $this;
}
/**
* Add indexer by specific code to required indexers list
*
* @param string $code
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract
*/
public function addRequiredIndexer($code)
{
if (!in_array($code, $this->_requiredIndexers)) {
$this->_requiredIndexers[] = $code;
}
return $this;
}
/**
* @param string $entityType
* @return array
*/
public function loadDefaultAttributes($entityType)
{
/** @var $eavConfig Mage_Eav_Model_Config */
$eavConfig = Mage::getSingleton('eav/config');
$attributeCodes = $eavConfig->getEntityAttributeCodes($entityType);
return $attributeCodes;
}
/**
* Loads EAV attribute into DB tables
*
* @throws UnexpectedValueException
* @throws InvalidArgumentException
* @param string $entityType
* @param array $values
* @return $this
*/
public function loadAttribute($entityType, $values)
{
/** @var $eavConfig Mage_Eav_Model_Config */
$eavConfig = Mage::getSingleton('eav/config');
/** @var $entityTypeModel Mage_Eav_Model_Entity_Type */
$entityTypeModel = $eavConfig->getEntityType($entityType);
$entityModel = $entityTypeModel->getEntity();
//use entity model to figure out setup class
$entityReflection = EcomDev_Utils_Reflection::getReflection($entityModel);
$classArray = explode('_', $entityReflection->getName());
$moduleName = $classArray[0] . '_' . $classArray[1];
$eavSetupModel = $this->_getSetupModelForModule($moduleName);
foreach ($values as $value) {
if (!isset($value['attribute_code'])) {
throw new InvalidArgumentException('Attribute definition must contain attribute_code');
}
/** @var $eavSetupModel Mage_Eav_Model_Entity_Setup */
$eavSetupModel->addAttribute($entityTypeModel->getEntityTypeCode(), $value['attribute_code'], $value);
}
return $this;
}
/**
* Remove fixture-generated attributes from database
*
* @param string $entityType
* @param array $attributes
* @throws EcomDev_PHPUnit_Model_Mysql4_Fixture_Exception
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_AbstractAttribute
*/
public function cleanAttributes($entityType, array $attributes)
{
$eavSetup = new Mage_Eav_Model_Entity_Setup('core_setup');
try {
if(empty($attributes)) {
throw new Exception('Attribute array cannot be empty');
}
else {
$attributeCodes = array();
foreach($attributes[$entityType] as $attribute){
$attributeCodes[] = $attribute['attribute_code'];
}
}
//delete entry from eav/attribute and allow FK cascade to delete all related values
//TODO: check if the attribute != is_user_defined (ie system), then *only* delete the attribute option values, not attribute definition
$this->_getWriteAdapter()
->delete(
$this->getTable('eav/attribute'),
array(
'entity_type_id = ?' => $eavSetup->getEntityTypeId($entityType),
'attribute_code IN (?)' => $attributeCodes,
)
);
$this->_getWriteAdapter()->commit();
} catch (Exception $e) {
throw new EcomDev_PHPUnit_Model_Mysql4_Fixture_Exception(
sprintf('Unable to clear records for a table "%s"', 'eav/attribute'),
$e
);
}
$this->resetAttributesAutoIncrement();
return $this;
}
/**
* Reset autoincrement value of all EAV attribute tables or those associated with an entity type
*
* @throws EcomDev_PHPUnit_Model_Mysql4_Fixture_Exception
* @param string $entityType
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_AbstractAttribute
*/
public function resetAttributesAutoIncrement($entityType = null)
{
//@TODO track which tables are altered
if ($entityType !== null) {
/** @var $eavConfig Mage_Eav_Model_Config */
$eavConfig = Mage::getSingleton('eav/config');
/** @var $entityTypeModel Mage_Eav_Model_Entity_Type */
$entityTypeModel = $eavConfig->getEntityType($entityType);
$this->resetTableAutoIncrement($entityTypeModel->getAdditionalAttributeTable());
} else {
//@TODO don't hardcode these
$this->resetTableAutoIncrement('eav/attribute');
$this->resetTableAutoIncrement('eav/attribute_set');
$this->resetTableAutoIncrement('eav/attribute_group');
$this->resetTableAutoIncrement('eav/attribute_label');
$this->resetTableAutoIncrement('eav/attribute_option');
$this->resetTableAutoIncrement('eav/attribute_option_value');
}
return $this;
}
/**
* Reset autoincrement value of a table
*
* @param string $table
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_AbstractAttribute
* @throws EcomDev_PHPUnit_Model_Mysql4_Fixture_Exception
*/
public function resetTableAutoIncrement($table)
{
try {
//reset table auto_increment to maximum value in table
$this->_getWriteAdapter()->query("ALTER TABLE `{$this->getTable($table)}` AUTO_INCREMENT = 1");
} catch (Exception $e) {
throw new EcomDev_PHPUnit_Model_Mysql4_Fixture_Exception(
sprintf('Unable to reset autoincrement for table "%s"', $table),
$e
);
}
return $this;
}
/**
* Get the setup model used by a Magento module
*
* @param $moduleName
* @return mixed
* @throws UnexpectedValueException
*/
protected function _getSetupModelForModule($moduleName)
{
$resources = Mage::getConfig()->getNode('global/resources')->children();
$resourceName = 'eav_setup';
$className = 'Mage_Eav_Model_Entity_Setup';
foreach ($resources as $resName => $resource) {
if (!$resource->setup) {
continue;
}
if (isset($resource->setup->module) && $resource->setup->module == $moduleName
&& isset($resource->setup->class)) {
$className = $resource->setup->getClassName();
$resourceName = $resName;
break;
}
}
$setupModel = new $className($resourceName);
$setupReflection = EcomDev_Utils_Reflection::getReflection($setupModel);
if (!$setupReflection->hasMethod('addAttribute')) {
throw new UnexpectedValueException('Problem loading EAV setup model');
}
return $setupModel;
}
}
<?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) 2013 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>
* @author Steve Rice <srice@endertech.com>
*/
abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_AbstractComplex
extends EcomDev_PHPUnit_Model_Mysql4_Fixture
{
/**
* Fixture options
*
* @var array
*/
protected $_options = array();
/**
* Fixture model
*
* @var EcomDev_PHPUnit_Model_FixtureInterface
*/
protected $_fixture = null;
/**
* Inject fixture model into complex loader
*
* @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_AbstractComplex
*/
public function setFixture($fixture)
{
$this->_fixture = $fixture;
return $this;
}
/**
* Set fixture options
*
* @param array $options
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_AbstractComplex
*/
public function setOptions(array $options)
{
$this->_options = $options;
return $this;
}
}
......@@ -14,180 +14,13 @@
* @copyright Copyright (c) 2013 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>
* @author Steve Rice <srice@endertech.com>
*/
/**
* @deprecated since 0.4.0
*/
abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_Attribute_Abstract
extends EcomDev_PHPUnit_Model_Mysql4_Fixture_Complex_Abstract
extends EcomDev_PHPUnit_Model_Mysql4_Fixture_AbstractAttribute
{
protected $_setupModel = 'Mage_Eav_Model_Entity_Setup';
/**
* @param string $entityType
* @return array
*/
public function loadDefaultAttributes($entityType)
{
/** @var $eavConfig Mage_Eav_Model_Config */
$eavConfig = Mage::getSingleton('eav/config');
$attributeCodes = $eavConfig->getEntityAttributeCodes($entityType);
return $attributeCodes;
}
/**
* Loads EAV attribute into DB tables
*
* @throws UnexpectedValueException
* @throws InvalidArgumentException
* @param string $entityType
* @param array $values
*/
public function loadAttribute($entityType, $values)
{
/** @var $eavConfig Mage_Eav_Model_Config */
$eavConfig = Mage::getSingleton('eav/config');
/** @var $entityTypeModel Mage_Eav_Model_Entity_Type */
$entityTypeModel = $eavConfig->getEntityType($entityType);
$entityModel = $entityTypeModel->getEntity();
//use entity model to figure out setup class
$entityReflection = EcomDev_Utils_Reflection::getRelflection($entityModel);
$classArray = explode('_', $entityReflection->getName());
$moduleName = $classArray[0] . '_' . $classArray[1];
$eavSetupModel = $this->_getSetupModelForModule($moduleName);
foreach ($values as $value) {
if (!isset($value['attribute_code'])) {
throw new InvalidArgumentException('Attribute definition must contain attribute_code');
}
/** @var $eavSetupModel Mage_Eav_Model_Entity_Setup */
$eavSetupModel->addAttribute($entityTypeModel->getEntityTypeCode(), $value['attribute_code'], $value);
}
}
/**
* Remove fixture-generated attributes from database
*
* @param string $entityType
* @param array $attributeCodes
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_Attribute_Abstract
* @throws EcomDev_PHPUnit_Model_Mysql4_Fixture_Exception
*/
public function cleanAttributes($entityType, array $attributeCodes)
{
$eavSetup = new Mage_Eav_Model_Entity_Setup('core_setup');
try {
//delete entry from eav/attribute and allow FK cascade to delete all related values
$this->_getWriteAdapter()
->delete(
$this->getTable('eav/attribute'),
array(
'entity_type_id = ?' => $eavSetup->getEntityTypeId($entityType),
'attribute_code IN (?)' => $attributeCodes,
)
);
$this->_getWriteAdapter()->commit();
} catch (Exception $e) {
throw new EcomDev_PHPUnit_Model_Mysql4_Fixture_Exception(
sprintf('Unable to clear records for a table "%s"', 'eav/attribute'),
$e
);
}
return $this;
}
/**
* Reset autoincrement value of all EAV attribute tables or those associated with an entity type
*
* @throws EcomDev_PHPUnit_Model_Mysql4_Fixture_Exception
* @param string $entityType
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_Attribute_Abstract
*/
public function resetAttributesAutoIncrement($entityType = null)
{
//@TODO track which tables are altered
if ($entityType !== null) {
/** @var $eavConfig Mage_Eav_Model_Config */
$eavConfig = Mage::getSingleton('eav/config');
/** @var $entityTypeModel Mage_Eav_Model_Entity_Type */
$entityTypeModel = $eavConfig->getEntityType($entityType);
$this->resetTableAutoIncrement($entityTypeModel->getAdditionalAttributeTable());
} else {
//@TODO don't hardcode these
$this->resetTableAutoIncrement('eav/attribute');
$this->resetTableAutoIncrement('eav/attribute_set');
$this->resetTableAutoIncrement('eav/attribute_group');
$this->resetTableAutoIncrement('eav/attribute_label');
$this->resetTableAutoIncrement('eav/attribute_option');
$this->resetTableAutoIncrement('eav/attribute_option_value');
}
return $this;
}
/**
* Reset autoincrement value of a table
*
* @param string $table
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_Attribute_Abstract
* @throws EcomDev_PHPUnit_Model_Mysql4_Fixture_Exception
*/
public function resetTableAutoIncrement($table)
{
try {
//reset table auto_increment to maximum value in table
$this->_getWriteAdapter()->query("ALTER TABLE `{$this->getTable($table)}` AUTO_INCREMENT = 1");
} catch (Exception $e) {
throw new EcomDev_PHPUnit_Model_Mysql4_Fixture_Exception(
sprintf('Unable to reset autoincrement for table "%s"', $table),
$e
);
}
return $this;
}
/**
* Get the setup model used by a Magento module
*
* @param $moduleName
* @return mixed
* @throws UnexpectedValueException
*/
protected function _getSetupModelForModule($moduleName)
{
$resources = Mage::getConfig()->getNode('global/resources')->children();
$resourceName = 'eav_setup';
$className = 'Mage_Eav_Model_Entity_Setup';
foreach ($resources as $resName => $resource) {
if (!$resource->setup) {
continue;
}
if (isset($resource->setup->module) && $resource->setup->module == $moduleName
&& isset($resource->setup->class)) {
$className = $resource->setup->getClassName();
$resourceName = $resName;
break;
}
}
$setupModel = new $className($resourceName);
$setupReflection = EcomDev_Utils_Reflection::getRelflection($setupModel);
if (!$setupReflection->hasMethod('addAttribute')) {
throw new UnexpectedValueException('Problem loading EAV setup model');
}
return $setupModel;
}
}
......@@ -18,7 +18,7 @@
*/
class EcomDev_PHPUnit_Model_Mysql4_Fixture_Attribute_Default
extends EcomDev_PHPUnit_Model_Mysql4_Fixture_Attribute_Abstract
extends EcomDev_PHPUnit_Model_Mysql4_Fixture_AbstractAttribute
{
}
......@@ -14,46 +14,13 @@
* @copyright Copyright (c) 2013 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>
* @author Steve Rice <srice@endertech.com>
*/
abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_Complex_Abstract extends EcomDev_PHPUnit_Model_Mysql4_Fixture
/**
* @deprecated since 0.4.0
*/
abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_Complex_Abstract
extends EcomDev_PHPUnit_Model_Mysql4_Fixture_AbstractComplex
{
/**
* Fixture options
*
* @var array
*/
protected $_options = array();
/**
* Fixture model
*
* @var EcomDev_PHPUnit_Model_Fixture_Interface
*/
protected $_fixture = null;
/**
* Inject fixture model into complex loader
*
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_Complex_Abstract
*/
public function setFixture($fixture)
{
$this->_fixture = $fixture;
return $this;
}
/**
* Set fixture options
*
* @param array $options
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_Complex_Abstract
*/
public function setOptions(array $options)
{
$this->_options = $options;
return $this;
}
}
......@@ -21,19 +21,19 @@
*
*
*/
abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Catalog_Abstract extends EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract
abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Catalog_Abstract
extends EcomDev_PHPUnit_Model_Mysql4_Fixture_AbstractEav
{
const SCOPE_TYPE_STORE = 'stores';
const SCOPE_TYPE_WEBSITE = 'websites';
/**
* Overriden to add GWS implementation for attribute records
* Overridden to add GWS implementation for attribute records
*
* @param array $row
* @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
* @param array $tableColumns
* @return array
* (non-PHPdoc)
* @see EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract::_getAttributeRecords()
*/
protected function _getAttributeRecords($row, $attribute, $tableColumns)
......@@ -43,7 +43,7 @@ abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Catalog_Abstract extends
// If the attribute is not global,
// then walk over all websites and stores scopes for attribute value
if ($attribute->isScopeStore() || $attribute->isScopeWebsite()) {
// Search for website values and fullfil data per website's store
// Search for website values and populate data per website's store
$storeValues = array();
foreach ($this->_getGwsCodes($row, self::SCOPE_TYPE_WEBSITE) as $websiteCode) {
$website = Mage::app()->getWebsite($websiteCode);
......@@ -96,6 +96,7 @@ abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Catalog_Abstract extends
*
* @param array $row
* @param string $scopeType
* @return array
*/
protected function _getGwsCodes($row, $scopeType = self::SCOPE_TYPE_STORE)
{
......@@ -130,8 +131,8 @@ abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Catalog_Abstract extends
}
/**
* Overriden to add default store id
* (non-PHPdoc)
* Overridden to add default store id
*
* @see EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract::_getAttributeValueInfo()
*/
protected function _getAttributeValueInfo($row, $attribute)
......
......@@ -28,7 +28,7 @@ class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Catalog_Category extends EcomDev_
);
/**
* Overriden to add easy fixture loading for product associations
* Overridden to add easy fixture loading for product associations
* (non-PHPdoc)
* @see EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract::_getCustomTableRecords()
*/
......
......@@ -31,8 +31,8 @@ class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Catalog_Product extends EcomDev_P
/**
* Overridden to fix issue with flat tables existance mark
* (non-PHPdoc)
* Overridden to fix issue with flat tables existence mark
*
* @see EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract::loadEntity()
*/
public function loadEntity($entityType, $values)
......@@ -49,7 +49,7 @@ class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Catalog_Product extends EcomDev_P
/**
* Overridden to add easy fixture loading for websites and categories associations
* (non-PHPdoc)
*
* @see EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract::_getCustomTableRecords()
*/
protected function _getCustomTableRecords($row, $entityTypeModel)
......@@ -59,13 +59,18 @@ class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Catalog_Product extends EcomDev_P
$records += $this->_getTierPriceRecords($row, $entityTypeModel);
$records += $this->_getCategoryAssociationRecords($row, $entityTypeModel);
$records += $this->_getProductStockRecords($row, $entityTypeModel);
$records += $this->_getProductSuperRelations($row, $entityTypeModel);
$records += $this->_getProductBundleRelations($row, $entityTypeModel);
return $records;
}
/**
* Changed to support price attribute type multi-scope
* (non-PHPdoc)
*
* @param array $row
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @param array $tableColumns
* @return array
* @see EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Catalog_Abstract::_getAttributeRecords()
*/
protected function _getAttributeRecords($row, $attribute, $tableColumns)
......@@ -79,6 +84,91 @@ class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Catalog_Product extends EcomDev_P
return parent::_getAttributeRecords($row, $attribute, $tableColumns);
}
/**
* Generates records for catalog_product_bundle_option and catalog_product_bundle_selection tables
*
* @param array $row
* @param Mage_Eav_Model_Entity_Type $entityTypeModel
* @return array
* @throws RuntimeException
*/
protected function _getProductBundleRelations($row, $entityTypeModel){
$result = array();
if (isset($row['bundle_options']) && is_array($row['bundle_options'])) {
$aOptions = array();
$aSelections = array();
foreach($row['bundle_options'] as $iOptionId => $aOption){
$aOptions[] = array(
'option_id' => $iOptionId,
'parent_id' => $row[$this->_getEntityIdField($entityTypeModel)],
'type' => 'radio' //TODO: allow specification of different types
);
foreach($aOption as $iSelectionProductId){
$aSelections[] = array(
'option_id' => $iOptionId,
'parent_product_id' => $row[$this->_getEntityIdField($entityTypeModel)],
'product_id' => $iSelectionProductId,
);
}
}
if(!empty($aOptions)){
$result += array('bundle/option' => $aOptions);
}
if(!empty($aSelections)){
$result += array('bundle/selection' => $aSelections);
}
}
return $result;
}
/**
* Generates records for catalog_product_super_attribute and catalog_product_super_link tables
*
* @param array $row
* @param Mage_Eav_Model_Entity_Type $entityTypeModel
* @throws Exception
* @return array
*/
protected function _getProductSuperRelations($row, $entityTypeModel)
{
$result = array();
if (isset($row['super_attributes']) && is_array($row['super_attributes'])) {
$records = array();
$attributeCodes = $entityTypeModel->getAttributeCollection();
foreach ($row['super_attributes'] as $attributeCode) {
$attribute = $attributeCodes->getItemByColumnValue('attribute_code', $attributeCode);
if(!$attribute){
throw new Exception('Super attribute not found with code: ' . $attributeCode);
}
$attributeId = $attribute->getId();
$records[] = array(
'product_id' => $row[$this->_getEntityIdField($entityTypeModel)],
'attribute_id' => $attributeId
);
}
if ($records) {
$result += array('catalog/product_super_attribute' => $records);
}
}
if (isset($row['configurable_children']) && is_array($row['configurable_children'])) {
$records = array();
foreach ($row['configurable_children'] as $childId) {
$records[] = array(
'parent_id' => $row[$this->_getEntityIdField($entityTypeModel)],
'product_id' => $childId
);
}
if ($records) {
$result += array('catalog/product_super_link' => $records);
}
}
return $result;
}
/**
* Generates records for catalog_product_website table
*
......@@ -195,7 +285,7 @@ class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Catalog_Product extends EcomDev_P
/**
* Adding enabled and visibility indexes
*
* (non-PHPdoc)
*
* @see EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract::_customEntityAction()
*/
protected function _customEntityAction($entity, $entityTypeModel)
......
......@@ -21,7 +21,7 @@
*
*
*/
class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Default extends EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract
class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Default extends EcomDev_PHPUnit_Model_Mysql4_Fixture_AbstractEav
{
}
\ No newline at end of file
<?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) 2013 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_Observer
{
const XML_PATH_TEST_HELPERS = 'phpunit/suite/helpers';
/**
* Registers default test helpers
*
*/
public function registerDefaultTestHelpers()
{
foreach (Mage::getConfig()->getNode(self::XML_PATH_TEST_HELPERS)->children() as $helperNode) {
$helperClass = (string)$helperNode;
if ($helperClass && class_exists($helperClass)) {
$helper = new $helperClass();
if (!$helper instanceof EcomDev_PHPUnit_HelperInterface) {
throw new RuntimeException(
sprintf(
'Test helpers should implement %s, but %s is not implementing it.',
'EcomDev_PHPUnit_HelperInterface',
$helperClass
)
);
}
EcomDev_PHPUnit_Helper::add($helper);
}
}
}
}
\ No newline at end of file
......@@ -17,30 +17,11 @@
*/
/**
* Interface for loadable test environment data
*
* @deprecated since 0.4.0
*/
interface EcomDev_PHPUnit_Model_Test_Loadable_Interface
interface EcomDev_PHPUnit_Model_Test_LoadableInterface
extends EcomDev_PHPUnit_Model_LoadableInterface
{
/**
* Loads external data by test case instance
*
* @param PHPUnit_Framework_TestCase $testCase
* @return EcomDev_PHPUnit_Model_Test_Loadable_Interface
*/
public function loadByTestCase(PHPUnit_Framework_TestCase $testCase);
/**
* Applies external data
*
* @return EcomDev_PHPUnit_Model_Test_Loadable_Interface
*/
public function apply();
/**
* Reverts applied data
*
* @return EcomDev_PHPUnit_Model_Test_Loadable_Interface
*/
public function discard();
}
<?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) 2013 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_AbstractLoader
implements EcomDev_PHPUnit_Model_Yaml_LoaderInterface
{
const DATA_DIR = '_data';
protected $_typeMap = array(
'fixtures' => 'fx',
'providers' => 'dp',
'expectations' => 'ex'
);
/**
* 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);
/**
* Looks in path for possible existent fixture
*
* @param string|array $path
* @param string $fileName
* @param string $type
* @return bool|string
*/
protected function _checkFilePath($path, $fileName, $type)
{
if (is_array($path)) {
foreach ($path as $value) {
if ($filePath = $this->_checkFilePath($value, $fileName, $type)) {
return $filePath;
}
}
return false;
}
if (isset($this->_typeMap[$type])
&& file_exists($filePath = $path . DS . self::DATA_DIR . DS . $this->_typeMap[$type] . '-' . $fileName)) {
return $filePath;
}
if (file_exists($filePath = $path . DS . $type . DS . $fileName)) {
return $filePath;
}
return false;
}
}
......@@ -31,14 +31,14 @@ class EcomDev_PHPUnit_Model_Yaml_Loader
/**
* YAML file loaders
*
* @var EcomDev_PHPUnit_Model_Yaml_Loader_Interface[]
* @var EcomDev_PHPUnit_Model_Yaml_LoaderInterface[]
*/
protected $_loaders = array();
/**
* Returns arrays of loaders
*
* @return EcomDev_PHPUnit_Model_Yaml_Loader_Interface[]
* @return EcomDev_PHPUnit_Model_Yaml_LoaderInterface[]
*/
public function getLoaders()
{
......@@ -50,12 +50,12 @@ class EcomDev_PHPUnit_Model_Yaml_Loader
}
/**
* Adds a loader to list of loders
* Adds a loader to list of loaders
*
* @param EcomDev_PHPUnit_Model_Yaml_Loader_Interface $loader
* @param EcomDev_PHPUnit_Model_Yaml_LoaderInterface $loader
* @return EcomDev_PHPUnit_Model_Yaml_Loader
*/
public function addLoader(EcomDev_PHPUnit_Model_Yaml_Loader_Interface $loader)
public function addLoader(EcomDev_PHPUnit_Model_Yaml_LoaderInterface $loader)
{
$this->_loaders[] = $loader;
return $this;
......
......@@ -16,79 +16,11 @@
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
abstract class EcomDev_PHPUnit_Model_Yaml_Loader_Abstract implements EcomDev_PHPUnit_Model_Yaml_Loader_Interface
/**
* @deprecated since 0.4.0
*/
abstract class EcomDev_PHPUnit_Model_Yaml_Loader_Abstract
extends EcomDev_PHPUnit_Model_Yaml_AbstractLoader
{
const DATA_DIR = '_data';
protected $_typeMap = array(
'fixtures' => 'fx',
'providers' => 'dp',
'expectations' => 'ex'
);
/**
* 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);
/**
* Looks in path for possible existent fixture
*
* @param string|array $path
* @param string $fileName
* @param string $type
* @return bool|string
*/
protected function _checkFilePath($path, $fileName, $type)
{
if (is_array($path)) {
foreach ($path as $value) {
if ($filePath = $this->_checkFilePath($value, $fileName, $type)) {
return $filePath;
}
}
return false;
}
if (isset($this->_typeMap[$type])
&& file_exists($filePath = $path . DS . self::DATA_DIR . DS . $this->_typeMap[$type] . '-' . $fileName)) {
return $filePath;
}
if (file_exists($filePath = $path . DS . $type . DS . $fileName)) {
return $filePath;
}
return false;
}
}
}
\ No newline at end of file
......@@ -16,7 +16,7 @@
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
class EcomDev_PHPUnit_Model_Yaml_Loader_Default extends EcomDev_PHPUnit_Model_Yaml_Loader_Abstract
class EcomDev_PHPUnit_Model_Yaml_Loader_Default extends EcomDev_PHPUnit_Model_Yaml_AbstractLoader
{
/**
* Returns processed file path
......
......@@ -16,7 +16,7 @@
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
class EcomDev_PHPUnit_Model_Yaml_Loader_Global extends EcomDev_PHPUnit_Model_Yaml_Loader_Abstract
class EcomDev_PHPUnit_Model_Yaml_Loader_Global extends EcomDev_PHPUnit_Model_Yaml_AbstractLoader
{
/**
* Returns processed file path
......
......@@ -16,16 +16,11 @@
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
interface EcomDev_PHPUnit_Model_Yaml_Loader_Interface
/**
* @deprecated since 0.4.0
*/
interface EcomDev_PHPUnit_Model_Yaml_Loader_Interface
extends EcomDev_PHPUnit_Model_Yaml_LoaderInterface
{
/**
* 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
......@@ -16,7 +16,7 @@
* @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
class EcomDev_PHPUnit_Model_Yaml_Loader_Module extends EcomDev_PHPUnit_Model_Yaml_AbstractLoader
{
/**
* Returns processed file path based on module test directory
......
<?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) 2013 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_LoaderInterface
{
/**
* 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
......@@ -17,11 +17,20 @@
*/
use EcomDev_PHPUnit_Test_Case_Util as TestUtil;
use EcomDev_PHPUnit_Helper as TestHelper;
/**
* Basic test case class
*
* Basic test case class, implements test helpers for easy working with Magento
*
* @method EcomDev_PHPUnit_Mock_Proxy mockClassAlias(string $type, $classAlias, array $methods = array(), array $constructorArgs = array())
* @method EcomDev_PHPUnit_Mock_Proxy mockModel($classAlias, array $methods = array(), array $constructorArgs = array())
* @method EcomDev_PHPUnit_Mock_Proxy mockBlock($classAlias, array $methods = array(), array $constructorArgs = array())
* @method EcomDev_PHPUnit_Mock_Proxy mockHelper($classAlias, array $methods = array(), array $constructorArgs = array())
* @method EcomDev_PHPUnit_Mock_Proxy mockSession($classAlias, array $methods = array())
* @method EcomDev_PHPUnit_Mock_Proxy adminSession(array $resources = array())
* @method EcomDev_PHPUnit_Mock_Proxy customerSession(int $customerId)
* @method EcomDev_PHPUnit_Mock_Proxy guestSession()
* @method Varien_Event_Observer generateObserver(array $eventData, string $eventName = null)
*/
abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
{
......@@ -230,13 +239,13 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
}
/**
* Assert that JSON string doesn't matches expected value,
* Assert that JSON string does not matches expected value,
* Can accept different match type for matching logic.
*
* @param string $string
* @param array $expectedValue
* @param string $message
* @param strign $matchType
* @param string $matchType
*/
public static function assertJsonNotMatch($string, array $expectedValue, $message = '',
$matchType = EcomDev_PHPUnit_Constraint_Json::MATCH_AND)
......@@ -325,6 +334,7 @@ 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 $this
*/
protected function replaceByMock($type, $classAlias, $mock)
{
......@@ -372,20 +382,18 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
*
* @param string $type block|model|helper
* @param string $classAlias
* @return PHPUnit_Framework_MockObject_MockBuilder
* @return EcomDev_PHPUnit_Mock_Proxy
*/
public function getGroupedClassMockBuilder($type, $classAlias)
{
$className = $this->getGroupedClassName($type, $classAlias);
return $this->getMockBuilder($className);
return TestUtil::getGroupedClassMockBuilder($this, $type, $classAlias);
}
/**
* Retrieves a mock builder for a block class alias
*
* @param string $classAlias
* @return PHPUnit_Framework_MockObject_MockBuilder
* @return EcomDev_PHPUnit_Mock_Proxy
*/
public function getBlockMockBuilder($classAlias)
{
......@@ -396,7 +404,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
* Retrieves a mock builder for a model class alias
*
* @param string $classAlias
* @return PHPUnit_Framework_MockObject_MockBuilder
* @return EcomDev_PHPUnit_Mock_Proxy
*/
public function getModelMockBuilder($classAlias)
{
......@@ -407,7 +415,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
* Retrieves a mock builder for a resource model class alias
*
* @param string $classAlias
* @return PHPUnit_Framework_MockObject_MockBuilder
* @return EcomDev_PHPUnit_Mock_Proxy
*/
public function getResourceModelMockBuilder($classAlias)
{
......@@ -418,7 +426,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
* Retrieves a mock builder for a helper class alias
*
* @param string $classAlias
* @return PHPUnit_Framework_MockObject_MockBuilder
* @return EcomDev_PHPUnit_Mock_Proxy
*/
public function getHelperMockBuilder($classAlias)
{
......@@ -436,7 +444,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
* @param boolean $callOriginalConstructor
* @param boolean $callOriginalClone
* @param boolean $callAutoload
* @return PHPUnit_Framework_MockObject_MockObject
* @return EcomDev_PHPUnit_Mock_Proxy
*/
public function getModelMock($classAlias, $methods = array(), $isAbstract = false,
array $constructorArguments = array(),
......@@ -460,7 +468,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
* @param boolean $callOriginalConstructor
* @param boolean $callOriginalClone
* @param boolean $callAutoload
* @return PHPUnit_Framework_MockObject_MockObject
* @return EcomDev_PHPUnit_Mock_Proxy
*/
public function getResourceModelMock($classAlias, $methods = array(), $isAbstract = false,
array $constructorArguments = array(),
......@@ -484,7 +492,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
* @param boolean $callOriginalConstructor
* @param boolean $callOriginalClone
* @param boolean $callAutoload
* @return PHPUnit_Framework_MockObject_MockObject
* @return EcomDev_PHPUnit_Mock_Proxy
*/
public function getHelperMock($classAlias, $methods = array(), $isAbstract = false,
array $constructorArguments = array(),
......@@ -508,7 +516,7 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
* @param boolean $callOriginalConstructor
* @param boolean $callOriginalClone
* @param boolean $callAutoload
* @return PHPUnit_Framework_MockObject_MockObject
* @return EcomDev_PHPUnit_Mock_Proxy
*/
public function getBlockMock($classAlias, $methods = array(), $isAbstract = false,
array $constructorArguments = array(),
......@@ -526,14 +534,11 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
*
* @param string $type block/model/helper/resource_model
* @param string $classAlias
* @return string
*/
protected function getGroupedClassName($type, $classAlias)
{
if ($type === 'resource_model') {
return $this->app()->getConfig()->getResourceModelClassName($classAlias);
}
return $this->app()->getConfig()->getGroupedClassName($type, $classAlias);
return TestUtil::getGroupedClassName($type, $classAlias);
}
/**
......@@ -675,7 +680,7 @@ 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
* @deprecated since 0.3.0
*/
public static function getYamlFilePathByClass($className, $type, $name)
{
......@@ -705,4 +710,16 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
TestUtil::setCurrentStore($store);
return $this;
}
/**
* Calling of the helper method
*
* @param string $method
* @param array $args
* @return mixed
*/
public function __call($method, array $args)
{
return TestUtil::call($method, $args);
}
}
......@@ -26,12 +26,12 @@ abstract class EcomDev_PHPUnit_Test_Case_Config extends EcomDev_PHPUnit_Test_Cas
/**
* Returns a new instance of EcomDev_PHPUnit_Constraint_Config
*
* @param EcomDev_PHPUnit_Constraint_Config_Interface $configContstraint
* @param EcomDev_PHPUnit_Constraint_ConfigInterface $configConstraint
* @return EcomDev_PHPUnit_Constraint_Config
*/
public static function config($configContstraint)
public static function config($configConstraint)
{
return new EcomDev_PHPUnit_Constraint_Config($configContstraint);
return new EcomDev_PHPUnit_Constraint_Config($configConstraint);
}
/**
......@@ -173,7 +173,7 @@ abstract class EcomDev_PHPUnit_Test_Case_Config extends EcomDev_PHPUnit_Test_Cas
* @return EcomDev_PHPUnit_Constraint_Config
*/
public static function configEventObserver($area, $eventName, $observerClassAlias, $observerMethod,
$type = EcomDev_PHPUnit_Constraint_Config_EventObserver::TYPE_DEFINDED, $observerName = null)
$type = EcomDev_PHPUnit_Constraint_Config_EventObserver::TYPE_DEFINED, $observerName = null)
{
return self::config(
new EcomDev_PHPUnit_Constraint_Config_EventObserver($area, $eventName, $observerClassAlias, $observerMethod, $type, $observerName)
......@@ -385,8 +385,7 @@ abstract class EcomDev_PHPUnit_Test_Case_Config extends EcomDev_PHPUnit_Test_Cas
* @param string|null $from
* @param string|null $to
* @param string|null $moduleName
* @param string|null $moduleName
* @param mixed $expectedResourceName
* @param string|null $resourceName
* @param string $message
*/
public static function assertSchemeSetupScriptVersions($from = null, $to = null,
......@@ -402,8 +401,7 @@ abstract class EcomDev_PHPUnit_Test_Case_Config extends EcomDev_PHPUnit_Test_Cas
* @param string|null $from
* @param string|null $to
* @param string|null $moduleName
* @param string|null $moduleName
* @param mixed $expectedResourceName
* @param string|null $resourceName
* @param string $message
*/
public static function assertDataSetupScriptVersions($from = null, $to = null,
......@@ -1200,6 +1198,8 @@ abstract class EcomDev_PHPUnit_Test_Case_Config extends EcomDev_PHPUnit_Test_Cas
*
* @param string $area (frontend|adminhtml)
* @param string $expectedFileName
* @param string $theme
* @param string|null $designPackage
* @param string $message
*/
public static function assertLayoutFileExistsInTheme($area, $expectedFileName, $theme,
......@@ -1236,7 +1236,7 @@ abstract class EcomDev_PHPUnit_Test_Case_Config extends EcomDev_PHPUnit_Test_Cas
self::assertThatConfig(
self::configEventObserver(
$area, $eventName, $observerClassAlias, $observerMethod,
EcomDev_PHPUnit_Constraint_Config_EventObserver::TYPE_DEFINDED,
EcomDev_PHPUnit_Constraint_Config_EventObserver::TYPE_DEFINED,
$observerName
),
$message
......@@ -1262,7 +1262,7 @@ abstract class EcomDev_PHPUnit_Test_Case_Config extends EcomDev_PHPUnit_Test_Cas
self::logicalNot(
self::configEventObserver(
$area, $eventName, $observerClassAlias, $observerMethod,
EcomDev_PHPUnit_Constraint_Config_EventObserver::TYPE_DEFINDED,
EcomDev_PHPUnit_Constraint_Config_EventObserver::TYPE_DEFINED,
$observerName
)
),
......
<?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) 2013 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>
*/
use EcomDev_PHPUnit_Helper as TestHelper;
use EcomDev_PHPUnit_Test_Case_Util as TestUtil;
/**
* Helper for stubbing customer session
*
*
*/
class EcomDev_PHPUnit_Test_Case_Helper_Customer extends EcomDev_PHPUnit_AbstractHelper
{
/**
* Logs in as a customer by customer id and store id
*
* @param int $customerId
* @param string|int|null $storeId
*
* @return EcomDev_PHPUnit_Mock_Proxy
*/
public function helperCustomerSession($customerId, $storeId = null)
{
$customerSessionMock = TestHelper::invoke(
'mockSession',
'customer/session',
array('renewSession')
);
if ($storeId === null) {
$storeId = TestUtil::app()->getAnyStoreView()->getCode();
}
TestUtil::setCurrentStore($storeId);
$customerSessionMock->loginById($customerId);
return $customerSessionMock;
}
}
<?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) 2013 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Mike Pretzlaw <pretzlaw@gmail.com>
*/
use EcomDev_PHPUnit_Helper as TestHelper;
use EcomDev_PHPUnit_Test_Case_Util as TestUtil;
/**
* Helper for stubbing customer session
*
*
*/
class EcomDev_PHPUnit_Test_Case_Helper_Guest extends EcomDev_PHPUnit_AbstractHelper
{
/**
* Start session as guest.
*
* @param string|int|null $storeId
*
* @return EcomDev_PHPUnit_Mock_Proxy
*/
public function helperGuestSession($storeId = null)
{
$guestSessionMock = TestHelper::invoke(
'mockSession',
'core/session',
array('renewSession')
);
/** @var Mage_Core_Model_Session $session */
$session = $guestSessionMock->getMock();
$_GET[$session->getSessionIdQueryParam()] = $session->getSessionId(); // some action need that (loginPost, ...)
if ($storeId === null)
{
$storeId = TestUtil::app()->getAnyStoreView()->getCode();
}
TestUtil::setCurrentStore($storeId);
return $guestSessionMock;
}
}
<?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) 2013 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>
*/
use EcomDev_PHPUnit_Test_Case_Util as TestUtil;
/**
* Mock helper for Test Case
*
*/
class EcomDev_PHPUnit_Test_Case_Helper_Mock extends EcomDev_PHPUnit_AbstractHelper
{
/**
* Creates a mockery for a class alias of particular type
*
* @param string $type
* @param string $classAlias
* @param array $methods
* @param array $constructorArgs
*
* @return EcomDev_PHPUnit_Mock_Proxy
*/
public function helperMockClassAlias($type, $classAlias, array $methods = array(), array $constructorArgs = array())
{
return TestUtil::getGroupedClassMockBuilder($this->testCase, $type, $classAlias)
->setConstructorArgs($constructorArgs)
->setMethods($methods);
}
/**
* Creates a mock for a model by its class alias
*
* @param string $classAlias
* @param array $methods
* @param array $constructorArgs
*
* @return EcomDev_PHPUnit_Mock_Proxy
*/
public function helperMockModel($classAlias, array $methods = array(), array $constructorArgs = array())
{
return $this->helperMockClassAlias('model', $classAlias, $methods, $constructorArgs);
}
/**
* Creates a mock for a block by its class alias
*
* @param string $classAlias
* @param array $methods
* @param array $constructorArgs
*
* @return EcomDev_PHPUnit_Mock_Proxy
*/
public function helperMockBlock($classAlias, array $methods = array(), array $constructorArgs = array())
{
return $this->helperMockClassAlias('block', $classAlias, $methods, $constructorArgs);
}
/**
* Creates a mock for a block by its class alias
*
* @param string $classAlias
* @param array $methods
* @param array $constructorArgs
*
* @return EcomDev_PHPUnit_Mock_Proxy
*/
public function helperMockHelper($classAlias, array $methods = array(), array $constructorArgs = array())
{
return $this->helperMockClassAlias('helper', $classAlias, $methods, $constructorArgs);
}
}
<?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) 2013 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>
*/
/**
* Helper for stubbing event observer in Magento
*
*
*/
class EcomDev_PHPUnit_Test_Case_Helper_Observer extends EcomDev_PHPUnit_AbstractHelper
{
/**
* Generates observer object
*
* @param array $eventData
* @param string $eventName
*
* @return Varien_Event_Observer
*/
public function helperGenerateObserver(
$eventData, $eventName = null)
{
$event = new Varien_Event($eventData);
$observer = new Varien_Event_Observer();
$observer->setEvent($event);
if ($eventName) {
$event->setName($eventName);
$observer->setEventName($eventName);
}
$observer->addData($eventData);
return $observer;
}
}
<?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) 2013 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>
*/
use EcomDev_PHPUnit_Test_Case_Util as TestUtil;
/**
* Session mocks helper
*
*/
class EcomDev_PHPUnit_Test_Case_Helper_Session
extends EcomDev_PHPUnit_AbstractHelper
implements EcomDev_PHPUnit_Helper_ListenerInterface
{
/**
* Loaded ACL model for admin session mocks
*
* @var Mage_Admin_Model_Acl
*/
protected $acl;
/**
* Creates a mockery for session
*
* @param string $classAlias
* @param array $methods
*
* @return EcomDev_PHPUnit_Mock_Proxy
*/
public function helperMockSession($classAlias, array $methods = array())
{
$sessionMock = EcomDev_PHPUnit_Helper::invoke('mockModel', $classAlias, $methods)
->disableOriginalConstructor();
TestUtil::replaceByMock('singleton', $classAlias, $sessionMock);
return $sessionMock;
}
/**
* Helper for mocking admin panel session
*
* @param array $resources
* @return EcomDev_PHPUnit_Mock_Proxy
*/
public function helperAdminSession(array $resources = array())
{
$session = $this->helperMockSession('admin/session', array('refreshAcl'));
$user = $this->createUser();
$this->loadRules($user, $this->getAcl(), $resources);
$session->setAcl($this->getAcl());
$session->setUser($user);
return $session;
}
/**
* Returns an instance of ACL object that will be used for all
* admin stubs
*
* @return Mage_Admin_Model_Acl
*/
public function getAcl()
{
if ($this->acl === null) {
$this->acl = Mage::getModel('admin/acl');
Mage::getSingleton('admin/config')->loadAclResources($this->acl);
}
return $this->acl;
}
/**
* Loads role rules into ACL for admin user
*
* @param Mage_Admin_Model_User $user
* @param Mage_Admin_Model_Acl $acl
* @param array $allowedResources
*
* @return $this
*/
public function loadRules(Mage_Admin_Model_User $user, Mage_Admin_Model_Acl $acl, array $allowedResources = array())
{
$userRole = Mage::getModel('admin/acl_role_user', Mage_Admin_Model_Acl::ROLE_TYPE_USER . $user->getId());
$acl->addRole($userRole);
if (empty($allowedResources)) {
$acl->allow($userRole);
$acl->allow($userRole, $acl->getResources());
return $this;
}
$aclResources = $acl->getResources();
$allow = array();
foreach ($allowedResources as $resource) {
$childResources = array_filter(
$aclResources,
function ($entry) use ($resource) {
return strpos($entry, 'admin/' . $resource) === 0;
}
);
$allow = array_merge($allow, $childResources);
}
$deny = array();
foreach ($aclResources as $resource) {
if (!in_array($resource, $allow)) {
$deny[] = $resource;
}
}
$acl->allow($userRole, $allow);
$acl->deny($userRole, $deny);
return $this;
}
/**
* Creates a new instance of user with unique id
*
* Used for stubbing admin user roles
*
* @param int $entropy
* @return Mage_Admin_Model_User
*/
public function createUser($entropy = 3)
{
$userId = floor(microtime(true)*pow(10, $entropy) - floor(time()/100)*100*pow(10, $entropy));
// Fix for EE gws functionality
$userRole = Mage::getModel('admin/roles');
$userRole->setGwsIsAll(1);
$user = EcomDev_PHPUnit_Helper::invoke('mockModel', 'admin/user', array('reload'))->getMockInstance();
$user->setId($userId);
EcomDev_Utils_Reflection::setRestrictedPropertyValue($user, '_role', $userRole);
return $user;
}
/**
* Does nothing during test setup
*
*
*/
public function setUp()
{
}
/**
* Clean ups acl roles information after test completed
*
*/
public function tearDown()
{
if ($this->acl !== null) {
$this->acl->removeRoleAll();
}
}
}
......@@ -59,6 +59,8 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
$this->getAppReflection()->getMethod('applyTestScope')->invoke(null);
}
$this->firstLevelTestSuite = $suite;
Mage::dispatchEvent('phpunit_suite_start_after', array(
'suite' => $suite,
......@@ -72,7 +74,7 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
'listener' => $this
));
EcomDev_PHPUnit_Test_Case_Util::getFixture($suite->getName())
->setScope(EcomDev_PHPUnit_Model_Fixture_Interface::SCOPE_SHARED)
->setScope(EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED)
->loadForClass($suite->getName());
$annotations = PHPUnit_Util_Test::parseTestMethodAnnotations(
......@@ -102,7 +104,7 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
'listener' => $this
));
EcomDev_PHPUnit_Test_Case_Util::getFixture($suite->getName())
->setScope(EcomDev_PHPUnit_Model_Fixture_Interface::SCOPE_SHARED)
->setScope(EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED)
->discard();
Mage::dispatchEvent('phpunit_test_case_end_after', array(
'suite' => $suite,
......@@ -139,8 +141,9 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
'listener' => $this
));
if ($test instanceof PHPUnit_Framework_TestCase) {
EcomDev_PHPUnit_Helper::setTestCase($test);
EcomDev_PHPUnit_Test_Case_Util::getFixture(get_class($test))
->setScope(EcomDev_PHPUnit_Model_Fixture_Interface::SCOPE_LOCAL)
->setScope(EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_LOCAL)
->loadByTestCase($test);
$annotations = $test->getAnnotations();
EcomDev_PHPUnit_Test_Case_Util::getFixture()
......@@ -148,6 +151,7 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
->apply();
EcomDev_PHPUnit_Test_Case_Util::setUp();
EcomDev_PHPUnit_Helper::setUp();
}
Mage::dispatchEvent('phpunit_test_start_after', array(
'test' => $test,
......@@ -170,7 +174,7 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
if ($test instanceof PHPUnit_Framework_TestCase) {
EcomDev_PHPUnit_Test_Case_Util::getFixture(get_class($test))
->setScope(EcomDev_PHPUnit_Model_Fixture_Interface::SCOPE_LOCAL)
->setScope(EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_LOCAL)
->discard(); // Clear applied fixture
if (EcomDev_PHPUnit_Test_Case_Util::getExpectation(get_class($test))->isLoaded()) {
......@@ -178,6 +182,7 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
}
EcomDev_PHPUnit_Test_Case_Util::tearDown();
EcomDev_PHPUnit_Helper::tearDown();
}
Mage::dispatchEvent('phpunit_test_end_after', array(
......@@ -258,4 +263,23 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
// No action is required
}
/**
* Risky test.
*
* @param PHPUnit_Framework_Test $test
* @param Exception $e
* @param float $time
* @since Method available since Release 4.0.0
*/
public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time)
{
Mage::dispatchEvent('phpunit_test_risky', array(
'test' => $test,
'exception' => $e,
'time' => $time,
'listener' => $this
));
// No action required
}
}
\ No newline at end of file
......@@ -93,6 +93,7 @@ class EcomDev_PHPUnit_Test_Suite extends PHPUnit_Framework_TestSuite
* @param string $searchPath path for searching files with tests
* @param string $moduleCodeDir path where the module files are placed (e.g. app/code/local),
* used for determining the class name
* @return array
*/
protected static function _loadTestCases($searchPath, $moduleCodeDir)
{
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
john_doe:
- 1
jane_doe:
- 2
unknown_customer:
- 3
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment