Skip to content

Commit 75d0d59

Browse files
committed
Use PHPUnit ini_set wrapper in tests
PHPUnit ini_set wrapper is now used in tests to automatically reset ini settings after the test is run. This avoids possible side effects and test skipping. Native ini_set is still used in DefaultCsrfProviderTest, but its tests are run in isolation.
1 parent 99ff8a6 commit 75d0d59

File tree

5 files changed

+12
-23
lines changed

5 files changed

+12
-23
lines changed

src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,14 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
2626
*/
2727
protected $errorReporting;
2828

29-
/**
30-
* @var string Display errors setting before running tests.
31-
*/
32-
protected $displayErrors;
33-
3429
public function setUp()
3530
{
3631
$this->errorReporting = error_reporting(E_ALL | E_STRICT);
37-
$this->displayErrors = ini_get('display_errors');
38-
ini_set('display_errors', '1');
32+
$this->iniSet('display_errors', '1');
3933
}
4034

4135
public function tearDown()
4236
{
43-
ini_set('display_errors', $this->displayErrors);
4437
error_reporting($this->errorReporting);
4538
}
4639

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase
3535

3636
protected function setUp()
3737
{
38-
ini_set('session.save_handler', 'files');
39-
ini_set('session.save_path', $this->savePath = sys_get_temp_dir().'/sf2test');
38+
$this->iniSet('session.save_handler', 'files');
39+
$this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sf2test');
4040
if (!is_dir($this->savePath)) {
4141
mkdir($this->savePath);
4242
}
@@ -121,15 +121,15 @@ public function testRegenerateDestroy()
121121

122122
public function testDefaultSessionCacheLimiter()
123123
{
124-
ini_set('session.cache_limiter', 'nocache');
124+
$this->iniSet('session.cache_limiter', 'nocache');
125125

126126
$storage = new NativeSessionStorage();
127127
$this->assertEquals('', ini_get('session.cache_limiter'));
128128
}
129129

130130
public function testExplicitSessionCacheLimiter()
131131
{
132-
ini_set('session.cache_limiter', 'nocache');
132+
$this->iniSet('session.cache_limiter', 'nocache');
133133

134134
$storage = new NativeSessionStorage(array('cache_limiter' => 'public'));
135135
$this->assertEquals('public', ini_get('session.cache_limiter'));
@@ -171,7 +171,7 @@ public function testSetSaveHandler53()
171171
$this->markTestSkipped('Test skipped, for PHP 5.3 only.');
172172
}
173173

174-
ini_set('session.save_handler', 'files');
174+
$this->iniSet('session.save_handler', 'files');
175175
$storage = $this->getStorage();
176176
$storage->setSaveHandler();
177177
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy', $storage->getSaveHandler());
@@ -193,7 +193,7 @@ public function testSetSaveHandler54()
193193
$this->markTestSkipped('Test skipped, for PHP 5.4 only.');
194194
}
195195

196-
ini_set('session.save_handler', 'files');
196+
$this->iniSet('session.save_handler', 'files');
197197
$storage = $this->getStorage();
198198
$storage->setSaveHandler();
199199
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/PhpBridgeSessionStorageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class PhpBridgeSessionStorageTest extends \PHPUnit_Framework_TestCase
3030

3131
protected function setUp()
3232
{
33-
ini_set('session.save_handler', 'files');
34-
ini_set('session.save_path', $this->savePath = sys_get_temp_dir().'/sf2test');
33+
$this->iniSet('session.save_handler', 'files');
34+
$this->iniSet('session.save_path', $this->savePath = sys_get_temp_dir().'/sf2test');
3535
if (!is_dir($this->savePath)) {
3636
mkdir($this->savePath);
3737
}

src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ public function testConstruct()
5656
*/
5757
public function testHandleWithoutLogger($event, $event2)
5858
{
59-
// store the current error_log, and disable it temporarily
60-
$errorLog = ini_set('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');
59+
$this->iniSet('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');
6160

6261
$l = new ExceptionListener('foo');
6362
$l->onKernelException($event);
@@ -69,9 +68,6 @@ public function testHandleWithoutLogger($event, $event2)
6968
} catch (\Exception $e) {
7069
$this->assertSame('foo', $e->getMessage());
7170
}
72-
73-
// restore the old error_log
74-
ini_set('error_log', $errorLog);
7571
}
7672

7773
/**

src/Symfony/Component/Process/Tests/ExecutableFinderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function testFindWithOpenBaseDir()
102102
$this->markTestSkipped('Cannot test when open_basedir is set');
103103
}
104104

105-
ini_set('open_basedir', dirname(PHP_BINARY).PATH_SEPARATOR.'/');
105+
$this->iniSet('open_basedir', dirname(PHP_BINARY).PATH_SEPARATOR.'/');
106106

107107
$finder = new ExecutableFinder();
108108
$result = $finder->find($this->getPhpBinaryName());
@@ -125,7 +125,7 @@ public function testFindProcessInOpenBasedir()
125125
}
126126

127127
$this->setPath('');
128-
ini_set('open_basedir', PHP_BINARY.PATH_SEPARATOR.'/');
128+
$this->iniSet('open_basedir', PHP_BINARY.PATH_SEPARATOR.'/');
129129

130130
$finder = new ExecutableFinder();
131131
$result = $finder->find($this->getPhpBinaryName(), false);

0 commit comments

Comments
 (0)