예제 #1
0
         }))->toHaveLength(2);
         expect(array_filter($coverage['coverage'], function ($value) {
             return $value === null;
         }))->toHaveLength(12);
     });
 });
 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));
예제 #2
0
    });
    describe("->stop()", function () {
        it("does nothing if not the collector has not been started", function () {
            expect($this->collector->stop())->toBe(false);
        });
        it("does nothing if not the collector has not been started", function () {
            $this->parent->start();
            $this->child->start();
            expect($this->parent->stop())->toBe(false);
            // Required to leave Kahlan in stable state when runned with some coverage reporting.
            $this->child->stop();
            $this->parent->stop();
        });
    });
    describe("->metrics()", function () {
        it("returns the metrics", function () {
            $code = new CodeCoverage();
            $this->collector->start();
            $code->shallPass();
            $this->collector->stop();
            $metrics = $this->collector->metrics();
            expect($metrics)->toBeAnInstanceOf('Kahlan\\Reporter\\Coverage\\Metrics');
        });
    });
    describe("->realpath()", function () {
        it("supports special chars", function () {
            $collector = new Collector(['driver' => $this->driver, 'path' => $this->path, 'prefix' => '/a/weird~cache/path']);
            expect($collector->realpath('/a/weird~cache/path/home/user/project/src/filename.php'))->toBe('/home/user/project/src/filename.php');
        });
    });
});
예제 #3
0
     expect($actual)->toBe(['loc' => 8, 'nlloc' => 4, 'lloc' => 4, 'cloc' => 2, 'coverage' => 2, 'methods' => 1, 'cmethods' => 1, 'line' => ['start' => 3, 'stop' => 11], 'percent' => 50]);
     $path = realpath('spec/Fixture/Reporter/Coverage/Functions.php');
     expect(isset($files[$path]))->toBe(true);
 });
 it("returns empty for unknown metric", function () {
     $code = new ExtraEmptyLine();
     $this->collector->start();
     $code->shallNotPass();
     $this->collector->stop();
     $metrics = $this->collector->metrics();
     $actual = $metrics->get('some\\unknown\\name\\space');
     expect($actual)->toBe(null);
 });
 it("ignores interfaces metrics", function () {
     $path = ['spec/Fixture/Reporter/Coverage/ImplementsCoverage.php', 'spec/Fixture/Reporter/Coverage/ImplementsCoverageInterface.php'];
     $collector = new Collector(['driver' => $this->driver, 'path' => $path]);
     $code = new ImplementsCoverage();
     $collector->start();
     $code->foo();
     $collector->stop();
     $metrics = $collector->metrics();
     $actual = $metrics->get('Kahlan\\Spec\\Fixture\\Reporter\\Coverage\\ImplementsCoverage')->data();
     $files = $actual['files'];
     unset($actual['files']);
     expect($actual)->toBe(['loc' => 6, 'nlloc' => 5, 'lloc' => 1, 'cloc' => 1, 'coverage' => 1, 'methods' => 1, 'cmethods' => 1, 'percent' => 100]);
     $path = realpath('spec/Fixture/Reporter/Coverage/ImplementsCoverage.php');
     expect(isset($files[$path]))->toBe(true);
     expect($metrics->get('Kahlan\\Spec\\Fixture\\Reporter\\Coverage\\ImplementsCoverageInterface'))->toBe(null);
     expect($collector->export())->toBe([str_replace('/', DS, 'spec/Fixture/Reporter/Coverage/ImplementsCoverage.php') => [7 => 1]]);
 });
 describe("->children()", function () {
예제 #4
0
     expect($actual)->toBe(['loc' => 8, 'nlloc' => 4, 'lloc' => 4, 'cloc' => 2, 'coverage' => 2, 'methods' => 1, 'cmethods' => 1, 'line' => ['start' => 5, 'stop' => 13], 'percent' => 50]);
     $path = realpath('spec/fixture/reporter/coverage/ExtraEmptyLine.php');
     expect(isset($files[$path]))->toBe(true);
 });
 it("return empty on unknown metric", function () {
     $code = new ExtraEmptyLine();
     $this->collector->start();
     $code->shallNotPass();
     $this->collector->stop();
     $metrics = $this->collector->metrics();
     $actual = $metrics->get('some\\unknown\\name\\space');
     expect($actual)->toBe(null);
 });
 it("doesn't store interfaces in metrics", function () {
     $path = ['spec/fixture/reporter/coverage/ImplementsCoverage.php', 'spec/fixture/reporter/coverage/ImplementsCoverageInterface.php'];
     $collector = new Collector(['driver' => new Xdebug(), 'path' => $path]);
     $code = new ImplementsCoverage();
     $collector->start();
     $code->foo();
     $collector->stop();
     $metrics = $collector->metrics();
     $actual = $metrics->get()->data();
     $files = $actual['files'];
     unset($actual['files']);
     expect($actual)->toBe(['loc' => 10, 'nlloc' => 9, 'lloc' => 1, 'cloc' => 1, 'coverage' => 1, 'methods' => 1, 'cmethods' => 1, 'percent' => 100]);
     $path = realpath('spec/fixture/reporter/coverage/ImplementsCoverage.php');
     expect(isset($files[$path]))->toBe(true);
 });
 describe("->childs()", function () {
     beforeEach(function () {
         $code = new ExtraEmptyLine();