本文整理汇总了PHP中PHP_CodeCoverage类的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeCoverage类的具体用法?PHP PHP_CodeCoverage怎么用?PHP PHP_CodeCoverage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PHP_CodeCoverage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* @param PHP_CodeCoverage $coverage
* @param string $target
*/
public function process(PHP_CodeCoverage $coverage, $target)
{
$target = $this->getDirectory($target);
$report = $coverage->getReport();
unset($coverage);
if (!isset($_SERVER['REQUEST_TIME'])) {
$_SERVER['REQUEST_TIME'] = time();
}
$date = date('D M j G:i:s T Y', $_SERVER['REQUEST_TIME']);
$dashboard = new PHP_CodeCoverage_Report_HTML_Renderer_Dashboard($this->templatePath, $this->generator, $date, $this->lowUpperBound, $this->highLowerBound);
$directory = new PHP_CodeCoverage_Report_HTML_Renderer_Directory($this->templatePath, $this->generator, $date, $this->lowUpperBound, $this->highLowerBound);
$file = new PHP_CodeCoverage_Report_HTML_Renderer_File($this->templatePath, $this->generator, $date, $this->lowUpperBound, $this->highLowerBound);
$directory->render($report, $target . 'index.html');
$dashboard->render($report, $target . 'dashboard.html');
foreach ($report as $node) {
$id = $node->getId();
if ($node instanceof PHP_CodeCoverage_Report_Node_Directory) {
if (!file_exists($target . $id)) {
mkdir($target . $id, 0777, true);
}
$directory->render($node, $target . $id . '/index.html');
$dashboard->render($node, $target . $id . '/dashboard.html');
} else {
$dir = dirname($target . $id);
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
$file->render($node, $target . $id . '.html');
}
}
$this->copyFiles($target);
}
示例2: getCoverageForFileWithIgnoredLines
protected function getCoverageForFileWithIgnoredLines()
{
$coverage = new PHP_CodeCoverage($this->setUpXdebugStubForFileWithIgnoredLines(), new PHP_CodeCoverage_Filter());
$coverage->start('FileWithIgnoredLines', TRUE);
$coverage->stop();
return $coverage;
}
示例3: testSimpleMergeLegacy
/**
* Test merge for code coverage library 3 version
*
* @requires function \PHP_CodeCoverage::merge
*/
public function testSimpleMergeLegacy()
{
$firstFile = PARATEST_ROOT . '/src/ParaTest/Logging/LogInterpreter.php';
$secondFile = PARATEST_ROOT . '/src/ParaTest/Logging/MetaProvider.php';
$filter = new \PHP_CodeCoverage_Filter();
$filter->addFilesToWhitelist([$firstFile, $secondFile]);
$coverage1 = new \PHP_CodeCoverage(null, $filter);
$coverage1->append(array($firstFile => array(35 => 1), $secondFile => array(34 => 1)), 'Test1');
$coverage2 = new \PHP_CodeCoverage(null, $filter);
$coverage2->append(array($firstFile => array(35 => 1, 36 => 1)), 'Test2');
$merger = new CoverageMerger();
$this->call($merger, 'addCoverage', $coverage1);
$this->call($merger, 'addCoverage', $coverage2);
/** @var \PHP_CodeCoverage $coverage */
$coverage = $this->getObjectValue($merger, 'coverage');
$this->assertInstanceOf('\\PHP_CodeCoverage', $coverage);
$data = $coverage->getData();
$this->assertCount(2, $data[$firstFile][35]);
$this->assertEquals('Test1', $data[$firstFile][35][0]);
$this->assertEquals('Test2', $data[$firstFile][35][1]);
$this->assertCount(1, $data[$firstFile][36]);
$this->assertEquals('Test2', $data[$firstFile][36][0]);
$this->assertCount(1, $data[$secondFile][34]);
$this->assertEquals('Test1', $data[$secondFile][34][0]);
}
示例4: getCoverageForClassWithAnonymousFunction
protected function getCoverageForClassWithAnonymousFunction()
{
$coverage = new PHP_CodeCoverage($this->setUpXdebugStubForClassWithAnonymousFunction(), new PHP_CodeCoverage_Filter());
$coverage->start('ClassWithAnonymousFunction', true);
$coverage->stop();
return $coverage;
}
示例5: addCoverage
/**
* @param \PHP_CodeCoverage|CodeCoverage $coverage
*/
private function addCoverage($coverage)
{
if (null === $this->coverage) {
$this->coverage = $coverage;
} else {
$this->coverage->merge($coverage);
}
}
示例6: create
/**
* @param PHP_CodeCoverage $coverage
*/
public function create(PHP_CodeCoverage $coverage)
{
$files = $coverage->getData();
$commonPath = $this->reducePaths($files);
$root = new PHP_CodeCoverage_Report_Node_Directory($commonPath, null);
$this->addItems($root, $this->buildDirectoryStructure($files), $coverage->getTests(), $coverage->getCacheTokens());
return $root;
}
示例7: coverage
/**
* @return \PHP_CodeCoverage
*/
public function coverage()
{
$coverage = new \PHP_CodeCoverage();
$coverage->setData($this->data);
$coverage->setTests($this->tests);
$filter = $coverage->filter();
$filter->setBlacklistedFiles($this->blackList);
$filter->setWhitelistedFiles($this->whiteList);
return $coverage;
}
示例8: parseReport
public function parseReport(\PHP_CodeCoverage $report)
{
$classes = array();
foreach ($report->getData() as $filename => $coverage) {
try {
$classes[] = $this->parseClass($filename, $coverage);
} catch (ParserException $e) {
echo "Skipping class " . $filename . ", failed to parse\n";
}
}
return $classes;
}
示例9: process
public function process(PHP_CodeCoverage $coverage, $target)
{
if (substr($target, -1, 1) != DIRECTORY_SEPARATOR) {
$target .= DIRECTORY_SEPARATOR;
}
$this->target = $target;
$this->initTargetDirectory($target);
$report = $coverage->getReport();
$this->project = new PHP_CodeCoverage_Report_XML_Project($coverage->getReport()->getName());
$this->processTests($coverage->getTests());
$this->processDirectory($report, $this->project);
$index = $this->project->asDom();
$index->formatOutput = true;
$index->preserveWhiteSpace = false;
$index->save($target . '/index.xml');
}
示例10: process
/**
* @param PHP_CodeCoverage $coverage
* @param string $target
* @return string
*/
public function process(PHP_CodeCoverage $coverage, $target = null)
{
$filter = $coverage->filter();
$output = sprintf('<?php
$coverage = new PHP_CodeCoverage;
$coverage->setData(%s);
$coverage->setTests(%s);
$filter = $coverage->filter();
$filter->setWhitelistedFiles(%s);
return $coverage;', var_export($coverage->getData(true), 1), var_export($coverage->getTests(), 1), var_export($filter->getWhitelistedFiles(), 1));
if ($target !== null) {
return file_put_contents($target, $output);
} else {
return $output;
}
}
示例11: testAppendThrowsExceptionIfUsedCodeWasNotExecuted
/**
* @covers PHP_CodeCoverage::performUnexecutedCoveredCodeCheck
* @expectedException PHP_CodeCoverage_CoveredCodeNotExecutedException
*/
public function testAppendThrowsExceptionIfUsedCodeWasNotExecuted()
{
$this->coverage->filter()->addDirectoryToWhitelist(TEST_FILES_PATH);
$this->coverage->setCheckForUnexecutedCoveredCode(true);
$data = [TEST_FILES_PATH . 'BankAccount.php' => [29 => -1, 31 => -1]];
$linesToBeCovered = [TEST_FILES_PATH . 'BankAccount.php' => [29, 31]];
$linesToBeUsed = [TEST_FILES_PATH . 'BankAccount.php' => [22, 24]];
$this->coverage->append($data, 'File1.php', true, $linesToBeCovered, $linesToBeUsed);
}
示例12: suite
public static function suite()
{
$srcDir = dirname(dirname(dirname(__DIR__))) . '/src/Pyrus/AtomicFileTransaction/Transaction';
// Setup coverage filters
$filter = PHP_CodeCoverage::getInstance()->filter();
$filter->addDirectoryToWhitelist($srcDir);
// Build and return test suite
return new PHPUnit_Extensions_PhptTestSuite(__DIR__);
}
示例13: get_reports
public function get_reports()
{
$this->reports = get_transient('json_testhelper_coverage');
if (empty($this->reports)) {
return new WP_Error('json_testhelper_no_report', __('No report data available', 'json_testhelper'), array('status' => 400));
}
if (!class_exists('PHP_CodeCoverage')) {
return new WP_Error('json_testhelper_missing_codecoverage', __('The CodeCoverage classes are missing', 'json_testhelper'), array('status' => 500));
}
$master = new PHP_CodeCoverage();
foreach ($this->reports as $report) {
$master->merge($report);
}
// Clean up
delete_transient('json_testhelper_coverage');
$data = array('reports' => count($this->reports), 'data' => serialize($master));
return $data;
}
示例14: renderCodeCoverage
/**
* Renders and outputs the code coverage report.
*
* @return void
*/
protected function renderCodeCoverage()
{
$this->coverage->stop();
$codeCoverageDirectory = PATH_site . 'typo3temp/codecoverage/';
if (!is_readable($codeCoverageDirectory) && !is_dir($codeCoverageDirectory)) {
t3lib_div::mkdir($codeCoverageDirectory);
}
$coverageReport = new PHP_CodeCoverage_Report_HTML();
$coverageReport->process($this->coverage, $codeCoverageDirectory);
$this->outputService->output('<p><a target="_blank" href="../typo3temp/codecoverage/index.html">' . 'Click here to access the Code Coverage report</a></p>' . '<p>Memory peak usage: ' . t3lib_div::formatSize(memory_get_peak_usage()) . 'B<p/>');
}
示例15: testSimpleMerge
public function testSimpleMerge()
{
$firstFile = PARATEST_ROOT . '/src/ParaTest/Logging/LogInterpreter.php';
$secondFile = PARATEST_ROOT . '/src/ParaTest/Logging/MetaProvider.php';
$coverage1 = new \PHP_CodeCoverage();
$coverage1->append(array($firstFile => array(35 => 1), $secondFile => array(34 => 1)), 'Test1');
$coverage2 = new \PHP_CodeCoverage();
$coverage2->append(array($firstFile => array(35 => 1, 36 => 1)), 'Test2');
$merger = new CoverageMerger();
$merger->addCoverage($coverage1);
$merger->addCoverage($coverage2);
$coverage = $merger->getCoverage();
$data = $coverage->getData();
$this->assertEquals(2, count($data[$firstFile][35]));
$this->assertEquals('Test1', $data[$firstFile][35][0]);
$this->assertEquals('Test2', $data[$firstFile][35][1]);
$this->assertEquals(1, count($data[$firstFile][36]));
$this->assertEquals('Test2', $data[$firstFile][36][0]);
$this->assertEquals(1, count($data[$secondFile][34]));
$this->assertEquals('Test1', $data[$secondFile][34][0]);
}