Skip to content

Loading…

Zend\Test Fix persistence with multi dispatch #5730

Closed
wants to merge 1 commit into from

2 participants

@blanchonvincent

When I write my functional tests, sometimes I need to assert error/validation messages created by flash messenger. So, sometimes I need to preserve my session for the tests.

@weierophinney
Zend Framework member

Scheduling for 2.3.0, as it adds new functionality.

@weierophinney weierophinney added this to the 2.3.0 milestone
@weierophinney weierophinney added a commit that referenced this pull request
@weierophinney weierophinney [#5730] CS fixes
- Trailing whitespace
6ecc9d0
@weierophinney weierophinney self-assigned this
@weierophinney
Zend Framework member

Merged to develop for release with 2.3.0.

@weierophinney weierophinney added a commit to zendframework/zend-test that referenced this pull request
@weierophinney weierophinney Merge pull request zendframework/zf2#5730 from blanchonvincent/hotfix…
…/zend-test-reset-persistence

Zend\Test Fix persistence with multi dispatch
a45b56d
@weierophinney weierophinney added a commit to zendframework/zend-test that referenced this pull request
@weierophinney weierophinney [zendframework/zf2#5730] CS fixes
- Trailing whitespace
9541bf3
@weierophinney weierophinney added a commit to zendframework/zend-test that referenced this pull request
@weierophinney weierophinney Merge branch 'feature/5730' into develop df3ea4b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 20, 2014
  1. @blanchonvincent
View
9 library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php
@@ -281,16 +281,19 @@ public function dispatch($url, $method = null, $params = array())
*
* @return AbstractControllerTestCase
*/
- public function reset()
+ public function reset($keepPersistence = false)
{
// force to re-create all components
$this->application = null;
// reset server datas
- $_SESSION = array();
+ if (!$keepPersistence) {
+ $_SESSION = array();
+ $_COOKIE = array();
+ }
+
$_GET = array();
$_POST = array();
- $_COOKIE = array();
// reset singleton
StaticEventManager::resetInstance();
View
1 tests/ZendTest/Test/PHPUnit/Controller/AbstractControllerTestCaseTest.php
@@ -34,6 +34,7 @@ public static function rmdir($dir)
foreach ($files as $file) {
(is_dir("$dir/$file")) ? static::rmdir("$dir/$file") : unlink("$dir/$file");
}
+
return rmdir($dir);
}
View
50 tests/ZendTest/Test/PHPUnit/Controller/AbstractHttpControllerTestCaseTest.php
@@ -489,7 +489,7 @@ public function testAssertQueryWithDynamicPutParamsInDispatchMethod()
$this->assertEquals($request->getMethod(), 'PUT');
$this->assertEquals('num_post=5&foo=bar', $request->getContent());
}
- /*
+
public function testAssertUriWithHostname()
{
$this->dispatch('http://my.domain.tld:443');
@@ -523,6 +523,54 @@ public function testAssertWithMultiDispatch()
$this->assertXpathQueryCount('//div[@class="post"]', 0);
}
+ public function testAssertWithMultiDispatchWithoutPersistence()
+ {
+ $this->dispatch('/tests-persistence');
+
+ $controller = $this->getApplicationServiceLocator()
+ ->get('ControllerLoader')
+ ->get('baz_index');
+ $flashMessenger = $controller->flashMessenger();
+ $messages = $flashMessenger->getMessages();
+ $this->assertCount(0, $messages);
+
+ $this->reset(false);
+
+ $this->dispatch('/tests');
+
+ $controller = $this->getApplicationServiceLocator()
+ ->get('ControllerLoader')
+ ->get('baz_index');
+ $flashMessenger = $controller->flashMessenger();
+ $messages = $flashMessenger->getMessages();
+
+ $this->assertCount(0, $messages);
+ }
+
+ public function testAssertWithMultiDispatchWithPersistence()
+ {
+ $this->dispatch('/tests-persistence');
+
+ $controller = $this->getApplicationServiceLocator()
+ ->get('ControllerLoader')
+ ->get('baz_index');
+ $flashMessenger = $controller->flashMessenger();
+ $messages = $flashMessenger->getMessages();
+ $this->assertCount(0, $messages);
+
+ $this->reset(true);
+
+ $this->dispatch('/tests');
+
+ $controller = $this->getApplicationServiceLocator()
+ ->get('ControllerLoader')
+ ->get('baz_index');
+ $flashMessenger = $controller->flashMessenger();
+ $messages = $flashMessenger->getMessages();
+
+ $this->assertCount(1, $messages);
+ }
+
public function testAssertWithEventShared()
{
$this->setApplicationConfig(
View
1 tests/ZendTest/Test/PHPUnit/Util/ModuleLoaderTest.php
@@ -27,6 +27,7 @@ public static function rmdir($dir)
foreach ($files as $file) {
(is_dir("$dir/$file")) ? static::rmdir("$dir/$file") : unlink("$dir/$file");
}
+
return rmdir($dir);
}
View
10 tests/ZendTest/Test/_files/Baz/config/module.config.php
@@ -48,6 +48,16 @@
),
),
),
+ 'persistence' => array(
+ 'type' => 'literal',
+ 'options' => array(
+ 'route' => '/tests-persistence',
+ 'defaults' => array(
+ 'controller' => 'baz_index',
+ 'action' => 'persistencetest',
+ ),
+ ),
+ ),
'exception' => array(
'type' => 'literal',
'options' => array(
View
5 tests/ZendTest/Test/_files/Baz/src/Baz/Controller/IndexController.php
@@ -28,6 +28,11 @@ public function consoleAction()
return 'foo, bar';
}
+ public function persistencetestAction()
+ {
+ $this->flashMessenger()->addMessage('test');
+ }
+
public function redirectAction()
{
return $this->redirect()->toUrl('http://www.zend.com');
View
0 tests/ZendTest/Test/_files/Baz/view/baz/index/persistencetest.phtml
No changes.
View
1 tests/ZendTest/Test/_files/modules-path/with-subdir/Bar/Module.php
@@ -34,6 +34,7 @@ public function getServiceConfig()
'BarObject' => function ($sm) {
$foo = $sm->get('FooObject');
$foo->bar = 'baz';
+
return $foo;
}
),
Something went wrong with that request. Please try again.