本文整理汇总了PHP中PHPUnit_Util_PHP::runJob方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Util_PHP::runJob方法的具体用法?PHP PHPUnit_Util_PHP::runJob怎么用?PHP PHPUnit_Util_PHP::runJob使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Util_PHP
的用法示例。
在下文中一共展示了PHPUnit_Util_PHP::runJob方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Runs a test and collects its result in a TestResult instance.
*
* @param PHPUnit_Framework_TestResult $result
* @return PHPUnit_Framework_TestResult
*/
public function run(PHPUnit_Framework_TestResult $result = null)
{
$sections = $this->parse();
$code = $this->render($sections['FILE']);
if ($result === null) {
$result = new PHPUnit_Framework_TestResult();
}
$skip = false;
$time = 0;
$settings = $this->settings;
$result->startTest($this);
if (isset($sections['INI'])) {
$settings = array_merge($settings, $this->parseIniSection($sections['INI']));
}
// Redirects STDERR to STDOUT
$this->phpUtil->setUseStderrRedirection(true);
if (isset($sections['SKIPIF'])) {
$jobResult = $this->phpUtil->runJob($sections['SKIPIF'], $settings);
if (!strncasecmp('skip', ltrim($jobResult['stdout']), 4)) {
if (preg_match('/^\\s*skip\\s*(.+)\\s*/i', $jobResult['stdout'], $message)) {
$message = substr($message[1], 2);
} else {
$message = '';
}
$result->addFailure($this, new PHPUnit_Framework_SkippedTestError($message), 0);
$skip = true;
}
}
if (!$skip) {
PHP_Timer::start();
$jobResult = $this->phpUtil->runJob($code, $settings);
$time = PHP_Timer::stop();
try {
$this->assertPhptExpectation($sections, $jobResult['stdout']);
} catch (PHPUnit_Framework_AssertionFailedError $e) {
$result->addFailure($this, $e, $time);
} catch (Throwable $t) {
$result->addError($this, $t, $time);
} catch (Exception $e) {
$result->addError($this, $e, $time);
}
if (isset($sections['CLEAN'])) {
$cleanCode = $this->render($sections['CLEAN']);
$this->phpUtil->runJob($cleanCode, $this->settings);
}
}
$result->endTest($this, $time);
return $result;
}
示例2: run
/**
* 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);
//.........这里部分代码省略.........
示例3: run
/**
* 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;
}
示例4: run
/**
* 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);
//.........这里部分代码省略.........
示例5: run
/**
* Runs a test and collects its result in a TestResult instance.
*
* @param PHPUnit_Framework_TestResult $result
*
* @return PHPUnit_Framework_TestResult
*/
public function run(PHPUnit_Framework_TestResult $result = null)
{
$sections = $this->parse();
$code = $this->render($sections['FILE']);
if ($result === null) {
$result = new PHPUnit_Framework_TestResult();
}
$skip = false;
$xfail = false;
$time = 0;
$settings = $this->settings;
$result->startTest($this);
if (isset($sections['INI'])) {
$settings = array_merge($settings, $this->parseIniSection($sections['INI']));
}
if (isset($sections['ENV'])) {
$env = $this->parseEnvSection($sections['ENV']);
$this->phpUtil->setEnv($env);
}
// Redirects STDERR to STDOUT
$this->phpUtil->setUseStderrRedirection(true);
if ($result->enforcesTimeLimit()) {
$this->phpUtil->setTimeout($result->getTimeoutForLargeTests());
}
if (isset($sections['SKIPIF'])) {
$jobResult = $this->phpUtil->runJob($sections['SKIPIF'], $settings);
if (!strncasecmp('skip', ltrim($jobResult['stdout']), 4)) {
if (preg_match('/^\\s*skip\\s*(.+)\\s*/i', $jobResult['stdout'], $message)) {
$message = substr($message[1], 2);
} else {
$message = '';
}
$result->addFailure($this, new PHPUnit_Framework_SkippedTestError($message), 0);
$skip = true;
}
}
if (isset($sections['XFAIL'])) {
$xfail = trim($sections['XFAIL']);
}
if (!$skip) {
if (isset($sections['STDIN'])) {
$this->phpUtil->setStdin($sections['STDIN']);
}
if (isset($sections['ARGS'])) {
$this->phpUtil->setArgs($sections['ARGS']);
}
PHP_Timer::start();
$jobResult = $this->phpUtil->runJob($code, $settings);
$time = PHP_Timer::stop();
try {
$this->assertPhptExpectation($sections, $jobResult['stdout']);
} catch (PHPUnit_Framework_AssertionFailedError $e) {
if ($xfail !== false) {
$result->addFailure($this, new PHPUnit_Framework_IncompleteTestError($xfail, 0, $e), $time);
} else {
$result->addFailure($this, $e, $time);
}
} catch (Throwable $t) {
$result->addError($this, $t, $time);
}
if ($result->allCompletelyImplemented() && $xfail !== false) {
$result->addFailure($this, new PHPUnit_Framework_IncompleteTestError('XFAIL section but test passes'), $time);
}
$this->phpUtil->setStdin('');
$this->phpUtil->setArgs('');
if (isset($sections['CLEAN'])) {
$cleanCode = $this->render($sections['CLEAN']);
$this->phpUtil->runJob($cleanCode, $this->settings);
}
}
$result->endTest($this, $time);
return $result;
}
示例6: runPhp
/**
* Run php code
*
* @param string $phpcode
* @param array $settings
* @return array
*/
public function runPhp($phpcode, array $settings)
{
return $this->phpRunner->runJob($phpcode, $settings);
}