Kahlan\Reporter\Coverage\Exporter\CodeClimate::export PHP Method

export() public static method

Exports a coverage to a string.
public static export ( array $options ) : string
$options array The option array where the possible values are: -`'collector'` _object_ : The collector instance. -`'repo_token'` _string_ : The Coveralls repo token. -`'head'` _string_ : The HEAD hash. -`'branch'` _string_ : The branch name. -`'committed_at'` _integer_: The committed timestamp. -`'environment'` _array_ : The Environment. Possible values are: -`'pwd'` _string_ : The repo absolute path. -`'ci_service'` _string_ : The CI service name - `'name` _string_ : CI service name - `'build_identifier` _string_ : build identifier - `'build_url` _string_ : build url - `'branch` _string_ : branch name - `'commit_sha` _string_ : commit SHA - `'pull_request` _string_ : pull request id -`'run_at'` _integer_: The runned timestamp.
return string
    public static function export($options)
    {
        $defaults = ['collector' => null, 'head' => null, 'branch' => null, 'committed_at' => null, 'repo_token' => null, 'environment' => ['pwd' => getcwd()], 'ci_service' => [], 'run_at' => time()];
        $options += $defaults;
        return json_encode(['partial' => false, 'run_at' => $options['run_at'], 'repo_token' => $options['repo_token'], 'environment' => $options['environment'] + ['package_version' => '0.1.2'], 'git' => ['head' => $options['head'] ?: `git log -1 --pretty=format:'%H'`, 'branch' => $options['branch'] ?: trim(`git rev-parse --abbrev-ref HEAD`), 'committed_at' => $options['committed_at'] ?: `git log -1 --pretty=format:'%ct'`], 'ci_service' => $options['ci_service'], 'source_files' => static::_sourceFiles($options['collector'])]);
    }

Usage Example

Beispiel #1
0
         expect(array_filter($coverage))->toHaveLength(2);
         expect(array_filter($coverage, function ($value) {
             return $value === 0;
         }))->toHaveLength(2);
         expect(array_filter($coverage, function ($value) {
             return $value === null;
         }))->toHaveLength(11);
     });
     it("exports the coverage of a file with an extra line at the end", 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();
         $json = CodeClimate::export(['collector' => $collector, 'repo_token' => 'ABC', 'ci' => ['name' => 'kahlan-ci', 'build_identifier' => '123']]);
         $actual = json_decode($json, true);
         $coverage = $actual['source_files'][0];
         expect($coverage['name'])->toBe($path);
         $coverage = json_decode($coverage['coverage']);
         expect($coverage)->toHaveLength(16);
         expect(array_filter($coverage, function ($value) {
             return $value === 0;
         }))->toHaveLength(2);
         expect(array_filter($coverage, function ($value) {
             return $value === null;
         }))->toHaveLength(12);
     });
 });
 describe("::write()", function () {
     beforeEach(function () {