/** * Filters stack frames from PHPUnit classes. * * @param Exception $e * @param boolean $asString * @return string */ public static function getFilteredStacktrace(Exception $e, $asString = TRUE) { if (!defined('PHPUNIT_TESTSUITE')) { $blacklist = PHPUnit_Util_GlobalState::phpunitFiles(); } else { $blacklist = array(); } if ($asString === TRUE) { $filteredStacktrace = ''; } else { $filteredStacktrace = array(); } if ($e instanceof PHPUnit_Framework_SyntheticError) { $eTrace = $e->getSyntheticTrace(); $eFile = $e->getSyntheticFile(); $eLine = $e->getSyntheticLine(); } else { $eTrace = $e->getTrace(); $eFile = $e->getFile(); $eLine = $e->getLine(); } if (!self::frameExists($eTrace, $eFile, $eLine)) { array_unshift($eTrace, array('file' => $eFile, 'line' => $eLine)); } foreach ($eTrace as $frame) { if (isset($frame['file']) && is_file($frame['file']) && !isset($blacklist[$frame['file']])) { if ($asString === TRUE) { $filteredStacktrace .= sprintf("%s:%s\n", $frame['file'], isset($frame['line']) ? $frame['line'] : '?'); } else { $filteredStacktrace[] = $frame; } } } return $filteredStacktrace; }
/** * Filters stack frames from PHPUnit classes. * * @param Exception $e * @param boolean $asString * @return string */ public static function getFilteredStacktrace(Exception $e, $asString = TRUE) { $prefix = FALSE; $script = realpath($GLOBALS['_SERVER']['SCRIPT_NAME']); if (defined('__PHPUNIT_PHAR__')) { $prefix = 'phar://' . __PHPUNIT_PHAR__ . '/'; } if (!defined('PHPUNIT_TESTSUITE')) { $blacklist = PHPUnit_Util_GlobalState::phpunitFiles(); } else { $blacklist = array(); } if ($asString === TRUE) { $filteredStacktrace = ''; } else { $filteredStacktrace = array(); } if ($e instanceof PHPUnit_Framework_SyntheticError) { $eTrace = $e->getSyntheticTrace(); $eFile = $e->getSyntheticFile(); $eLine = $e->getSyntheticLine(); } else { if ($e->getPrevious()) { $eTrace = $e->getPrevious()->getTrace(); } else { $eTrace = $e->getTrace(); } $eFile = $e->getFile(); $eLine = $e->getLine(); } if (!self::frameExists($eTrace, $eFile, $eLine)) { array_unshift($eTrace, array('file' => $eFile, 'line' => $eLine)); } foreach ($eTrace as $frame) { if (isset($frame['file']) && is_file($frame['file']) && !isset($blacklist[$frame['file']]) && ($prefix === FALSE || strpos($frame['file'], $prefix) !== 0) && $frame['file'] !== $script) { if ($asString === TRUE) { $filteredStacktrace .= sprintf("%s:%s\n", $frame['file'], isset($frame['line']) ? $frame['line'] : '?'); } else { $filteredStacktrace[] = $frame; } } } return $filteredStacktrace; }
/** * Runs the test case and collects the results in a TestResult object. * If no TestResult object is passed a new one will be created. * * @param PHPUnit_Framework_TestResult $result * @return PHPUnit_Framework_TestResult * @throws PHPUnit_Framework_Exception */ public function run(PHPUnit_Framework_TestResult $result = null) { if ($result === null) { $result = $this->createResult(); } if (!$this instanceof PHPUnit_Framework_Warning) { $this->setTestResultObject($result); $this->setUseErrorHandlerFromAnnotation(); } if ($this->useErrorHandler !== null) { $oldErrorHandlerSetting = $result->getConvertErrorsToExceptions(); $result->convertErrorsToExceptions($this->useErrorHandler); } if (!$this instanceof PHPUnit_Framework_Warning && !$this->handleDependencies()) { return; } if ($this->runTestInSeparateProcess === true && $this->inIsolation !== true && !$this instanceof PHPUnit_Extensions_SeleniumTestCase && !$this instanceof PHPUnit_Extensions_PhptTestCase) { $class = new ReflectionClass($this); $template = new Text_Template(__DIR__ . '/../Util/PHP/Template/TestCaseMethod.tpl'); if ($this->preserveGlobalState) { $constants = PHPUnit_Util_GlobalState::getConstantsAsString(); $globals = PHPUnit_Util_GlobalState::getGlobalsAsString(); $includedFiles = PHPUnit_Util_GlobalState::getIncludedFilesAsString(); $iniSettings = PHPUnit_Util_GlobalState::getIniSettingsAsString(); } else { $constants = ''; if (!empty($GLOBALS['__PHPUNIT_BOOTSTRAP'])) { $globals = '$GLOBALS[\'__PHPUNIT_BOOTSTRAP\'] = ' . var_export($GLOBALS['__PHPUNIT_BOOTSTRAP'], true) . ";\n"; } else { $globals = ''; } $includedFiles = ''; $iniSettings = ''; } $coverage = $result->getCollectCodeCoverageInformation() ? 'true' : 'false'; $isStrictAboutTestsThatDoNotTestAnything = $result->isStrictAboutTestsThatDoNotTestAnything() ? 'true' : 'false'; $isStrictAboutOutputDuringTests = $result->isStrictAboutOutputDuringTests() ? 'true' : 'false'; $isStrictAboutTestSize = $result->isStrictAboutTestSize() ? 'true' : 'false'; $isStrictAboutTodoAnnotatedTests = $result->isStrictAboutTodoAnnotatedTests() ? 'true' : 'false'; if (defined('PHPUNIT_COMPOSER_INSTALL')) { $composerAutoload = var_export(PHPUNIT_COMPOSER_INSTALL, true); } else { $composerAutoload = '\'\''; } if (defined('__PHPUNIT_PHAR__')) { $phar = var_export(__PHPUNIT_PHAR__, true); } else { $phar = '\'\''; } $data = var_export(serialize($this->data), true); $dataName = var_export($this->dataName, true); $dependencyInput = var_export(serialize($this->dependencyInput), true); $includePath = var_export(get_include_path(), true); // must do these fixes because TestCaseMethod.tpl has unserialize('{data}') in it, and we can't break BC // the lines above used to use addcslashes() rather than var_export(), which breaks null byte escape sequences $data = "'." . $data . ".'"; $dataName = "'.(" . $dataName . ").'"; $dependencyInput = "'." . $dependencyInput . ".'"; $includePath = "'." . $includePath . ".'"; $template->setVar(array('composerAutoload' => $composerAutoload, 'phar' => $phar, 'filename' => $class->getFileName(), 'className' => $class->getName(), 'methodName' => $this->name, 'collectCodeCoverageInformation' => $coverage, 'data' => $data, 'dataName' => $dataName, 'dependencyInput' => $dependencyInput, 'constants' => $constants, 'globals' => $globals, 'include_path' => $includePath, 'included_files' => $includedFiles, 'iniSettings' => $iniSettings, 'isStrictAboutTestsThatDoNotTestAnything' => $isStrictAboutTestsThatDoNotTestAnything, 'isStrictAboutOutputDuringTests' => $isStrictAboutOutputDuringTests, 'isStrictAboutTestSize' => $isStrictAboutTestSize, 'isStrictAboutTodoAnnotatedTests' => $isStrictAboutTodoAnnotatedTests)); $this->prepareTemplate($template); $php = PHPUnit_Util_PHP::factory(); $php->runTestJob($template->render(), $this, $result); } else { $result->run($this); } if ($this->useErrorHandler !== null) { $result->convertErrorsToExceptions($oldErrorHandlerSetting); } $this->result = null; return $result; }
/** * @return array * @since Method available since Release 3.6.0 */ public static function phpunitFiles() { if (self::$phpunitFiles === NULL) { self::$phpunitFiles = phpunit_autoload(); if (function_exists('phpunit_mockobject_autoload')) { self::$phpunitFiles = array_merge(self::$phpunitFiles, phpunit_mockobject_autoload()); } if (function_exists('file_iterator_autoload')) { self::$phpunitFiles = array_merge(self::$phpunitFiles, file_iterator_autoload()); } if (function_exists('php_codecoverage_autoload')) { self::$phpunitFiles = array_merge(self::$phpunitFiles, php_codecoverage_autoload()); } if (function_exists('php_timer_autoload')) { self::$phpunitFiles = array_merge(self::$phpunitFiles, php_timer_autoload()); } if (function_exists('php_tokenstream_autoload')) { self::$phpunitFiles = array_merge(self::$phpunitFiles, php_tokenstream_autoload()); } if (function_exists('text_template_autoload')) { self::$phpunitFiles = array_merge(self::$phpunitFiles, text_template_autoload()); } if (function_exists('phpunit_dbunit_autoload')) { self::$phpunitFiles = array_merge(self::$phpunitFiles, phpunit_dbunit_autoload()); } if (function_exists('phpunit_selenium_autoload')) { self::$phpunitFiles = array_merge(self::$phpunitFiles, phpunit_selenium_autoload()); } if (function_exists('phpunit_story_autoload')) { self::$phpunitFiles = array_merge(self::$phpunitFiles, phpunit_story_autoload()); } if (function_exists('php_invoker_autoload')) { self::$phpunitFiles = array_merge(self::$phpunitFiles, php_invoker_autoload()); } foreach (self::$phpunitFiles as $key => $value) { self::$phpunitFiles[$key] = str_replace('/', DIRECTORY_SEPARATOR, $value); } self::$phpunitFiles = array_flip(self::$phpunitFiles); } return self::$phpunitFiles; }
/** * Runs the bare test sequence. */ public function runBare() { $this->numAssertions = 0; // Backup the $GLOBALS array and static attributes. if ($this->runTestInSeparateProcess !== TRUE && $this->inIsolation !== TRUE) { if ($this->backupGlobals === NULL || $this->backupGlobals === TRUE) { PHPUnit_Util_GlobalState::backupGlobals($this->backupGlobalsBlacklist); } if (version_compare(PHP_VERSION, '5.3', '>') && $this->backupStaticAttributes === TRUE) { PHPUnit_Util_GlobalState::backupStaticAttributes($this->backupStaticAttributesBlacklist); } } // Start output buffering. if ($this->useOutputBuffering === TRUE) { ob_start(); } // Clean up stat cache. clearstatcache(); // Run the test. try { // Set up the fixture. if ($this->inIsolation) { $this->setUpBeforeClass(); } $this->setUp(); // Assert pre-conditions. $this->assertPreConditions(); $this->testResult = $this->runTest(); // Assert post-conditions. $this->assertPostConditions(); // Verify Mock Object conditions. foreach ($this->mockObjects as $mockObject) { $this->numAssertions++; $mockObject->__phpunit_verify(); $mockObject->__phpunit_cleanup(); } $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED; } catch (PHPUnit_Framework_IncompleteTest $e) { $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE; $this->statusMessage = $e->getMessage(); } catch (PHPUnit_Framework_SkippedTest $e) { $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED; $this->statusMessage = $e->getMessage(); } catch (PHPUnit_Framework_AssertionFailedError $e) { $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE; $this->statusMessage = $e->getMessage(); } catch (Exception $e) { $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_ERROR; $this->statusMessage = $e->getMessage(); } $this->mockObjects = array(); // Tear down the fixture. An exception raised in tearDown() will be // caught and passed on when no exception was raised before. try { $this->tearDown(); if ($this->inIsolation) { $this->tearDownAfterClass(); } } catch (Exception $_e) { if (!isset($e)) { $e = $_e; } } // Stop output buffering. if ($this->useOutputBuffering === TRUE) { ob_end_clean(); } // Clean up stat cache. clearstatcache(); // Restore the $GLOBALS array and static attributes. if ($this->runTestInSeparateProcess !== TRUE && $this->inIsolation !== TRUE) { if ($this->backupGlobals === NULL || $this->backupGlobals === TRUE) { PHPUnit_Util_GlobalState::restoreGlobals($this->backupGlobalsBlacklist); } if (version_compare(PHP_VERSION, '5.3', '>') && $this->backupStaticAttributes === TRUE) { PHPUnit_Util_GlobalState::restoreStaticAttributes(); } } // Clean up INI settings. foreach ($this->iniSettings as $varName => $oldValue) { ini_set($varName, $oldValue); } $this->iniSettings = array(); // Clean up locale settings. foreach ($this->locale as $category => $locale) { setlocale($category, $locale); } // Workaround for missing "finally". if (isset($e)) { $this->onNotSuccessfulTest($e); } }
/** * @return array * @since Method available since Release 3.6.0 */ public static function phpunitFiles() { if (self::$phpunitFiles === NULL) { self::$phpunitFiles = array_merge(phpunit_autoload(), phpunit_mockobject_autoload(), file_iterator_autoload(), php_codecoverage_autoload(), php_timer_autoload(), php_tokenstream_autoload(), text_template_autoload()); if (function_exists('phpunit_dbunit_autoload')) { self::$phpunitFiles = array_merge(self::$phpunitFiles, phpunit_dbunit_autoload()); } if (function_exists('phpunit_selenium_autoload')) { self::$phpunitFiles = array_merge(self::$phpunitFiles, phpunit_selenium_autoload()); } if (function_exists('phpunit_story_autoload')) { self::$phpunitFiles = array_merge(self::$phpunitFiles, phpunit_story_autoload()); } if (function_exists('php_invoker_autoload')) { self::$phpunitFiles = array_merge(self::$phpunitFiles, php_invoker_autoload()); } self::$phpunitFiles = array_flip(self::$phpunitFiles); } return self::$phpunitFiles; }
/** * Runs the bare test sequence. */ public function runBare() { $this->numAssertions = 0; // Backup the $GLOBALS array and static attributes. if ($this->runTestInSeparateProcess !== TRUE && $this->inIsolation !== TRUE) { if ($this->backupGlobals === NULL || $this->backupGlobals === TRUE) { PHPUnit_Util_GlobalState::backupGlobals($this->backupGlobalsBlacklist); } if ($this->backupStaticAttributes === TRUE) { PHPUnit_Util_GlobalState::backupStaticAttributes($this->backupStaticAttributesBlacklist); } } // Start output buffering. ob_start(); $this->outputBufferingActive = TRUE; // Clean up stat cache. clearstatcache(); // Backup the cwd $currentWorkingDirectory = getcwd(); try { if ($this->inIsolation) { $this->setUpBeforeClass(); } $this->setExpectedExceptionFromAnnotation(); $this->setUp(); $this->checkRequirements(); $this->assertPreConditions(); $this->testResult = $this->runTest(); $this->verifyMockObjects(); $this->assertPostConditions(); $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED; } catch (PHPUnit_Framework_IncompleteTest $e) { $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE; $this->statusMessage = $e->getMessage(); } catch (PHPUnit_Framework_SkippedTest $e) { $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED; $this->statusMessage = $e->getMessage(); } catch (PHPUnit_Framework_AssertionFailedError $e) { $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE; $this->statusMessage = $e->getMessage(); } catch (Exception $e) { $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_ERROR; $this->statusMessage = $e->getMessage(); } // Clean up the mock objects. $this->mockObjects = array(); // Tear down the fixture. An exception raised in tearDown() will be // caught and passed on when no exception was raised before. try { $this->tearDown(); if ($this->inIsolation) { $this->tearDownAfterClass(); } } catch (Exception $_e) { if (!isset($e)) { $e = $_e; } } // Stop output buffering. if ($this->outputCallback === FALSE) { $this->output = ob_get_contents(); } else { $this->output = call_user_func_array($this->outputCallback, array(ob_get_contents())); } ob_end_clean(); $this->outputBufferingActive = FALSE; // Clean up stat cache. clearstatcache(); // Restore the cwd if it was changed by the test if ($currentWorkingDirectory != getcwd()) { chdir($currentWorkingDirectory); } // Restore the $GLOBALS array and static attributes. if ($this->runTestInSeparateProcess !== TRUE && $this->inIsolation !== TRUE) { if ($this->backupGlobals === NULL || $this->backupGlobals === TRUE) { PHPUnit_Util_GlobalState::restoreGlobals($this->backupGlobalsBlacklist); } if ($this->backupStaticAttributes === TRUE) { PHPUnit_Util_GlobalState::restoreStaticAttributes(); } } // Clean up INI settings. foreach ($this->iniSettings as $varName => $oldValue) { ini_set($varName, $oldValue); } $this->iniSettings = array(); // Clean up locale settings. foreach ($this->locale as $category => $locale) { setlocale($category, $locale); } // Perform assertion on output. if (!isset($e)) { try { if ($this->outputExpectedRegex !== NULL) { $this->hasPerformedExpectationsOnOutput = TRUE; $this->assertRegExp($this->outputExpectedRegex, $this->output); $this->outputExpectedRegex = NULL; } else { if ($this->outputExpectedString !== NULL) { $this->hasPerformedExpectationsOnOutput = TRUE; $this->assertEquals($this->outputExpectedString, $this->output); $this->outputExpectedString = NULL; } } } catch (Exception $_e) { $e = $_e; } } // Workaround for missing "finally". if (isset($e)) { $this->onNotSuccessfulTest($e); } }
/** * @covers PHPUnit_Util_GlobalState::processIncludedFilesAsString */ public function testIncludedFilesAsStringSkipsVfsProtocols() { $dir = __DIR__; $files = ['phpunit', $dir . '/ConfigurationTest.php', $dir . '/GlobalStateTest.php', 'vfs://' . $dir . '/RegexTest.php', 'phpvfs53e46260465c7://' . $dir . '/TestTest.php', 'file://' . $dir . '/XMLTest.php']; $this->assertEquals("require_once '" . $dir . "/ConfigurationTest.php';\n" . "require_once '" . $dir . "/GlobalStateTest.php';\n" . "require_once 'file://" . $dir . "/XMLTest.php';\n", PHPUnit_Util_GlobalState::processIncludedFilesAsString($files)); }
public static function restoreStaticAttributes() { foreach (self::$staticAttributes as $className => $staticAttributes) { foreach ($staticAttributes as $name => $value) { $reflector = new ReflectionProperty($className, $name); $reflector->setAccessible(true); $reflector->setValue(unserialize($value)); } } self::$staticAttributes = array(); }
/** * Define constants after including files. */ function prepareTemplate(Text_Template $template) { $template->setVar(array('constants' => '')); $template->setVar(array('wp_constants' => PHPUnit_Util_GlobalState::getConstantsAsString())); parent::prepareTemplate($template); }
/** * Runs the bare test sequence. */ public function runBare() { $this->numAssertions = 0; // Backup the $GLOBALS array and static attributes. if ($this->runTestInSeparateProcess !== true && $this->inIsolation !== true) { if ($this->backupGlobals === null || $this->backupGlobals === true) { PHPUnit_Util_GlobalState::backupGlobals($this->backupGlobalsBlacklist); } if ($this->backupStaticAttributes === true) { PHPUnit_Util_GlobalState::backupStaticAttributes($this->backupStaticAttributesBlacklist); } } $this->startOutputBuffering(); // Clean up stat cache. clearstatcache(); // Backup the cwd $currentWorkingDirectory = getcwd(); $hookMethods = PHPUnit_Util_Test::getHookMethods(get_class($this)); try { $hasMetRequirements = false; $this->checkRequirements(); $hasMetRequirements = true; if ($this->inIsolation) { foreach ($hookMethods['beforeClass'] as $method) { $this->{$method}(); } } $this->setExpectedExceptionFromAnnotation(); foreach ($hookMethods['before'] as $method) { $this->{$method}(); } $this->assertPreConditions(); $this->testResult = $this->runTest(); $this->verifyMockObjects(); $this->assertPostConditions(); $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED; } catch (PHPUnit_Framework_IncompleteTest $e) { $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE; $this->statusMessage = $e->getMessage(); } catch (PHPUnit_Framework_SkippedTest $e) { $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED; $this->statusMessage = $e->getMessage(); } catch (PHPUnit_Framework_AssertionFailedError $e) { $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE; $this->statusMessage = $e->getMessage(); } catch (Exception $e) { $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_ERROR; $this->statusMessage = $e->getMessage(); } // Clean up the mock objects. $this->mockObjects = array(); // Tear down the fixture. An exception raised in tearDown() will be // caught and passed on when no exception was raised before. try { if ($hasMetRequirements) { foreach ($hookMethods['after'] as $method) { $this->{$method}(); } if ($this->inIsolation) { foreach ($hookMethods['afterClass'] as $method) { $this->{$method}(); } } } } catch (Exception $_e) { if (!isset($e)) { $e = $_e; } } try { $this->stopOutputBuffering(); } catch (PHPUnit_Framework_RiskyTestError $_e) { if (!isset($e)) { $e = $_e; } } // Clean up stat cache. clearstatcache(); // Restore the cwd if it was changed by the test if ($currentWorkingDirectory != getcwd()) { chdir($currentWorkingDirectory); } // Restore the $GLOBALS array and static attributes. if ($this->runTestInSeparateProcess !== true && $this->inIsolation !== true) { if ($this->backupGlobals === null || $this->backupGlobals === true) { PHPUnit_Util_GlobalState::restoreGlobals($this->backupGlobalsBlacklist); } if ($this->backupStaticAttributes === true) { PHPUnit_Util_GlobalState::restoreStaticAttributes(); } } // Clean up INI settings. foreach ($this->iniSettings as $varName => $oldValue) { ini_set($varName, $oldValue); } $this->iniSettings = array(); // Clean up locale settings. foreach ($this->locale as $category => $locale) { setlocale($category, $locale); } // Perform assertion on output. if (!isset($e)) { try { if ($this->outputExpectedRegex !== null) { $this->assertRegExp($this->outputExpectedRegex, $this->output); } elseif ($this->outputExpectedString !== null) { $this->assertEquals($this->outputExpectedString, $this->output); } } catch (Exception $_e) { $e = $_e; } } // Workaround for missing "finally". if (isset($e)) { $this->onNotSuccessfulTest($e); } }
/** * @return array * @since Method available since Release 3.6.0 */ public static function phpunitFiles() { if (self::$phpunitFiles === NULL) { self::$phpunitFiles = array(); self::addDirectoryContainingClassToPHPUnitFilesList('File_Iterator'); self::addDirectoryContainingClassToPHPUnitFilesList('PHP_CodeCoverage'); self::addDirectoryContainingClassToPHPUnitFilesList('PHP_Invoker'); self::addDirectoryContainingClassToPHPUnitFilesList('PHP_Timer'); self::addDirectoryContainingClassToPHPUnitFilesList('PHP_Token'); self::addDirectoryContainingClassToPHPUnitFilesList('PHPUnit_Framework_TestCase', 2); self::addDirectoryContainingClassToPHPUnitFilesList('PHPUnit_Extensions_Database_TestCase', 2); self::addDirectoryContainingClassToPHPUnitFilesList('PHPUnit_Framework_MockObject_Generator', 2); self::addDirectoryContainingClassToPHPUnitFilesList('PHPUnit_Extensions_SeleniumTestCase', 2); self::addDirectoryContainingClassToPHPUnitFilesList('PHPUnit_Extensions_Story_TestCase', 2); self::addDirectoryContainingClassToPHPUnitFilesList('Text_Template'); } return self::$phpunitFiles; }
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ require dirname(dirname(__FILE__)) . '/PHPUnit/Autoload.php'; $stub = <<<ENDSTUB #!/usr/bin/env php <?php Phar::mapPhar('phpunit.phar'); require 'phar://phpunit.phar/PHPUnit/Autoload.php'; PHPUnit_TextUI_Command::main(); __HALT_COMPILER(); ENDSTUB; $phar = new Phar('phpunit.phar', 0, 'phpunit.phar'); $phar->startBuffering(); $files = array_keys(PHPUnit_Util_GlobalState::phpunitFiles()); $offset = substr_count(dirname(__FILE__), '/'); foreach ($files as $file) { $phar->addFile($file, join('/', array_slice(explode('/', $file), $offset))); } $phar->setStub($stub); $phar->stopBuffering();
/** * Get the dependend classes of this test. * * @return string[] An array containing class names as keys and path to the * file's defining class as value. * * @author Dominik del Bondio <*****@*****.**> * @since 1.1.0 */ private function getDependendClasses() { // We need to collect the dependend classes in case there is a test which // has set @agaviBootstrap to off. That results in the Agavi autoloader not // being started and if the test class depends on any files from Agavi (like // AgaviPhpUnitTestCase) it would not be loaded when the test is instantiated $classesInTest = array(); $reflectionClass = new ReflectionClass(get_class($this)); $testFile = $reflectionClass->getFileName(); $getDeclaredFuncs = array('get_declared_classes', 'get_declared_interfaces'); if (version_compare(PHP_VERSION, '5.4', '>=')) { $getDeclaredFuncs[] = 'get_declared_traits'; } foreach ($getDeclaredFuncs as $getDeclaredFunc) { foreach ($getDeclaredFunc() as $name) { $reflectionClass = new ReflectionClass($name); if ($testFile === $reflectionClass->getFileName()) { $classesInTest[] = $name; } } } // FIXME: added by phpunit 4.x if (class_exists('PHPUnit_Util_Blacklist')) { $blacklist = new PHPUnit_Util_Blacklist(); $isBlacklisted = function ($file) use($testFile, $blacklist) { return $file === $testFile || $blacklist->isBlacklisted($file); }; } elseif (is_callable(array('PHPUnit_Util_GlobalState', 'phpunitFiles'))) { $blacklist = PHPUnit_Util_GlobalState::phpunitFiles(); $isBlacklisted = function ($file) use($testFile, $blacklist) { return $file === $testFile || isset($blacklist[$file]); }; } else { $isBlacklisted = function ($file) use($testFile) { return $file === $testFile; }; } $classesToFile = array('AgaviTesting' => realpath(__DIR__ . '/AgaviTesting.class.php')); foreach ($classesInTest as $className) { $classesToFile = array_merge($classesToFile, $this->getClassDependendFiles(new ReflectionClass($className), $isBlacklisted)); } return $classesToFile; }
public static function checkIfThereIsClosureInIt($arr) { if ($arr instanceof Closure) { return true; } if (is_object($arr)) { $arr = get_object_vars($arr); } if (is_array($arr)) { foreach ($arr as $x) { if (PHPUnit_Util_GlobalState::checkIfThereIsClosureInIt($x)) { return true; } } } return false; }