Skip to content

Commit 4e5feb7

Browse files
Refactor TestStatus to enumeration
1 parent 35cc5a6 commit 4e5feb7

8 files changed

Lines changed: 49 additions & 181 deletions

File tree

src/CodeCoverage.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
use SebastianBergmann\CodeCoverage\Test\Target\TargetCollectionValidator;
2525
use SebastianBergmann\CodeCoverage\Test\Target\ValidationResult;
2626
use SebastianBergmann\CodeCoverage\Test\TestSize\TestSize;
27-
use SebastianBergmann\CodeCoverage\Test\TestStatus\TestStatus;
2827

2928
/**
3029
* Provides collection functionality for PHP code coverage information.
@@ -190,7 +189,7 @@ public function append(RawCodeCoverageData $rawData, ?string $id = null, bool $a
190189
}
191190

192191
if ($status === null) {
193-
$status = TestStatus::unknown();
192+
$status = TestStatus::Unknown;
194193
}
195194

196195
if ($covers === null) {

src/TestStatus.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of phpunit/php-code-coverage.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace SebastianBergmann\CodeCoverage;
11+
12+
/**
13+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage
14+
*/
15+
enum TestStatus: string
16+
{
17+
public function isKnown(): bool
18+
{
19+
return $this !== self::Unknown;
20+
}
21+
22+
public function isUnknown(): bool
23+
{
24+
return $this === self::Unknown;
25+
}
26+
27+
public function isSuccess(): bool
28+
{
29+
return $this === self::Success;
30+
}
31+
32+
public function isFailure(): bool
33+
{
34+
return $this === self::Failure;
35+
}
36+
37+
public function asString(): string
38+
{
39+
return $this->value;
40+
}
41+
case Unknown = 'unknown';
42+
case Success = 'success';
43+
case Failure = 'failure';
44+
}

src/TestStatus/Failure.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/TestStatus/Known.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/TestStatus/Success.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/TestStatus/TestStatus.php

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/TestStatus/Unknown.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/tests/TestStatusTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@
1010
namespace SebastianBergmann\CodeCoverage\Test\TestStatus;
1111

1212
use PHPUnit\Framework\Attributes\CoversClass;
13-
use PHPUnit\Framework\Attributes\CoversClassesThatExtendClass;
1413
use PHPUnit\Framework\Attributes\Small;
1514
use PHPUnit\Framework\TestCase;
15+
use SebastianBergmann\CodeCoverage\TestStatus;
1616

1717
#[CoversClass(TestStatus::class)]
18-
#[CoversClassesThatExtendClass(TestStatus::class)]
1918
#[Small]
2019
final class TestStatusTest extends TestCase
2120
{
2221
public function testCanBeUnknown(): void
2322
{
24-
$status = TestStatus::unknown();
23+
$status = TestStatus::Unknown;
2524

2625
$this->assertTrue($status->isUnknown());
2726
$this->assertFalse($status->isKnown());
@@ -32,7 +31,7 @@ public function testCanBeUnknown(): void
3231

3332
public function testCanBeSuccess(): void
3433
{
35-
$status = TestStatus::success();
34+
$status = TestStatus::Success;
3635

3736
$this->assertFalse($status->isUnknown());
3837
$this->assertTrue($status->isKnown());
@@ -43,7 +42,7 @@ public function testCanBeSuccess(): void
4342

4443
public function testCanBeFailure(): void
4544
{
46-
$status = TestStatus::failure();
45+
$status = TestStatus::Failure;
4746

4847
$this->assertFalse($status->isUnknown());
4948
$this->assertTrue($status->isKnown());

0 commit comments

Comments
 (0)