Skip to content

Commit 646195f

Browse files
Refactor TestSize to enumeration
1 parent 4e5feb7 commit 646195f

13 files changed

Lines changed: 87 additions & 257 deletions

ChangeLog-14.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
1616
* In addition to the above, the `process()` method of `SebastianBergmann\CodeCoverage\Report\Xml\Facade` requires the result of `SebastianBergmann\CodeCoverage\CodeCoverage::getTests()`
1717
* The format of the file written by `SebastianBergmann\CodeCoverage\Serialization\Serializer` is incompatible with the format of the file that was written by `SebastianBergmann\CodeCoverage\Report\PHP` in the past
1818
* The `<build>` element and its children of the XML report generated by `SebastianBergmann\CodeCoverage\Report\Xml\Facade` require the optional arguments to be passed to the `process()` method
19+
* The `TestSize` and `TestStatus` value objects are now enumerations
1920

2021
### Removed
2122

phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ parameters:
5252
# Ignore errors caused by defensive programming
5353
- '#Call to function assert\(\) with true will always evaluate to true.#'
5454
- '#Call to method .* will always evaluate to true.#'
55-
- '#Call to method .* will always evaluate to false.#'
5655
- '#Instanceof between .* and .* will always evaluate to true.#'
5756
- '#SebastianBergmann\\CodeCoverage\\Node\\Iterator::current\(\) should be covariant with return type#'
5857

src/CodeCoverage.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use SebastianBergmann\CodeCoverage\Test\Target\TargetCollection;
2424
use SebastianBergmann\CodeCoverage\Test\Target\TargetCollectionValidator;
2525
use SebastianBergmann\CodeCoverage\Test\Target\ValidationResult;
26-
use SebastianBergmann\CodeCoverage\Test\TestSize\TestSize;
2726

2827
/**
2928
* Provides collection functionality for PHP code coverage information.
@@ -203,7 +202,7 @@ public function append(RawCodeCoverageData $rawData, ?string $id = null, bool $a
203202
$size = $this->currentSize;
204203

205204
if ($size === null) {
206-
$size = TestSize::unknown();
205+
$size = TestSize::Unknown;
207206
}
208207

209208
$this->cachedReport = null;

src/FilterProcessor.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use SebastianBergmann\CodeCoverage\Data\RawCodeCoverageData;
1818
use SebastianBergmann\CodeCoverage\StaticAnalysis\FileAnalyser;
1919
use SebastianBergmann\CodeCoverage\Test\Target\Mapper;
20-
use SebastianBergmann\CodeCoverage\Test\TestSize\TestSize;
2120

2221
/**
2322
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage

src/TestSize.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 TestSize: 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 isSmall(): bool
28+
{
29+
return $this === self::Small;
30+
}
31+
32+
public function isMedium(): bool
33+
{
34+
return $this === self::Medium;
35+
}
36+
37+
public function isLarge(): bool
38+
{
39+
return $this === self::Large;
40+
}
41+
42+
public function isGreaterThan(self $other): bool
43+
{
44+
return $this->order() > $other->order();
45+
}
46+
47+
public function asString(): string
48+
{
49+
return $this->value;
50+
}
51+
52+
private function order(): int
53+
{
54+
return match ($this) {
55+
self::Unknown => -1,
56+
self::Small => 0,
57+
self::Medium => 1,
58+
self::Large => 2,
59+
};
60+
}
61+
62+
case Unknown = 'unknown';
63+
case Small = 'small';
64+
case Medium = 'medium';
65+
case Large = 'large';
66+
}

src/TestSize/Known.php

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

src/TestSize/Large.php

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

src/TestSize/Medium.php

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

src/TestSize/Small.php

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

src/TestSize/TestSize.php

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

0 commit comments

Comments
 (0)