本文整理汇总了PHP中PHPUnit_Util_Test::getLinesToBeCovered方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Util_Test::getLinesToBeCovered方法的具体用法?PHP PHPUnit_Util_Test::getLinesToBeCovered怎么用?PHP PHPUnit_Util_Test::getLinesToBeCovered使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Util_Test
的用法示例。
在下文中一共展示了PHPUnit_Util_Test::getLinesToBeCovered方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isValidMethod
/**
* Check if the method has valid @covers and @uses tags
*
* @param string $class
* @param string $method
*
* @return bool
*/
public static function isValidMethod($class, $method)
{
try {
Test::getLinesToBeCovered($class, $method);
} catch (CodeCoverageException $e) {
return false;
}
return true;
}
示例2: codeCoverageEnd
public function codeCoverageEnd($status, $time)
{
$codeCoverage = $this->getTestResultObject()->getCodeCoverage();
if (!$codeCoverage) {
return;
}
$linesToBeCovered = \PHPUnit_Util_Test::getLinesToBeCovered(get_class($this->testClassInstance), 'test');
$linesToBeUsed = \PHPUnit_Util_Test::getLinesToBeUsed(get_class($this->testClassInstance), 'test');
try {
$codeCoverage->stop(true, $linesToBeCovered, $linesToBeUsed);
} catch (\PHP_CodeCoverage_Exception $cce) {
if ($status === \Codeception\Test\Test::STATUS_OK) {
$this->getTestResultObject()->addError($this, $cce, $time);
}
}
}
示例3: run
/**
* Runs a TestCase.
*
* @param PHPUnit_Framework_Test $test
*/
public function run(PHPUnit_Framework_Test $test)
{
PHPUnit_Framework_Assert::resetCount();
$error = false;
$failure = false;
$warning = false;
$incomplete = false;
$risky = false;
$skipped = false;
$this->startTest($test);
$errorHandlerSet = false;
if ($this->convertErrorsToExceptions) {
$oldErrorHandler = set_error_handler(['PHPUnit_Util_ErrorHandler', 'handleError'], E_ALL | E_STRICT);
if ($oldErrorHandler === null) {
$errorHandlerSet = true;
} else {
restore_error_handler();
}
}
$collectCodeCoverage = $this->codeCoverage !== null && !$test instanceof PHPUnit_Framework_WarningTestCase;
if ($collectCodeCoverage) {
$this->codeCoverage->start($test);
}
$monitorFunctions = $this->beStrictAboutResourceUsageDuringSmallTests && !$test instanceof PHPUnit_Framework_WarningTestCase && $test->getSize() == PHPUnit_Util_Test::SMALL && function_exists('xdebug_start_function_monitor');
if ($monitorFunctions) {
xdebug_start_function_monitor(ResourceOperations::getFunctions());
}
PHP_Timer::start();
try {
if (!$test instanceof PHPUnit_Framework_WarningTestCase && $test->getSize() != PHPUnit_Util_Test::UNKNOWN && $this->enforceTimeLimit && extension_loaded('pcntl') && class_exists('PHP_Invoker')) {
switch ($test->getSize()) {
case PHPUnit_Util_Test::SMALL:
$_timeout = $this->timeoutForSmallTests;
break;
case PHPUnit_Util_Test::MEDIUM:
$_timeout = $this->timeoutForMediumTests;
break;
case PHPUnit_Util_Test::LARGE:
$_timeout = $this->timeoutForLargeTests;
break;
}
$invoker = new PHP_Invoker();
$invoker->invoke([$test, 'runBare'], [], $_timeout);
} else {
$test->runBare();
}
} catch (PHPUnit_Framework_AssertionFailedError $e) {
$failure = true;
if ($e instanceof PHPUnit_Framework_RiskyTestError) {
$risky = true;
} elseif ($e instanceof PHPUnit_Framework_IncompleteTestError) {
$incomplete = true;
} elseif ($e instanceof PHPUnit_Framework_SkippedTestError) {
$skipped = true;
}
} catch (PHPUnit_Framework_Warning $e) {
$warning = true;
} catch (PHPUnit_Framework_Exception $e) {
$error = true;
} catch (Throwable $e) {
$e = new PHPUnit_Framework_ExceptionWrapper($e);
$error = true;
} catch (Exception $e) {
$e = new PHPUnit_Framework_ExceptionWrapper($e);
$error = true;
}
$time = PHP_Timer::stop();
$test->addToAssertionCount(PHPUnit_Framework_Assert::getCount());
if ($monitorFunctions) {
$blacklist = new PHPUnit_Util_Blacklist();
$functions = xdebug_get_monitored_functions();
xdebug_stop_function_monitor();
foreach ($functions as $function) {
if (!$blacklist->isBlacklisted($function['filename'])) {
$this->addFailure($test, new PHPUnit_Framework_RiskyTestError(sprintf('%s() used in %s:%s', $function['function'], $function['filename'], $function['lineno'])), $time);
}
}
}
if ($this->beStrictAboutTestsThatDoNotTestAnything && $test->getNumAssertions() == 0) {
$risky = true;
}
if ($collectCodeCoverage) {
$append = !$risky && !$incomplete && !$skipped;
$linesToBeCovered = [];
$linesToBeUsed = [];
if ($append && $test instanceof PHPUnit_Framework_TestCase) {
$linesToBeCovered = PHPUnit_Util_Test::getLinesToBeCovered(get_class($test), $test->getName(false));
$linesToBeUsed = PHPUnit_Util_Test::getLinesToBeUsed(get_class($test), $test->getName(false));
}
try {
$this->codeCoverage->stop($append, $linesToBeCovered, $linesToBeUsed);
} catch (PHP_CodeCoverage_UnintentionallyCoveredCodeException $cce) {
$this->addFailure($test, new PHPUnit_Framework_UnintentionallyCoveredCodeError('This test executed code that is not listed as code to be covered or used:' . PHP_EOL . $cce->getMessage()), $time);
} catch (PHPUnit_Framework_InvalidCoversTargetException $cce) {
$this->addFailure($test, new PHPUnit_Framework_InvalidCoversTargetError($cce->getMessage()), $time);
//.........这里部分代码省略.........
示例4: appendCodeCoverageInformation
/**
* Appends code coverage information to the test
*
* @param PHPUnit_Framework_Test $test
* @param array $data
* @since Method available since Release 3.2.0
*/
public function appendCodeCoverageInformation(PHPUnit_Framework_Test $test, $data)
{
$deadCode = array();
$executableCode = array();
foreach (array_keys($data) as $file) {
if (PHPUnit_Util_Filter::isFiltered($file, FALSE)) {
unset($data[$file]);
}
}
$newFilesToCollect = array_diff_key($data, PHPUnit_Util_Filter::getCoveredFiles());
if (count($newFilesToCollect) > 0) {
$deadCode = PHPUnit_Util_CodeCoverage::getDeadLines($newFilesToCollect);
$executableCode = PHPUnit_Util_CodeCoverage::getExecutableLines($newFilesToCollect);
foreach (array_keys($newFilesToCollect) as $file) {
PHPUnit_Util_Filter::addCoveredFile($file);
}
unset($newFilesToCollect);
}
if ($test instanceof PHPUnit_Framework_TestCase) {
$linesToBeCovered = PHPUnit_Util_Test::getLinesToBeCovered(get_class($test), $test->getName());
if (!empty($linesToBeCovered)) {
$data = array_intersect_key($data, $linesToBeCovered);
foreach (array_keys($data) as $file) {
$data[$file] = array_intersect_key($data[$file], array_flip($linesToBeCovered[$file]));
}
}
}
$executed = PHPUnit_Util_CodeCoverage::getExecutedLines($data);
unset($data);
$this->codeCoverageInformation[] = array('test' => $test, 'files' => $executed, 'dead' => $deadCode, 'executable' => $executableCode);
}
示例5: run
/**
* Runs a TestCase.
*
* @param PHPUnit_Framework_Test $test
*/
public function run(PHPUnit_Framework_Test $test)
{
PHPUnit_Framework_Assert::resetCount();
$error = false;
$failure = false;
$incomplete = false;
$risky = false;
$skipped = false;
$this->startTest($test);
$errorHandlerSet = false;
if ($this->convertErrorsToExceptions) {
$oldErrorHandler = set_error_handler(array('PHPUnit_Util_ErrorHandler', 'handleError'), E_ALL | E_STRICT);
if ($oldErrorHandler === null) {
$errorHandlerSet = true;
} else {
restore_error_handler();
}
}
$collectCodeCoverage = $this->codeCoverage !== null && !$test instanceof PHPUnit_Extensions_SeleniumTestCase && !$test instanceof PHPUnit_Framework_Warning;
if ($collectCodeCoverage) {
// We need to blacklist test source files when no whitelist is used.
if (!$this->codeCoverage->filter()->hasWhitelist()) {
$classes = $this->getHierarchy(get_class($test), true);
foreach ($classes as $class) {
$this->codeCoverage->filter()->addFileToBlacklist($class->getFileName());
}
}
$this->codeCoverage->start($test);
}
PHP_Timer::start();
try {
if (!$test instanceof PHPUnit_Framework_Warning && $this->beStrictAboutTestSize && extension_loaded('pcntl') && class_exists('PHP_Invoker')) {
switch ($test->getSize()) {
case PHPUnit_Util_Test::SMALL:
$_timeout = $this->timeoutForSmallTests;
break;
case PHPUnit_Util_Test::MEDIUM:
$_timeout = $this->timeoutForMediumTests;
break;
case PHPUnit_Util_Test::LARGE:
$_timeout = $this->timeoutForLargeTests;
break;
}
$invoker = new PHP_Invoker();
$invoker->invoke(array($test, 'runBare'), array(), $_timeout);
} else {
$test->runBare();
}
} catch (PHPUnit_Framework_AssertionFailedError $e) {
$failure = true;
if ($e instanceof PHPUnit_Framework_RiskyTestError) {
$risky = true;
} elseif ($e instanceof PHPUnit_Framework_IncompleteTestError) {
$incomplete = true;
} elseif ($e instanceof PHPUnit_Framework_SkippedTestError) {
$skipped = true;
}
} catch (PHPUnit_Framework_Exception $e) {
$error = true;
} catch (Exception $e) {
$e = new PHPUnit_Framework_ExceptionWrapper($e);
$error = true;
}
$time = PHP_Timer::stop();
$test->addToAssertionCount(PHPUnit_Framework_Assert::getCount());
if ($this->beStrictAboutTestsThatDoNotTestAnything && $test->getNumAssertions() == 0) {
$risky = true;
}
if ($collectCodeCoverage) {
$append = !$risky && !$incomplete && !$skipped;
$linesToBeCovered = array();
$linesToBeUsed = array();
if ($append && $test instanceof PHPUnit_Framework_TestCase) {
$linesToBeCovered = PHPUnit_Util_Test::getLinesToBeCovered(get_class($test), $test->getName(false));
$linesToBeUsed = PHPUnit_Util_Test::getLinesToBeUsed(get_class($test), $test->getName(false));
}
try {
$this->codeCoverage->stop($append, $linesToBeCovered, $linesToBeUsed);
} catch (PHP_CodeCoverage_Exception_UnintentionallyCoveredCode $cce) {
$this->addFailure($test, new PHPUnit_Framework_UnintentionallyCoveredCodeError('This test executed code that is not listed as code to be covered or used:' . PHP_EOL . $cce->getMessage()), $time);
} catch (PHPUnit_Framework_InvalidCoversTargetException $cce) {
$this->addFailure($test, new PHPUnit_Framework_InvalidCoversTargetError($cce->getMessage()), $time);
} catch (PHP_CodeCoverage_Exception $cce) {
$error = true;
if (!isset($e)) {
$e = $cce;
}
}
}
if ($errorHandlerSet === true) {
restore_error_handler();
}
if ($error === true) {
$this->addError($test, $e, $time);
} elseif ($failure === true) {
//.........这里部分代码省略.........
示例6: testMethodParenthesesAreAllowedWithWhitespace
/**
* @covers PHPUnit_Util_Test::getLinesToBeCovered
* @covers PHPUnit_Util_Test::getLinesToBeCoveredOrUsed
*/
public function testMethodParenthesesAreAllowedWithWhitespace()
{
$this->assertSame(array(TEST_FILES_PATH . 'CoveredClass.php' => range(31, 35)), PHPUnit_Util_Test::getLinesToBeCovered('CoverageMethodParenthesesWhitespaceTest', 'testSomething'));
}
示例7: testNamespacedFunctionCanBeCoveredOrUsed
/**
* @covers PHPUnit_Util_Test::getLinesToBeCovered
* @covers PHPUnit_Util_Test::getLinesToBeCoveredOrUsed
*/
public function testNamespacedFunctionCanBeCoveredOrUsed()
{
$this->assertEquals(array(TEST_FILES_PATH . 'NamespaceCoveredFunction.php' => range(4, 7)), PHPUnit_Util_Test::getLinesToBeCovered('CoverageNamespacedFunctionTest', 'testFunc'));
}
示例8: appendCodeCoverageInformation
/**
* Appends code coverage information to the test
*
* @param PHPUnit_Framework_Test $test
* @param array $data
* @since Method available since Release 3.2.0
*/
public function appendCodeCoverageInformation(PHPUnit_Framework_Test $test, $data)
{
if ($test instanceof PHPUnit_Framework_TestCase) {
$linesToBeCovered = PHPUnit_Util_Test::getLinesToBeCovered(get_class($test), $test->getName());
if (!empty($linesToBeCovered)) {
$filesToBeCovered = array_keys($linesToBeCovered);
$filesCovered = array_keys($data);
$filesCovered = array_intersect($filesCovered, $filesToBeCovered);
foreach ($filesCovered as $file) {
$linesCovered = array_keys($data[$file]);
$linesNotToCover = array_diff($linesCovered, $linesToBeCovered[$file]);
foreach ($linesNotToCover as $line) {
if ($data[$file][$line] > 0) {
$data[$file][$line] = -1;
}
}
}
}
}
$this->codeCoverageInformation[] = array('test' => $test, 'files' => $data);
}