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

CoverageCommandTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 0
loc 108
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testExecutionWithTextToFile() 0 21 1
A testExecutionWithTextToConsole() 0 15 1
A testExecutionWithTextSummaryToFile() 0 21 1
A testExecutionWithTextSummaryToConsole() 0 15 1
A getTempCoverageFilename() 0 8 1
A createCommandTester() 0 9 1
A prepareArguments() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tests\Functional\Command;
6
7
use Paraunit\Command\CoverageCommand;
8
use Paraunit\Configuration\CoverageConfiguration;
9
use Symfony\Component\Console\Application;
10
use Symfony\Component\Console\Tester\CommandTester;
11
use Tests\BaseTestCase;
12
13
class CoverageCommandTest extends BaseTestCase
14
{
15
    private const COMMAND_NAME = 'coverage';
16
17
    public function testExecutionWithTextToFile(): void
18
    {
19
        $coverageFileName = $this->getTempCoverageFilename();
20
        $commandTester = $this->createCommandTester();
21
22
        $arguments = $this->prepareArguments([
23
            '--text' => $coverageFileName,
24
        ]);
25
        $exitCode = $commandTester->execute($arguments);
26
27
        $output = $commandTester->getDisplay();
28
        $this->assertNotContains('NO TESTS EXECUTED', $output);
29
        $this->assertNotContains('Coverage Report', $output);
30
        $this->assertNotContains('StubbedParaunitProcess', $output);
31
        $this->assertEquals(0, $exitCode);
32
        $this->assertFileExists($coverageFileName);
33
        $fileContent = file_get_contents($coverageFileName);
34
        unlink($coverageFileName);
35
        $this->assertContains('Coverage Report', $fileContent);
36
        $this->assertContains('StubbedParaunitProcess', $fileContent);
37
    }
38
39
    public function testExecutionWithTextToConsole(): void
40
    {
41
        $commandTester = $this->createCommandTester();
42
43
        $arguments = $this->prepareArguments([
44
            '--text' => null,
45
        ]);
46
        $exitCode = $commandTester->execute($arguments);
47
48
        $output = $commandTester->getDisplay();
49
        $this->assertNotContains('NO TESTS EXECUTED', $output);
50
        $this->assertContains('Coverage Report', $output);
51
        $this->assertContains('StubbedParaunitProcess', $output);
52
        $this->assertEquals(0, $exitCode);
53
    }
54
55
    public function testExecutionWithTextSummaryToFile(): void
56
    {
57
        $coverageFileName = $this->getTempCoverageFilename();
58
        $commandTester = $this->createCommandTester();
59
60
        $arguments = $this->prepareArguments([
61
            '--text-summary' => $coverageFileName,
62
        ]);
63
        $exitCode = $commandTester->execute($arguments);
64
65
        $output = $commandTester->getDisplay();
66
        $this->assertNotContains('NO TESTS EXECUTED', $output);
67
        $this->assertNotContains('Coverage Report', $output);
68
        $this->assertNotContains('StubbedParaunitProcess', $output);
69
        $this->assertEquals(0, $exitCode);
70
        $this->assertFileExists($coverageFileName);
71
        $fileContent = file_get_contents($coverageFileName);
72
        unlink($coverageFileName);
73
        $this->assertContains('Coverage Report', $fileContent);
74
        $this->assertNotContains('StubbedParaunitProcess', $fileContent);
75
    }
76
77
    public function testExecutionWithTextSummaryToConsole(): void
78
    {
79
        $commandTester = $this->createCommandTester();
80
81
        $arguments = $this->prepareArguments([
82
            '--text-summary' => null,
83
        ]);
84
        $exitCode = $commandTester->execute($arguments);
85
86
        $output = $commandTester->getDisplay();
87
        $this->assertNotContains('NO TESTS EXECUTED', $output);
88
        $this->assertContains('Coverage Report', $output);
89
        $this->assertNotContains('StubbedParaunitProcess', $output);
90
        $this->assertEquals(0, $exitCode);
91
    }
92
93
    private function getTempCoverageFilename(): string
94
    {
95
        /** @var string $filename */
96
        $filename = tempnam(sys_get_temp_dir(), 'coverage.txt');
97
        $this->assertInternalType('string', $filename);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
98
99
        return $filename;
100
    }
101
102
    private function createCommandTester(): CommandTester
103
    {
104
        $application = new Application();
105
        $application->add(new CoverageCommand(new CoverageConfiguration()));
106
107
        $command = $application->find(self::COMMAND_NAME);
108
109
        return new CommandTester($command);
110
    }
111
112
    private function prepareArguments(array $additionalArguments = []): array
113
    {
114
        return array_merge([
115
            'command' => self::COMMAND_NAME,
116
            '--configuration' => $this->getConfigForStubs(),
117
            'stringFilter' => 'green',
118
        ], $additionalArguments);
119
    }
120
}
121