Test Failed
Pull Request — master (#132)
by Alessandro
03:15
created

CoveragePrinterTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 36.36 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 20
loc 55
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testOnEngineBeforeStartWithPHPDBGEngine() 10 10 1
A testOnEngineBeforeStartWithxDebugEngine() 10 10 1
A testOnEngineBeforeStartWithWarningForBothEnginesEnabled() 0 12 1
A mockPhpdbgBin() 0 8 1
A mockXdebugLoaded() 0 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tests\Unit\Printer;
6
7
use Paraunit\Configuration\PHPDbgBinFile;
8
use Paraunit\Printer\CoveragePrinter;
9
use Paraunit\Proxy\XDebugProxy;
10
use Tests\BaseUnitTestCase;
11
use Tests\Stub\UnformattedOutputStub;
12
13
/**
14
 * Class CoveragePrinterTest
15
 * @package Tests\Unit\Printer
16
 */
17
class CoveragePrinterTest extends BaseUnitTestCase
18
{
19 View Code Duplication
    public function testOnEngineBeforeStartWithPHPDBGEngine()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
    {
21
        $output = new UnformattedOutputStub();
22
23
        $printer = new CoveragePrinter($this->mockPhpdbgBin(true), $this->mockXdebugLoaded(false), $output);
24
25
        $printer->onEngineBeforeStart();
26
27
        $this->assertContains('Coverage driver in use: PHPDBG', $output->getOutput());
28
    }
29
30 View Code Duplication
    public function testOnEngineBeforeStartWithxDebugEngine()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32
        $output = new UnformattedOutputStub();
33
34
        $printer = new CoveragePrinter($this->mockPhpdbgBin(false), $this->mockXdebugLoaded(true), $output);
35
36
        $printer->onEngineBeforeStart();
37
38
        $this->assertContains('Coverage driver in use: xDebug', $output->getOutput());
39
    }
40
41
    public function testOnEngineBeforeStartWithWarningForBothEnginesEnabled()
42
    {
43
        $output = new UnformattedOutputStub();
44
45
        $printer = new CoveragePrinter($this->mockPhpdbgBin(true), $this->mockXdebugLoaded(true), $output);
46
47
        $printer->onEngineBeforeStart();
48
49
        $this->assertContains('WARNING', $output->getOutput());
50
        $this->assertContains('both driver', $output->getOutput());
51
        $this->assertNotContains('xDebug', $output->getOutput());
52
    }
53
54
    private function mockPhpdbgBin(bool $shouldReturn): PHPDbgBinFile
55
    {
56
        $phpdbgBin = $this->prophesize(PHPDbgBinFile::class);
57
        $phpdbgBin->isAvailable()
58
            ->willReturn($shouldReturn);
59
60
        return $phpdbgBin->reveal();
61
    }
62
63
    private function mockXdebugLoaded(bool $shouldReturn): XDebugProxy
64
    {
65
        $xdebug = $this->prophesize(XDebugProxy::class);
66
        $xdebug->isLoaded()
67
            ->willReturn($shouldReturn);
68
69
        return $xdebug->reveal();
70
    }
71
}
72