Skip to content
This repository has been archived by the owner on May 27, 2023. It is now read-only.

Dev #275

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open

Dev #275

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b937a83
Change to using an array for old scope data
LeeSaferite Mar 5, 2014
b18329d
Convert to using a stack for test scope storage (see issue #178)
LeeSaferite Mar 5, 2014
e601785
Clear params on dispatch
Apr 24, 2014
e7c5ba3
Reset to array instead of null
Apr 25, 2014
cdc2129
Fix issue with current store code
IvanChepurnyi Oct 31, 2014
2589fa9
Merge pull request #189 from rskuipers/feature/fix-params
IvanChepurnyi Nov 17, 2014
51eb8da
Suggest a couple of typo fixes in README.md
robbieaverill Nov 25, 2014
0a8932d
Merge pull request #233 from robbieaverill/robbieaverill/readme-typo-…
IvanChepurnyi Feb 6, 2015
1e7a0d4
Disable Events without Disabling Event Capture
Mar 6, 2015
9742b6a
Merge pull request #241 from kojiromike/observe-and-report
IvanChepurnyi Mar 24, 2015
8674636
Merge pull request #184 from AOEmedia/issue/178-fixture_scope
IvanChepurnyi Mar 24, 2015
6d0b007
Update travis environment and PHP versions
hakre Mar 31, 2015
68bfe5b
Merge pull request #249 from hakre/hakre/magento-latest
IvanChepurnyi Mar 31, 2015
e0b3595
Fix error reporting for issues happining during setup process, lift p…
IvanChepurnyi Aug 12, 2015
8276c46
Fix constraint type for assertLayoutBlockRenderedContent[Not]()
schmengler Jul 12, 2016
0f6bdb0
Merge pull request #271 from schmengler/bugfix/block-content-constraint
IvanChepurnyi Jul 12, 2016
ac76e59
Integrate PHP 7 compatibility patch from Inchoo_PHP7 into EcomDev_PHP…
schmengler Aug 29, 2016
7e015df
Update Spyc YAML lib to 0.5.1 for PHP 7.1 compatibility
schmengler Jan 24, 2017
a0531ac
Reset _beforeForwardInfo to make multiple forward assertions possible
schmengler Apr 26, 2017
7ecc527
Merge pull request #282 from schmengler/bugfix/forward-info
IvanChepurnyi May 4, 2017
59b5c17
Fix default value for 'attribute_set_id'.
colinmollenhour May 9, 2017
df54041
Avoid PHP notice about empty array.
colinmollenhour May 10, 2017
35c08fb
Merge pull request #283 from colinmollenhour/dev
IvanChepurnyi May 11, 2017
a8116f2
Merge pull request #276 from schmengler/bugfix/php7compat
schmengler Dec 17, 2018
bd99f65
Merge branch 'master' into dev
IvanChepurnyi Nov 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ language: php
php:
- 5.3
- 5.4
- 5.5
env:
- MAGE=1.9.1.0
- MAGE=1.9.0.1
- MAGE=1.8.1.0
- MAGE=1.7.0.2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Magento PHPUnit Integration

Magento is a quite complex platform without built in unit test suite, so the code is not oriented on running tests over it.

This extension was created especially for resolving this problem and promoting test driven development practices in Magento developers community. It doesn't change core files or brake your Magento instalment database, because all the system objects are replaced during the run-time with the test ones and a separate database connection is used for tests.
This extension was created especially for resolving this problem and promoting test driven development practices in Magento developers community. It doesn't change core files or break your Magento installation database. All system objects are replaced during run-time with the test objects, and a separate database connection is used for tests.

System Requirements
-------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public function resetInternalProperties()
// From Http request
$this->_paramSources = array('_GET', '_POST');
$this->_requestUri = null;
$this->_params = array();
$this->_baseUrl = null;
$this->_basePath = null;
$this->_pathInfo = '';
Expand All @@ -174,6 +175,7 @@ public function resetInternalProperties()
$this->_route = null;
$this->_directFrontNames = null;
$this->_controllerModule = null;
$this->_beforeForwardInfo = null;
return $this;
}

