getConstantsAsString() 공개 정적인 메소드

public static getConstantsAsString ( )
예제 #1
0
 /**
  * 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;
 }
예제 #2
0
 /**
  * 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 InvalidArgumentException
  */
 public function run(PHPUnit_Framework_TestResult $result = NULL)
 {
     if ($result === NULL) {
         $result = $this->createResult();
     }
     $this->setExpectedExceptionFromAnnotation();
     $this->setUseErrorHandlerFromAnnotation();
     $this->setUseOutputBufferingFromAnnotation();
     if ($this->useErrorHandler !== NULL) {
         $oldErrorHandlerSetting = $result->getConvertErrorsToExceptions();
         $result->convertErrorsToExceptions($this->useErrorHandler);
     }
     $this->result = $result;
     if (!empty($this->dependencies) && !$this->inIsolation) {
         $className = get_class($this);
         $passed = $this->result->passed();
         $passedKeys = array_keys($passed);
         $numKeys = count($passedKeys);
         for ($i = 0; $i < $numKeys; $i++) {
             $pos = strpos($passedKeys[$i], ' with data set');
             if ($pos !== FALSE) {
                 $passedKeys[$i] = substr($passedKeys[$i], 0, $pos);
             }
         }
         $passedKeys = array_flip(array_unique($passedKeys));
         foreach ($this->dependencies as $dependency) {
             if (strpos($dependency, '::') === FALSE) {
                 $dependency = $className . '::' . $dependency;
             }
             if (!isset($passedKeys[$dependency])) {
                 $result->addError($this, new PHPUnit_Framework_SkippedTestError(sprintf('This test depends on "%s" to pass.', $dependency)), 0);
                 return;
             } else {
                 if (isset($passed[$dependency])) {
                     $this->dependencyInput[] = $passed[$dependency];
                 } else {
                     $this->dependencyInput[] = NULL;
                 }
             }
         }
     }
     if ($this->runTestInSeparateProcess === TRUE && $this->inIsolation !== TRUE && !$this instanceof PHPUnit_Extensions_SeleniumTestCase && !$this instanceof PHPUnit_Extensions_PhptTestCase) {
         $class = new ReflectionClass($this);
         $collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
         $template = new PHPUnit_Util_Template(sprintf('%s%sProcess%sTestCaseMethod.tpl', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
         $template->setVar(array('filename' => $class->getFileName(), 'className' => $class->getName(), 'methodName' => $this->name, 'data' => addcslashes(serialize($this->data), "'"), 'dependencyInput' => addcslashes(serialize($this->dependencyInput), "'"), 'dataName' => $this->dataName, 'collectCodeCoverageInformation' => $collectCodeCoverageInformation ? 'TRUE' : 'FALSE', 'included_files' => $this->preserveGlobalState ? PHPUnit_Util_GlobalState::getIncludedFilesAsString() : '', 'constants' => $this->preserveGlobalState ? PHPUnit_Util_GlobalState::getConstantsAsString() : '', 'globals' => $this->preserveGlobalState ? PHPUnit_Util_GlobalState::getGlobalsAsString() : '', 'include_path' => addslashes(get_include_path())));
         $this->prepareTemplate($template);
         $job = $template->render();
         $result->startTest($this);
         $jobResult = PHPUnit_Util_PHP::runJob($job);
         if (!empty($jobResult['stderr'])) {
             $time = 0;
             $result->addError($this, new RuntimeException(trim($jobResult['stderr'])), $time);
         } else {
             $childResult = @unserialize($jobResult['stdout']);
             if ($childResult !== FALSE) {
                 if (!empty($childResult['output'])) {
                     print $childResult['output'];
                 }
                 $this->testResult = $childResult['testResult'];
                 $this->numAssertions = $childResult['numAssertions'];
                 $childResult = $childResult['result'];
                 if ($collectCodeCoverageInformation) {
                     $codeCoverageInformation = $childResult->getRawCodeCoverageInformation();
                     $result->appendCodeCoverageInformation($this, $codeCoverageInformation[0]['data']);
                 }
                 $time = $childResult->time();
                 $notImplemented = $childResult->notImplemented();
                 $skipped = $childResult->skipped();
                 $errors = $childResult->errors();
                 $failures = $childResult->failures();
                 if (!empty($notImplemented)) {
                     $result->addError($this, $notImplemented[0]->thrownException(), $time);
                 } else {
                     if (!empty($skipped)) {
                         $result->addError($this, $skipped[0]->thrownException(), $time);
                     } else {
                         if (!empty($errors)) {
                             $result->addError($this, $errors[0]->thrownException(), $time);
                         } else {
                             if (!empty($failures)) {
                                 $result->addFailure($this, $failures[0]->thrownException(), $time);
                             }
                         }
                     }
                 }
             } else {
                 $time = 0;
                 $result->addError($this, new RuntimeException(trim($jobResult['stdout'])), $time);
             }
         }
         $result->endTest($this, $time);
     } else {
         $result->run($this);
     }
     if ($this->useErrorHandler !== NULL) {
         $result->convertErrorsToExceptions($oldErrorHandlerSetting);
     }
     $this->result = NULL;
     return $result;
 }
예제 #3
0
 /**
  * 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();
         $this->setUseOutputBufferingFromAnnotation();
     }
     if ($this->useErrorHandler !== NULL) {
         $oldErrorHandlerSetting = $result->getConvertErrorsToExceptions();
         $result->convertErrorsToExceptions($this->useErrorHandler);
     }
     if (!$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(sprintf('%s%sProcess%sTestCaseMethod.tpl', __DIR__, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
         if ($this->preserveGlobalState) {
             $constants = PHPUnit_Util_GlobalState::getConstantsAsString();
             $globals = PHPUnit_Util_GlobalState::getGlobalsAsString();
             $includedFiles = PHPUnit_Util_GlobalState::getIncludedFilesAsString();
         } else {
             $constants = '';
             $globals = '';
             $includedFiles = '';
         }
         if ($result->getCollectCodeCoverageInformation()) {
             $coverage = 'TRUE';
         } else {
             $coverage = 'FALSE';
         }
         if ($result->isStrict()) {
             $strict = 'TRUE';
         } else {
             $strict = 'FALSE';
         }
         $data = var_export(serialize($this->data), 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 . ".'";
         $dependencyInput = "'." . $dependencyInput . ".'";
         $includePath = "'." . $includePath . ".'";
         $template->setVar(array('filename' => $class->getFileName(), 'className' => $class->getName(), 'methodName' => $this->name, 'collectCodeCoverageInformation' => $coverage, 'data' => $data, 'dataName' => $this->dataName, 'dependencyInput' => $dependencyInput, 'constants' => $constants, 'globals' => $globals, 'include_path' => $includePath, 'included_files' => $includedFiles, 'strict' => $strict));
         $this->prepareTemplate($template);
         $php = PHPUnit_Util_PHP::factory();
         $php->runJob($template->render(), $this, $result);
     } else {
         $result->run($this);
     }
     if ($this->useErrorHandler !== NULL) {
         $result->convertErrorsToExceptions($oldErrorHandlerSetting);
     }
     $this->result = NULL;
     return $result;
 }
예제 #4
0
파일: testcase.php 프로젝트: dannyoz/tls
 /**
  * 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);
 }
예제 #5
0
 /**
  * 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 InvalidArgumentException
  */
 public function run(PHPUnit_Framework_TestResult $result = NULL)
 {
     if ($result === NULL) {
         $result = $this->createResult();
     }
     $this->setExpectedExceptionFromAnnotation();
     $this->setUseErrorHandlerFromAnnotation();
     $this->setUseOutputBufferingFromAnnotation();
     if ($this->useErrorHandler !== NULL) {
         $oldErrorHandlerSetting = $result->getConvertErrorsToExceptions();
         $result->convertErrorsToExceptions($this->useErrorHandler);
     }
     $this->result = $result;
     if (!empty($this->dependencies) && !$this->inIsolation) {
         $className = get_class($this);
         $passed = $this->result->passed();
         $passedKeys = array_keys($passed);
         $numKeys = count($passedKeys);
         for ($i = 0; $i < $numKeys; $i++) {
             $pos = strpos($passedKeys[$i], ' with data set');
             if ($pos !== FALSE) {
                 $passedKeys[$i] = substr($passedKeys[$i], 0, $pos);
             }
         }
         $passedKeys = array_flip(array_unique($passedKeys));
         foreach ($this->dependencies as $dependency) {
             if (strpos($dependency, '::') === FALSE) {
                 $dependency = $className . '::' . $dependency;
             }
             if (!isset($passedKeys[$dependency])) {
                 $result->addError($this, new PHPUnit_Framework_SkippedTestError(sprintf('This test depends on "%s" to pass.', $dependency)), 0);
                 return;
             } else {
                 if (isset($passed[$dependency])) {
                     $this->dependencyInput[] = $passed[$dependency];
                 } else {
                     $this->dependencyInput[] = NULL;
                 }
             }
         }
     }
     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(sprintf('%s%sProcess%sTestCaseMethod.tpl', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
         if ($this->preserveGlobalState) {
             $constants = PHPUnit_Util_GlobalState::getConstantsAsString();
             $globals = PHPUnit_Util_GlobalState::getGlobalsAsString();
             $includedFiles = PHPUnit_Util_GlobalState::getIncludedFilesAsString();
         } else {
             $constants = '';
             $globals = '';
             $includedFiles = '';
         }
         if ($result->getCollectCodeCoverageInformation()) {
             $coverage = 'TRUE';
         } else {
             $coverage = 'FALSE';
         }
         $data = addcslashes(serialize($this->data), "'");
         $dependencyInput = addcslashes(serialize($this->dependencyInput), "'");
         $includePath = addslashes(get_include_path());
         $template->setVar(array('filename' => $class->getFileName(), 'className' => $class->getName(), 'methodName' => $this->name, 'collectCodeCoverageInformation' => $coverage, 'data' => $data, 'dataName' => $this->dataName, 'dependencyInput' => $dependencyInput, 'constants' => $constants, 'globals' => $globals, 'include_path' => $includePath, 'included_files' => $includedFiles));
         $this->prepareTemplate($template);
         PHPUnit_Util_PHP::runJob($template->render(), $this, $result);
     } else {
         $result->run($this);
     }
     if ($this->useErrorHandler !== NULL) {
         $result->convertErrorsToExceptions($oldErrorHandlerSetting);
     }
     $this->result = NULL;
     return $result;
 }
예제 #6
0
    /**
     * 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 InvalidArgumentException
     */
    public function run(PHPUnit_Framework_TestResult $result = NULL)
    {
        if ($result === NULL) {
            $result = $this->createResult();
        }

        $this->result = $result;

        $this->setExpectedExceptionFromAnnotation();
        $this->setUseErrorHandlerFromAnnotation();
        $this->setUseOutputBufferingFromAnnotation();

        if ($this->useErrorHandler !== NULL) {
            $oldErrorHandlerSetting = $result->getConvertErrorsToExceptions();
            $result->convertErrorsToExceptions($this->useErrorHandler);
        }

        if (!$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(
              sprintf(
                '%s%sProcess%sTestCaseMethod.tpl',

                dirname(__FILE__),
                DIRECTORY_SEPARATOR,
                DIRECTORY_SEPARATOR,
                DIRECTORY_SEPARATOR
              )
            );

            if ($this->preserveGlobalState) {
                $constants     = PHPUnit_Util_GlobalState::getConstantsAsString();
                $globals       = PHPUnit_Util_GlobalState::getGlobalsAsString();
                $includedFiles = PHPUnit_Util_GlobalState::getIncludedFilesAsString();
            } else {
                $constants     = '';
                $globals       = '';
                $includedFiles = '';
            }

            if ($result->getCollectCodeCoverageInformation()) {
                $coverage = 'TRUE';
            } else {
                $coverage = 'FALSE';
            }

            if ($result->isStrict()) {
                $strict = 'TRUE';
            } else {
                $strict = 'FALSE';
            }

            $data            = addcslashes(serialize($this->data), "'");
            $dependencyInput = addcslashes(
              serialize($this->dependencyInput), "'"
            );
            $includePath     = addslashes(get_include_path());

            $template->setVar(
              array(
                'filename'                       => $class->getFileName(),
                'className'                      => $class->getName(),
                'methodName'                     => $this->name,
                'collectCodeCoverageInformation' => $coverage,
                'data'                           => $data,
                'dataName'                       => $this->dataName,
                'dependencyInput'                => $dependencyInput,
                'constants'                      => $constants,
                'globals'                        => $globals,
                'include_path'                   => $includePath,
                'included_files'                 => $includedFiles,
                'strict'                         => $strict
              )
            );

            $this->prepareTemplate($template);

            PHPUnit_Util_PHP::runJob($template->render(), $this, $result);
        } else {
            $result->run($this);
        }

        if ($this->useErrorHandler !== NULL) {
            $result->convertErrorsToExceptions($oldErrorHandlerSetting);
        }

        $this->result = NULL;

        return $result;
    }