/** * The default `'reporting'` filter. */ protected function _reporting() { return Filter::on($this, 'reporting', [], function ($chain) { $reporter = $this->reporters()->get('coverage'); if (!$reporter) { return; } if ($this->args()->exists('clover')) { Clover::write(['collector' => $reporter, 'file' => $this->args()->get('clover')]); } if ($this->args()->exists('istanbul')) { Istanbul::write(['collector' => $reporter, 'file' => $this->args()->get('istanbul')]); } if ($this->args()->exists('lcov')) { Lcov::write(['collector' => $reporter, 'file' => $this->args()->get('lcov')]); } }); }
describe("::write()", function () { beforeEach(function () { $this->output = tempnam("/tmp", "KAHLAN"); }); afterEach(function () { unlink($this->output); }); it("writes the coverage to a file", function () { $path = 'spec' . DS . 'Fixture' . DS . 'Reporter' . DS . 'Coverage' . DS . 'NoEmptyLine.php'; $collector = new Collector(['driver' => $this->driver, 'path' => $path]); $code = new NoEmptyLine(); $collector->start(); $code->shallNotPass(); $collector->stop(); $time = time(); $success = Istanbul::write(['collector' => $collector, 'file' => $this->output, 'base_path' => DS . 'home' . DS . 'crysalead' . DS . 'kahlan']); expect($success)->toBe(635); $json = file_get_contents($this->output); $ds = DS; $expected = <<<EOD {"\\/home\\/crysalead\\/kahlan\\/spec\\/Fixture\\/Reporter\\/Coverage\\/NoEmptyLine.php":{"path":"\\/home\\/crysalead\\/kahlan\\/spec\\/Fixture\\/Reporter\\/Coverage\\/NoEmptyLine.php","s":{"1":1,"2":0,"3":1,"4":0},"f":{"1":1},"b":[],"statementMap":{"1":{"start":{"line":8,"column":0},"end":{"line":8,"column":31}},"2":{"start":{"line":10,"column":0},"end":{"line":10,"column":34}},"3":{"start":{"line":12,"column":0},"end":{"line":12,"column":30}},"4":{"start":{"line":13,"column":0},"end":{"line":13,"column":30}}},"fnMap":{"1":{"name":"shallNotPass","line":6,"loc":{"start":{"line":6,"column":0},"end":{"line":14,"column":false}}}},"branchMap":[]}} EOD; expect($json)->toBe($expected); }); it("throws exception when no file is set", function () { expect(function () { Istanbul::write([]); })->toThrow(new RuntimeException('Missing file name')); }); }); });