Expand Down
88 changes: 42 additions & 46 deletions app/code/community/EcomDev/PHPUnit/Model/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,11 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
const XML_PATH_CONTROLLER_RESPONSE = 'phpunit/suite/controller/response/class';

/**
* Old configuration model to be returned back
* after unit tests are finished
*
* @var Mage_Core_Model_Config
*/
protected static $_oldConfig = null;

/**
* Old application model to be returned back
* after unit tests are finished
*
* @var Mage_Core_Model_App
*/
protected static $_oldApplication = null;

/**
* Old event collection to be returned back
* after the unit tests are finished
*
* @var Varien_Event_Collection
*/
protected static $_oldEventCollection = null;

/**
* List of singletons in original application
* Test scope data to be returned back after unit tests are finished
*
* @var array
*/
protected static $_oldRegistry = null;
protected static $_testScopeStack = array();

/**
* Configuration model class name for unit tests
Expand Down Expand Up @@ -143,10 +119,12 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
public static function applyTestScope()
{
// Save old environment variables
self::$_oldApplication = EcomDev_Utils_Reflection::getRestrictedPropertyValue('Mage', '_app');
self::$_oldConfig = EcomDev_Utils_Reflection::getRestrictedPropertyValue('Mage', '_config');
self::$_oldEventCollection = EcomDev_Utils_Reflection::getRestrictedPropertyValue('Mage', '_events');
self::$_oldRegistry = EcomDev_Utils_Reflection::getRestrictedPropertyValue('Mage', '_registry');
self::$_testScopeStack[] = array(
'app' => EcomDev_Utils_Reflection::getRestrictedPropertyValue('Mage', '_app'),
'config' => EcomDev_Utils_Reflection::getRestrictedPropertyValue('Mage', '_config'),
'events' => EcomDev_Utils_Reflection::getRestrictedPropertyValue('Mage', '_events'),
'registry' => EcomDev_Utils_Reflection::getRestrictedPropertyValue('Mage', '_registry'),
);


// Setting environment variables for unit tests
Expand All @@ -156,7 +134,20 @@ public static function applyTestScope()
EcomDev_Utils_Reflection::setRestrictedPropertyValue('Mage', '_registry', array());

// All unit tests will be run in admin scope, to get rid of frontend restrictions
Mage::app()->initTest();
// Init modules runs install process for table structures,
// It is required for setting up proper setup script
try {
set_error_handler(function ($errorCode, $errorMessage) {
echo $errorMessage, $errorCode;
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
exit;
});
Mage::app()->initTest();
restore_error_handler();
} catch (Exception $e) {
echo $e->getMessage(), "\n", $e->getTraceAsString();
exit;
}
}

/**
Expand Down Expand Up @@ -225,10 +216,10 @@ public function initTest()
$this->replaceRegistry(self::REGISTRY_PATH_SHARED_STORAGE, new Varien_Object());
return $this;
}

/**
* Sets cache options for test case
*
*
* @param array $options
* @return EcomDev_PHPUnit_Model_App
*/
Expand All @@ -243,7 +234,7 @@ public function setCacheOptions(array $options)

/**
* Retrieve cache options for test case
*
*
* @return array
*/
public function getCacheOptions()
Expand Down Expand Up @@ -358,7 +349,7 @@ public function removeEventArea($code)

/**
* Returns request for test suite
*
*
* @see Mage_Core_Model_App::getRequest()
* @return EcomDev_PHPUnit_Controller_Request_Http
*/
Expand All @@ -376,7 +367,7 @@ public function getRequest()

