Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit e9c0a57

Browse files
committed
Merge branch 'hotfix/7'
Close #7
2 parents d1d291c + 15ecd0e commit e9c0a57

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5-
## 2.5.3 - TBD
5+
## 2.5.3 - 2016-03-01
66

77
### Added
88

@@ -21,6 +21,9 @@ All notable changes to this project will be documented in this file, in reverse
2121
- [#6](https://github.com/zendframework/zend-test/pull/6) updates the
2222
`AbstractControllerTestCase` to mark a test as failed if no route match occurs
2323
in a number of assertions that require a route match.
24+
- [#7](https://github.com/zendframework/zend-test/pull/7) modifies the `reset()`
25+
method of the `AbstractControllerTestCase` to prevent rewriting the
26+
`$_SESSION` superglobal if it has not previously been enabled.
2427

2528
## 2.5.2 - 2015-12-09
2629

src/PHPUnit/Controller/AbstractControllerTestCase.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,14 @@ public function reset($keepPersistence = false)
292292
// force to re-create all components
293293
$this->application = null;
294294

295-
// reset server datas
295+
// reset server data
296296
if (!$keepPersistence) {
297-
$_SESSION = [];
297+
// Do not create a global session variable if it doesn't already
298+
// exist. Otherwise calling this function could mark tests risky,
299+
// as it changes global state.
300+
if (array_key_exists('_SESSION', $GLOBALS)) {
301+
$_SESSION = [];
302+
}
298303
$_COOKIE = [];
299304
}
300305

@@ -697,8 +702,8 @@ public function assertNoMatchedRoute()
697702
$match = $routeMatch->getMatchedRouteName();
698703
$match = strtolower($match);
699704
throw new PHPUnit_Framework_ExpectationFailedException(sprintf(
700-
'Failed asserting that no route matched, actual matched route name is "%s"',
701-
$match
705+
'Failed asserting that no route matched, actual matched route name is "%s"',
706+
$match
702707
));
703708
}
704709
$this->assertNull($routeMatch);

test/PHPUnit/Controller/AbstractControllerTestCaseTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -418,4 +418,15 @@ public function testCustomResponseObject()
418418
$this->dispatch('/custom-response');
419419
$this->assertResponseStatusCode(999);
420420
}
421+
422+
public function testResetDoesNotCreateSessionIfNoSessionExists()
423+
{
424+
if (! extension_loaded('session')) {
425+
$this->markTestSkipped('No session extension loaded');
426+
}
427+
428+
$this->reset();
429+
430+
$this->assertFalse(array_key_exists('_SESSION', $GLOBALS));
431+
}
421432
}

test/PHPUnit/Controller/AbstractHttpControllerTestCaseTest.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ public function testAssertWithMultiDispatch()
549549

550550
public function testAssertWithMultiDispatchWithoutPersistence()
551551
{
552+
if (! extension_loaded('session')) {
553+
$this->markTestSkipped('No session extension loaded');
554+
}
555+
552556
$this->dispatch('/tests-persistence');
553557

554558
$controller = $this->getApplicationServiceLocator()
@@ -573,6 +577,10 @@ public function testAssertWithMultiDispatchWithoutPersistence()
573577

574578
public function testAssertWithMultiDispatchWithPersistence()
575579
{
580+
if (! extension_loaded('session')) {
581+
$this->markTestSkipped('No session extension loaded');
582+
}
583+
576584
$this->dispatch('/tests-persistence');
577585

578586
$controller = $this->getApplicationServiceLocator()
@@ -607,14 +615,18 @@ public function testAssertWithEventShared()
607615

608616
$this->assertEquals(true, StaticEventManager::hasInstance());
609617
$countListeners = count(StaticEventManager::getInstance()->getListeners(
610-
'Zend\Mvc\Application', MvcEvent::EVENT_FINISH));
618+
'Zend\Mvc\Application',
619+
MvcEvent::EVENT_FINISH
620+
));
611621
$this->assertEquals(1, $countListeners);
612622

613623
$this->reset();
614624

615625
$this->assertEquals(false, StaticEventManager::hasInstance());
616626
$countListeners = StaticEventManager::getInstance()->getListeners(
617-
'Zend\Mvc\Application', MvcEvent::EVENT_FINISH);
627+
'Zend\Mvc\Application',
628+
MvcEvent::EVENT_FINISH
629+
);
618630
$this->assertEquals(false, $countListeners);
619631

620632
$this->dispatch('/tests-bis');

0 commit comments

Comments
 (0)