From 3b396fb99461f6cabd8a034093d44f6793065444 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 20 Aug 2010 08:31:07 -0400 Subject: [PATCH 1/2] Added preserveGlobalState hack for session tests - Overrode run() in test cases to disable preservation of global state, per http://matthewturland.com/2010/08/19/process-isolation-in-phpunit/ - Fixed issue in StandardConfiguration (incorrectly referenced classname) - TODO: because global state is destroyed, autoloader disappears --- src/Configuration/StandardConfiguration.php | 2 +- test/ContainerTest.php | 13 +++++++++++++ test/SessionManagerTest.php | 13 +++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Configuration/StandardConfiguration.php b/src/Configuration/StandardConfiguration.php index 3ecc80a5..fe8ab9e0 100644 --- a/src/Configuration/StandardConfiguration.php +++ b/src/Configuration/StandardConfiguration.php @@ -26,7 +26,7 @@ use Zend\Session\Configuration as Configurable, Zend\Session\Exception as SessionException, - Zend\Validator\Hostname\Hostname as HostnameValidator, + Zend\Validator\Hostname as HostnameValidator, Zend\Filter\Word\CamelCaseToUnderscore as CamelCaseToUnderscoreFilter; /** diff --git a/test/ContainerTest.php b/test/ContainerTest.php index f7733db1..f8b3ea67 100644 --- a/test/ContainerTest.php +++ b/test/ContainerTest.php @@ -25,6 +25,19 @@ public function tearDown() Container::setDefaultManager(null); } + /** + * Hack to allow running tests in separate processes + * + * @see http://matthewturland.com/2010/08/19/process-isolation-in-phpunit/ + * @param PHPUnit_Framework_TestResult $result + * @return void + */ + public function run(\PHPUnit_Framework_TestResult $result = NULL) + { + $this->setPreserveGlobalState(false); + return parent::run($result); + } + public function testInstantiationStartsSession() { $this->manager->destroy(); diff --git a/test/SessionManagerTest.php b/test/SessionManagerTest.php index cab39114..4ffe2d35 100644 --- a/test/SessionManagerTest.php +++ b/test/SessionManagerTest.php @@ -19,6 +19,19 @@ public function setUp() Registry::_unsetInstance(); } + /** + * Hack to allow running tests in separate processes + * + * @see http://matthewturland.com/2010/08/19/process-isolation-in-phpunit/ + * @param PHPUnit_Framework_TestResult $result + * @return void + */ + public function run(\PHPUnit_Framework_TestResult $result = NULL) + { + $this->setPreserveGlobalState(false); + return parent::run($result); + } + public function handleErrors($errno, $errstr) { $this->error = $errstr; From f23a91367f53cf4e90177cd71cfd303f9a344ea9 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 20 Aug 2010 09:38:32 -0400 Subject: [PATCH 2/2] Fixes for Session tests - Moved test autoload setup to tests/_autoload.php - Modified Session\ContainerTest and Session\SessionManagerTest to include _autoload.php if no autoloader is detected (happens when global state is destroyed). --- test/ContainerTest.php | 9 +++++++++ test/SessionManagerTest.php | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/test/ContainerTest.php b/test/ContainerTest.php index f8b3ea67..b5c60571 100644 --- a/test/ContainerTest.php +++ b/test/ContainerTest.php @@ -10,6 +10,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { public function setUp() { + $this->forceAutoloader(); $_SESSION = array(); Container::setDefaultManager(null); $this->manager = $manager = new TestAsset\TestManager(array( @@ -25,6 +26,14 @@ public function tearDown() Container::setDefaultManager(null); } + protected function forceAutoloader() + { + $splAutoloadFunctions = spl_autoload_functions(); + if (!$splAutoloadFunctions || !in_array('ZendTest_Autoloader', $splAutoloadFunctions)) { + include __DIR__ . '/../../_autoload.php'; + } + } + /** * Hack to allow running tests in separate processes * diff --git a/test/SessionManagerTest.php b/test/SessionManagerTest.php index 4ffe2d35..2e586954 100644 --- a/test/SessionManagerTest.php +++ b/test/SessionManagerTest.php @@ -14,11 +14,20 @@ class SessionManagerTest extends \PHPUnit_Framework_TestCase public function setUp() { + $this->forceAutoloader(); $this->error = false; $this->manager = new SessionManager(); Registry::_unsetInstance(); } + protected function forceAutoloader() + { + $splAutoloadFunctions = spl_autoload_functions(); + if (!$splAutoloadFunctions || !in_array('ZendTest_Autoloader', $splAutoloadFunctions)) { + include __DIR__ . '/../../_autoload.php'; + } + } + /** * Hack to allow running tests in separate processes *