/**
* Returns response for test suite
*
*
* @see Mage_Core_Model_App::getResponse()
* @return EcomDev_PHPUnit_Controller_Response_Http
*/
Expand Down Expand Up @@ -405,7 +396,6 @@ public function getResponse()
protected function _getClassNameFromConfig($configPath, $interface = null)
{
$className = (string)$this->getConfig()->getNode($configPath);

$reflection = EcomDev_Utils_Reflection::getReflection($className);
if ($interface !== null && !$reflection->implementsInterface($interface)) {
throw new RuntimeException(
Expand Down Expand Up @@ -434,11 +424,17 @@ protected function _initStores()
*/
public static function discardTestScope()
{
if(empty(self::$_testScopeStack)) {
throw new RuntimeException('No test scope to discard');
}

$previousScope = array_pop(self::$_testScopeStack);

// Setting environment variables for unit tests
EcomDev_Utils_Reflection::setRestrictedPropertyValue('Mage', '_app', self::$_oldApplication);
EcomDev_Utils_Reflection::setRestrictedPropertyValue('Mage', '_config', self::$_oldConfig);
EcomDev_Utils_Reflection::setRestrictedPropertyValue('Mage', '_events', self::$_oldEventCollection);
EcomDev_Utils_Reflection::setRestrictedPropertyValue('Mage', '_registry', self::$_oldRegistry);
EcomDev_Utils_Reflection::setRestrictedPropertyValue('Mage', '_app', $previousScope['app']);
EcomDev_Utils_Reflection::setRestrictedPropertyValue('Mage', '_config', $previousScope['config']);
EcomDev_Utils_Reflection::setRestrictedPropertyValue('Mage', '_events', $previousScope['events']);
EcomDev_Utils_Reflection::setRestrictedPropertyValue('Mage', '_registry', $previousScope['registry']);
}

/**
Expand Down Expand Up @@ -527,14 +523,14 @@ public function dispatchEvent($eventName, $args)
{
if ($this->_eventsEnabled) {
parent::dispatchEvent($eventName, $args);
}

if (!isset($this->_dispatchedEvents[$eventName])) {
$this->_dispatchedEvents[$eventName] = 0;
}

$this->_dispatchedEvents[$eventName]++;
if (!isset($this->_dispatchedEvents[$eventName])) {
$this->_dispatchedEvents[$eventName] = 0;
}

$this->_dispatchedEvents[$eventName]++;

return $this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterfac
$this->getResource()->cleanTable($tableEntity);
}
foreach (array_keys($data) as $tableEntity) {
if (isset($restoreTableData[$tableEntity])) {
if ( ! empty($restoreTableData[$tableEntity])) {
$this->getResource()->loadTableData($tableEntity, $restoreTableData[$tableEntity]);
}
}
Expand Down
11 changes: 10 additions & 1 deletion app/code/community/EcomDev/PHPUnit/Model/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,15 @@ public function isLoaded()
public function getOutput()
{
$this->record(self::ACTION_RENDER, 'layout');
return parent::getOutput();

// parent::getOutput() with Inchoo_PHP7 fix:
$out = '';
if (!empty($this->_output)) {
foreach ($this->_output as $callback) {
$out .= $this->getBlock($callback[0])->{$callback[1]}();
}
}

return $out;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public function loadEntity($entityType, $values)
$defaultAttributeSet = 0;
}

$values[$index]['attribute_set_id'] = $defaultAttributeSet;
$row['attribute_set_id'] = $defaultAttributeSet;
}

// Preparing entity table record
Expand Down
4 changes: 2 additions & 2 deletions app/code/community/EcomDev/PHPUnit/Test/Case/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ public static function assertLayoutBlockRenderedContent($blockName,
self::assertThatLayout(
self::layoutBlock(
$blockName,
EcomDev_PHPUnit_Constraint_Layout_Block::TYPE_RENDERED,
EcomDev_PHPUnit_Constraint_Layout_Block::TYPE_RENDERED_CONTENT,
$constraint
),
$message
Expand All @@ -1180,7 +1180,7 @@ public static function assertLayoutBlockRenderedContentNot($blockName,
self::assertThatLayout(
self::layoutBlock(
$blockName,
EcomDev_PHPUnit_Constraint_Layout_Block::TYPE_RENDERED,
EcomDev_PHPUnit_Constraint_Layout_Block::TYPE_RENDERED_CONTENT,
self::logicalNot($constraint)
),
$message
Expand Down
Loading