/** * @param \PHP_CodeCoverage|CodeCoverage $coverage */ private function addCoverage($coverage) { if (null === $this->coverage) { $this->coverage = $coverage; } else { $this->coverage->merge($coverage); } }
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; }
/** * @covers PHP_CodeCoverage::getData * @covers PHP_CodeCoverage::merge */ public function testMerge2() { $driver = $this->getMockBuilder('PHP_CodeCoverage_Driver')->setConstructorArgs(array(new PHP_CodeCoverage_Filter(), new PHP_CodeCoverage_Parser()))->getMockForAbstractClass(); $coverage = new PHP_CodeCoverage($driver, new PHP_CodeCoverage_Filter()); $coverage->merge($this->getCoverageForBankAccount()); $this->assertEquals($this->getExpectedDataArrayForBankAccount(), $coverage->getData()); }
/** * @covers PHP_CodeCoverage::merge */ public function testMerge() { $coverage = new PHP_CodeCoverage($this->setUpXdebugStubForBankAccount(), new PHP_CodeCoverage_Filter()); $coverage->merge($this->getCoverageForBankAccount()); $this->assertEquals($this->getCoverageForBankAccount()->getSummary(), $coverage->getSummary()); }
/** * @covers PHP_CodeCoverage::getData * @covers PHP_CodeCoverage::merge */ public function testMerge2() { $coverage = new PHP_CodeCoverage($this->getMock('PHP_CodeCoverage_Driver_Xdebug'), new PHP_CodeCoverage_Filter()); $coverage->merge($this->getCoverageForBankAccount()); $this->assertEquals($this->getExpectedDataArrayForBankAccount(), $coverage->getData()); }
/** * Main method. */ public static function main() { $input = new ezcConsoleInput(); $input->registerOption(new ezcConsoleOption('', 'clover', ezcConsoleInput::TYPE_STRING)); $input->registerOption(new ezcConsoleOption('', 'html', ezcConsoleInput::TYPE_STRING)); $input->registerOption(new ezcConsoleOption('', 'blacklist', ezcConsoleInput::TYPE_STRING, array(), TRUE)); $input->registerOption(new ezcConsoleOption('', 'whitelist', ezcConsoleInput::TYPE_STRING, array(), TRUE)); $input->registerOption(new ezcConsoleOption('', 'merge', ezcConsoleInput::TYPE_NONE, FALSE)); $input->registerOption(new ezcConsoleOption('h', 'help', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); $input->registerOption(new ezcConsoleOption('v', 'version', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); try { $input->process(); } catch (ezcConsoleOptionException $e) { print $e->getMessage() . "\n"; exit(1); } if ($input->getOption('help')->value) { self::showHelp(); exit(0); } else { if ($input->getOption('version')->value) { self::printVersionString(); exit(0); } } $arguments = $input->getArguments(); $clover = $input->getOption('clover')->value; $html = $input->getOption('html')->value; $blacklist = $input->getOption('blacklist')->value; $whitelist = $input->getOption('whitelist')->value; $merge = $input->getOption('merge')->value; if (count($arguments) == 1) { self::printVersionString(); $coverage = new PHP_CodeCoverage(); $filter = $coverage->filter(); if (empty($whitelist)) { $c = new ReflectionClass('ezcBase'); $filter->addDirectoryToBlacklist(dirname($c->getFileName())); $c = new ReflectionClass('ezcConsoleInput'); $filter->addDirectoryToBlacklist(dirname($c->getFileName())); foreach ($blacklist as $item) { if (is_dir($item)) { $filter->addDirectoryToBlacklist($item); } else { if (is_file($item)) { $filter->addFileToBlacklist($item); } } } } else { foreach ($whitelist as $item) { if (is_dir($item)) { $filter->addDirectoryToWhitelist($item); } else { if (is_file($item)) { $filter->addFileToWhitelist($item); } } } } if (!$merge) { $coverage->start('phpcov'); require $arguments[0]; $coverage->stop(); } else { $facade = new File_Iterator_Facade(); $result = $facade->getFilesAsArray($arguments[0], '.cov'); foreach ($files as $file) { $coverage->merge(unserialize(file_get_contents($file))); } } if ($clover) { $writer = new PHP_CodeCoverage_Report_Clover(); $writer->process($coverage, $clover); } if ($html) { $writer = new PHP_CodeCoverage_Report_HTML(); $writer->process($coverage, $html); } } else { self::showHelp(); exit(1); } }
/** * @param \PHP_CodeCoverage $coverage */ private function mergeCoverage(\PHP_CodeCoverage $coverage) { $this->coverage->merge($coverage); }
/** * Main method. */ public static function main() { $input = new ezcConsoleInput(); $input->registerOption(new ezcConsoleOption('', 'clover', ezcConsoleInput::TYPE_STRING)); $input->registerOption(new ezcConsoleOption('', 'html', ezcConsoleInput::TYPE_STRING)); $input->registerOption(new ezcConsoleOption('', 'php', ezcConsoleInput::TYPE_STRING)); $input->registerOption(new ezcConsoleOption('', 'text', ezcConsoleInput::TYPE_STRING)); $input->registerOption(new ezcConsoleOption('', 'blacklist', ezcConsoleInput::TYPE_STRING, array(), TRUE)); $input->registerOption(new ezcConsoleOption('', 'whitelist', ezcConsoleInput::TYPE_STRING, array(), TRUE)); $input->registerOption(new ezcConsoleOption('', 'merge', ezcConsoleInput::TYPE_NONE, FALSE)); $input->registerOption(new ezcConsoleOption('', 'add-uncovered', ezcConsoleInput::TYPE_NONE, FALSE)); $input->registerOption(new ezcConsoleOption('', 'process-uncovered', ezcConsoleInput::TYPE_NONE, FALSE)); $input->registerOption(new ezcConsoleOption('h', 'help', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); $input->registerOption(new ezcConsoleOption('v', 'version', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE)); try { $input->process(); } catch (ezcConsoleOptionException $e) { print $e->getMessage() . "\n"; exit(1); } if ($input->getOption('help')->value) { self::showHelp(); exit(0); } else { if ($input->getOption('version')->value) { self::printVersionString(); exit(0); } } $arguments = $input->getArguments(); $clover = $input->getOption('clover')->value; $html = $input->getOption('html')->value; $php = $input->getOption('php')->value; $text = $input->getOption('text')->value; $blacklist = $input->getOption('blacklist')->value; $whitelist = $input->getOption('whitelist')->value; $addUncovered = $input->getOption('add-uncovered')->value; $processUncovered = $input->getOption('process-uncovered')->value; $merge = $input->getOption('merge')->value; if (count($arguments) == 1) { self::printVersionString(); $coverage = new PHP_CodeCoverage(); $filter = $coverage->filter(); if (empty($whitelist)) { $c = new ReflectionClass('ezcBase'); $filter->addDirectoryToBlacklist(dirname($c->getFileName())); $c = new ReflectionClass('ezcConsoleInput'); $filter->addDirectoryToBlacklist(dirname($c->getFileName())); foreach ($blacklist as $item) { if (is_dir($item)) { $filter->addDirectoryToBlacklist($item); } else { if (is_file($item)) { $filter->addFileToBlacklist($item); } } } } else { $coverage->setAddUncoveredFilesFromWhitelist($addUncovered); $coverage->setProcessUncoveredFilesFromWhitelist($processUncovered); foreach ($whitelist as $item) { if (is_dir($item)) { $filter->addDirectoryToWhitelist($item); } else { if (is_file($item)) { $filter->addFileToWhitelist($item); } } } } if (!$merge) { $coverage->start('phpcov'); require $arguments[0]; $coverage->stop(); } else { $finder = new Symfony\Component\Finder\Finder(); $finder->in($arguments[0])->name('*.cov'); foreach ($finder as $file) { $coverage->merge(unserialize(file_get_contents($file->getRealpath()))); } } if ($clover) { $writer = new PHP_CodeCoverage_Report_Clover(); $writer->process($coverage, $clover); } if ($html) { $writer = new PHP_CodeCoverage_Report_HTML(); $writer->process($coverage, $html); } if ($php) { $writer = new PHP_CodeCoverage_Report_PHP(); $writer->process($coverage, $php); } if ($text) { $writer = new PHP_CodeCoverage_Report_Text(); $writer->process($coverage, $text); } } else { self::showHelp(); exit(1); } }