<?php use filter\Filter; use kahlan\reporter\Coverage; use kahlan\reporter\coverage\exporter\CodeClimate; $args = $this->args(); $args->argument('coverage', 'default', 3); Filter::register('kahlan.coverage-exporter', function ($chain) { $reporter = $this->reporters()->get('coverage'); if (!$reporter || !getenv('CODECLIMATE_REPO_TOKEN')) { return $chain->next(); } CodeClimate::write(['collector' => $reporter, 'file' => 'codeclimate.json', 'branch' => getenv('TRAVIS_BRANCH') ?: null, 'repo_token' => getenv('CODECLIMATE_REPO_TOKEN')]); return $chain->next(); }); Filter::apply($this, 'reporting', 'kahlan.coverage-exporter'); require_once __DIR__ . '/spec/init.php';
<?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');
}); 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/fixture/reporter/coverage/ExtraEmptyLine.php'; $collector = new Collector(['driver' => new Xdebug(), 'path' => $path]); $code = new ExtraEmptyLine(); $collector->start(); $code->shallNotPass(); $collector->stop(); $success = CodeClimate::write(['collector' => $collector, 'file' => $this->output, 'environment' => ['pwd' => '/home/crysalead/kahlan'], 'repo_token' => 'ABC']); $json = file_get_contents($this->output); expect($success)->toBe(strlen($json)); $actual = json_decode($json, true); $coverage = $actual['source_files'][0]; expect($coverage['name'])->toBe($path); $coverage = json_decode($coverage['coverage']); expect($coverage)->toHaveLength(16); }); it("throws an exception when no file is set", function () { expect(function () { CodeClimate::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; $commandLine = $this->commandLine(); $commandLine->option('coverage', 'default', 3); Filter::register('kahlan.coverage', function ($chain) { if (!extension_loaded('xdebug')) { return; } $reporters = $this->reporters(); $coverage = new Coverage(['verbosity' => $this->commandLine()->get('coverage'), 'driver' => new Xdebug(), 'path' => $this->commandLine()->get('src'), 'exclude' => ['src/init.php', 'src/functions.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', 'src/Reporter/Json.php', 'src/Reporter/Tap.php'], 'colors' => !$this->commandLine()->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' => '422174e17459424c0dc0dfdd720eb17324b283a204b093e85ba21400f1414536']); return $chain->next(); }); Filter::apply($this, 'reporting', 'kahlan.coverage-exporter');