From 21f620f8c9c83033c9413f38de5b3e174657436b Mon Sep 17 00:00:00 2001 From: Jeff Welch Date: Fri, 25 Jan 2013 03:14:14 -0500 Subject: [PATCH] Fixes #789 * Maintain INI values during process isolation. --- .../Framework/Process/TestCaseMethod.tpl.dist | 1 + PHPUnit/Framework/TestCase.php | 3 +++ PHPUnit/Util/GlobalState.php | 16 ++++++++++++ Tests/TextUI/ini-isolation.phpt | 25 +++++++++++++++++++ Tests/_files/IniTest.php | 8 ++++++ 5 files changed, 53 insertions(+) create mode 100644 Tests/TextUI/ini-isolation.phpt create mode 100644 Tests/_files/IniTest.php diff --git a/PHPUnit/Framework/Process/TestCaseMethod.tpl.dist b/PHPUnit/Framework/Process/TestCaseMethod.tpl.dist index 4bad7fa612f..6dfd0e17525 100644 --- a/PHPUnit/Framework/Process/TestCaseMethod.tpl.dist +++ b/PHPUnit/Framework/Process/TestCaseMethod.tpl.dist @@ -1,4 +1,5 @@ getCollectCodeCoverageInformation()) { @@ -763,6 +765,7 @@ public function run(PHPUnit_Framework_TestResult $result = NULL) 'globals' => $globals, 'include_path' => $includePath, 'included_files' => $includedFiles, + 'iniSettings' => $iniSettings, 'strict' => $strict ) ); diff --git a/PHPUnit/Util/GlobalState.php b/PHPUnit/Util/GlobalState.php index 2737985ad07..3215043f81d 100644 --- a/PHPUnit/Util/GlobalState.php +++ b/PHPUnit/Util/GlobalState.php @@ -213,6 +213,22 @@ public static function getIncludedFilesAsString() return $result; } + public static function getIniSettingsAsString() + { + $result = ''; + $iniSettings = ini_get_all(null, FALSE); + + foreach ($iniSettings as $key => $value) { + $result .= sprintf( + 'ini_set(%s, %s);' . "\n", + self::exportVariable($key), + self::exportVariable($value) + ); + } + + return $result; + } + public static function getConstantsAsString() { $constants = get_defined_constants(TRUE); diff --git a/Tests/TextUI/ini-isolation.phpt b/Tests/TextUI/ini-isolation.phpt new file mode 100644 index 00000000000..c6adbbc704f --- /dev/null +++ b/Tests/TextUI/ini-isolation.phpt @@ -0,0 +1,25 @@ +--TEST-- +phpunit --process-isolation -d default_mimetype=application/x-test IniTest ../_files/IniTest.php +--FILE-- + +--EXPECTF-- +PHPUnit %s by Sebastian Bergmann. + +. + +Time: %i %s, Memory: %sMb + +OK (1 test, 1 assertion) + diff --git a/Tests/_files/IniTest.php b/Tests/_files/IniTest.php new file mode 100644 index 00000000000..5846abf55e6 --- /dev/null +++ b/Tests/_files/IniTest.php @@ -0,0 +1,8 @@ +assertEquals('application/x-test', ini_get('default_mimetype')); + } +}