|
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() |
|
|
|
|
|
|
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() |
|
|
|
|
|
|
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
|
|
|
|
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.