});
});
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 . 'ExtraEmptyLine.php';
$collector = new Collector(['driver' => $this->driver, 'path' => $path]);
$code = new ExtraEmptyLine();
$collector->start();
$code->shallNotPass();
$collector->stop();
$success = Coveralls::write(['collector' => $collector, 'file' => $this->output, 'service_name' => 'kahlan-ci', 'service_job_id' => '123', 'repo_token' => 'ABC']);
expect($success)->toBe(585);
$json = file_get_contents($this->output);
$actual = json_decode($json, true);
unset($actual['run_at']);
expect($actual['service_name'])->toBe('kahlan-ci');
expect($actual['service_job_id'])->toBe('123');
expect($actual['repo_token'])->toBe('ABC');
$coverage = $actual['source_files'][0];
expect($coverage['name'])->toBe($path);
expect($coverage['source'])->toBe(file_get_contents($path));
expect($coverage['coverage'])->toHaveLength(16);
});
it("throws an exception no file is set", function () {
expect(function () {