Beispiel #1
0
use Kahlan\Spec\Fixture\Reporter\Coverage\ExtraEmptyLine;
use RuntimeException;
describe("Coveralls", function () {
    beforeEach(function () {
        if (!extension_loaded('xdebug') && PHP_SAPI !== 'phpdbg') {
            skipIf(true);
        }
        $this->driver = PHP_SAPI !== 'phpdbg' ? new Xdebug() : new Phpdbg();
    });
    describe("::export()", function () {
        it("exports the coverage of a file with no extra end line", function () {
            $path = 'spec' . DS . 'Fixture' . DS . 'Reporter' . DS . 'Coverage' . DS . 'NoEmptyLine.php';
            $collector = new Collector(['driver' => $this->driver, 'path' => $path]);
            $code = new NoEmptyLine();
            $collector->start();
            $code->shallNotPass();
            $collector->stop();
            $json = Coveralls::export(['collector' => $collector, 'service_name' => 'kahlan-ci', 'service_job_id' => '123', 'repo_token' => 'ABC']);
            $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(15);
            expect(array_filter($coverage['coverage']))->toHaveLength(2);
            expect(array_filter($coverage['coverage'], function ($value) {
                return $value === 0;
            }))->toHaveLength(2);
Beispiel #2
0
         skipIf(true);
     }
     $this->driver = PHP_SAPI !== 'phpdbg' ? new Xdebug() : new Phpdbg();
 });
 beforeEach(function () {
     $this->path = ['spec/Fixture/Reporter/Coverage/GlobalFunctions.php', 'spec/Fixture/Reporter/Coverage/Functions.php', 'spec/Fixture/Reporter/Coverage/ExtraEmptyLine.php', 'spec/Fixture/Reporter/Coverage/NoEmptyLine.php'];
     $driver = PHP_SAPI !== 'phpdbg' ? new Xdebug() : new Phpdbg();
     $this->collector = new Collector(['driver' => $this->driver, 'path' => $this->path]);
 });
 describe("->metrics()", function () {
     it("returns the global metrics", function () {
         $empty = new ExtraEmptyLine();
         $noEmpty = new NoEmptyLine();
         $this->collector->start();
         $empty->shallNotPass();
         $noEmpty->shallNotPass();
         \shallNotPass();
         \Kahlan\Spec\Fixture\Reporter\Coverage\shallNotPass();
         $this->collector->stop();
         $metrics = $this->collector->metrics();
         $actual = $metrics->data();
         $files = $actual['files'];
         unset($actual['files']);
         expect($actual)->toBe(['loc' => 55, 'nlloc' => 39, 'lloc' => 16, 'cloc' => 8, 'coverage' => 8, 'methods' => 4, 'cmethods' => 4, 'percent' => 50]);
         foreach ($this->path as $path) {
             $path = realpath($path);
             expect(isset($files[$path]))->toBe(true);
         }
     });
     it("returns class metrics", function () {
         $code = new ExtraEmptyLine();