}); 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 () { Coveralls::write([]); })->toThrow(new RuntimeException("Missing file name")); }); }); });
<?php use Kahlan\Filter\Filter; use Kahlan\Reporter\Coverage; use Kahlan\Reporter\Coverage\Driver\Xdebug; use Kahlan\Reporter\Coverage\Exporter\Coveralls; use Kahlan\Reporter\Coverage\Exporter\CodeClimate; $args = $this->args(); $args->argument('coverage', 'default', 3); Filter::register('kahlan.coverage', function ($chain) { if (!extension_loaded('xdebug')) { return; } $reporters = $this->reporters(); $coverage = new Coverage(['verbosity' => $this->args()->get('coverage'), 'driver' => new Xdebug(), 'path' => $this->args()->get('src'), 'exclude' => ['src/init.php', 'src/Cli/Kahlan.php', 'src/Reporter/Coverage/Collector.php', 'src/Reporter/Coverage/Driver/Xdebug.php', 'src/Reporter/Coverage/Driver/HHVM.php', 'src/Reporter/Coverage/Driver/Phpdbg.php', 'src/Reporter/Dot.php', 'src/Reporter/Bar.php', 'src/Reporter/Verbose.php', 'src/Reporter/Terminal.php', 'src/Reporter/Reporter.php', 'src/Reporter/Coverage.php'], 'colors' => !$this->args()->get('no-colors')]); $reporters->add('coverage', $coverage); }); Filter::apply($this, 'coverage', 'kahlan.coverage'); Filter::register('kahlan.coverage-exporter', function ($chain) { $reporter = $this->reporters()->get('coverage'); if (!$reporter) { return; } Coveralls::write(['collector' => $reporter, 'file' => 'coveralls.json', 'service_name' => 'travis-ci', 'service_job_id' => getenv('TRAVIS_JOB_ID') ?: null]); CodeClimate::write(['collector' => $reporter, 'file' => 'codeclimate.json', 'branch' => getenv('TRAVIS_BRANCH') ?: null, 'repo_token' => 'a4b5637db5629f60a5d3fc1a070b2339479ff8989c6491dfc6a19cada5e4ffaa']); return $chain->next(); }); Filter::apply($this, 'reporting', 'kahlan.coverage-exporter');