|
8 | 8 | use ReflectionClass;
|
9 | 9 | use ReflectionException;
|
10 | 10 | use Throwable;
|
| 11 | +use function file_get_contents; |
11 | 12 |
|
12 | 13 | class BadgeComposerTest extends TestCase
|
13 | 14 | {
|
14 | 15 | private BadgeComposer $badgeComposer;
|
15 | 16 |
|
16 | 17 | private string $inputFile = __DIR__ . "/test-input1.xml";
|
17 | 18 | private string $inputFile2 = __DIR__ . "/test-input2.xml";
|
18 |
| - private string $outputFile = "output.svg"; |
| 19 | + private string $outputFile = __DIR__ . "/../badges/output.svg"; |
19 | 20 | private string $coverageName = "unit";
|
20 | 21 |
|
21 | 22 | /**
|
@@ -97,4 +98,38 @@ public function testProcessMultipleCloverFilesAndCalculateTheCoverage(): void
|
97 | 98 | $this->assertEquals(83, $this->badgeComposer->getTotalCoverage());
|
98 | 99 | }
|
99 | 100 |
|
| 101 | + /** |
| 102 | + * @throws ReflectionException |
| 103 | + */ |
| 104 | + public function testItThrowsExceptionWhenFileProcessingFails(): void |
| 105 | + { |
| 106 | + $this->expectException(Throwable::class); |
| 107 | + $this->expectExceptionMessage('Error reading file: invalid_file.xml'); |
| 108 | + |
| 109 | + $this->processFile('invalid_file.xml'); |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * @throws ReflectionException |
| 114 | + */ |
| 115 | + public function finalizeCoverage() |
| 116 | + { |
| 117 | + $method = (new ReflectionClass($this->badgeComposer))->getMethod('finalizeCoverage'); |
| 118 | + |
| 119 | + return $method->invoke($this->badgeComposer); |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * @throws ReflectionException |
| 124 | + */ |
| 125 | + public function testFinalizeCoverageCalculatesAverageCoverage(): void |
| 126 | + { |
| 127 | + $this->finalizeCoverage(); |
| 128 | + |
| 129 | + $outputFileContent = file_get_contents(__DIR__ . "/../badges/output.svg"); |
| 130 | + $this->assertStringContainsString('#e05d44', $outputFileContent); |
| 131 | + |
| 132 | + $this->assertStringContainsString('unit', $outputFileContent); |
| 133 | + } |
| 134 | + |
100 | 135 | }
|
0 commit comments