/** * @param PHP_CodeCoverage_Report_Node_Directory $root * @param array $items * @param array $tests * @param boolean $cacheTokens */ protected function addItems(PHP_CodeCoverage_Report_Node_Directory $root, array $items, array $tests, $cacheTokens) { foreach ($items as $key => $value) { if (substr($key, -2) == '/f') { $key = substr($key, 0, -2); $root->addFile($key, $value, $tests, $cacheTokens); } else { $child = $root->addDirectory($key); $this->addItems($child, $value, $tests, $cacheTokens); } } }
/** * @param PHP_CodeCoverage_Report_Node_Directory $root * @param array $items * @param array $tests * @param boolean $cacheTokens */ private function addItems(PHP_CodeCoverage_Report_Node_Directory $root, array $items, array $tests, $cacheTokens) { foreach ($items as $key => $value) { if (substr($key, -2) == '/f') { $key = substr($key, 0, -2); if (file_exists($root->getPath() . DIRECTORY_SEPARATOR . $key)) { $root->addFile($key, $value, $tests, $cacheTokens); } } else { $child = $root->addDirectory($key); $this->addItems($child, $value, $tests, $cacheTokens); } } }
public function testProcess() { vfsStream::setup('tmp'); $target = vfsStream::url('tmp'); file_put_contents($target . '/file', "test\n"); $report = new \PHP_CodeCoverage_Report_Node_Directory($target); $report->addFile('file', array('class' => array(1 => 1)), array(), false); $coverage = $this->getMock('PHP_CodeCoverage'); $coverage->expects($this->once())->method('getReport')->will($this->returnValue($report)); $report = new Html(array('target' => $target)); try { $result = $report->process($coverage); } catch (\Exception $e) { // workaround until https://github.com/mikey179/vfsStream/pull/67 is merged if ($e->getMessage() === 'Could not write to vfs://tmp/index.dashboard.html: /tmp/index.dashboard.html): failed to open stream: "org\\bovigo\\vfs\\vfsStreamWrapper::stream_open" call failed') { $this->markTestSkipped(); } else { $this->fail(); } } }