From 3dce136b8b0af630993e196f03f45463196e9179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Thu, 2 Nov 2023 10:40:47 +0100 Subject: [PATCH] Fix: Rename MaximumCount to Count --- CHANGELOG.md | 2 ++ src/{MaximumCount.php => Count.php} | 6 +++--- ...nvalidMaximumCount.php => InvalidCount.php} | 2 +- src/Extension.php | 4 ++-- src/Reporter/DefaultReporter.php | 4 ++-- .../{MaximumCountTest.php => CountTest.php} | 18 +++++++++--------- ...ximumCountTest.php => InvalidCountTest.php} | 6 +++--- 7 files changed, 22 insertions(+), 20 deletions(-) rename src/{MaximumCount.php => Count.php} (81%) rename src/Exception/{InvalidMaximumCount.php => InvalidCount.php} (89%) rename test/Unit/{MaximumCountTest.php => CountTest.php} (60%) rename test/Unit/Exception/{InvalidMaximumCountTest.php => InvalidCountTest.php} (78%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72848ac6..46082da6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ For a full diff see [`2.3.2...main`][2.3.2...main]. - Extracted `Duration` ([#351]), by [@localheinz] - Merged `MaximumDuration` into `Duration` ([#352]), by [@localheinz] +- Renamed `MaximumCount` to `Count` ([#353]), by [@localheinz] ### Fixed @@ -176,5 +177,6 @@ For a full diff see [`7afa59c...1.0.0`][7afa59c...1.0.0]. [#350]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/350 [#351]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/351 [#352]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/352 +[#353]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/353 [@localheinz]: https://github.com/localheinz diff --git a/src/MaximumCount.php b/src/Count.php similarity index 81% rename from src/MaximumCount.php rename to src/Count.php index 2754fa62..fc9aaea7 100644 --- a/src/MaximumCount.php +++ b/src/Count.php @@ -16,19 +16,19 @@ /** * @internal */ -final class MaximumCount +final class Count { private function __construct(private readonly int $value) { } /** - * @throws Exception\InvalidMaximumCount + * @throws Exception\InvalidCount */ public static function fromInt(int $value): self { if (0 >= $value) { - throw Exception\InvalidMaximumCount::notGreaterThanZero($value); + throw Exception\InvalidCount::notGreaterThanZero($value); } return new self($value); diff --git a/src/Exception/InvalidMaximumCount.php b/src/Exception/InvalidCount.php similarity index 89% rename from src/Exception/InvalidMaximumCount.php rename to src/Exception/InvalidCount.php index 7e69b255..490e6d6b 100644 --- a/src/Exception/InvalidMaximumCount.php +++ b/src/Exception/InvalidCount.php @@ -16,7 +16,7 @@ /** * @internal */ -final class InvalidMaximumCount extends \InvalidArgumentException +final class InvalidCount extends \InvalidArgumentException { public static function notGreaterThanZero(int $value): self { diff --git a/src/Extension.php b/src/Extension.php index 6fc36fbb..76dff55a 100644 --- a/src/Extension.php +++ b/src/Extension.php @@ -27,10 +27,10 @@ public function bootstrap( return; } - $maximumCount = MaximumCount::fromInt(10); + $maximumCount = Count::fromInt(10); if ($parameters->has('maximum-count')) { - $maximumCount = MaximumCount::fromInt((int) $parameters->get('maximum-count')); + $maximumCount = Count::fromInt((int) $parameters->get('maximum-count')); } $maximumDuration = Duration::fromMilliseconds(500); diff --git a/src/Reporter/DefaultReporter.php b/src/Reporter/DefaultReporter.php index 34d41e38..a9f91cb4 100644 --- a/src/Reporter/DefaultReporter.php +++ b/src/Reporter/DefaultReporter.php @@ -14,9 +14,9 @@ namespace Ergebnis\PHPUnit\SlowTestDetector\Reporter; use Ergebnis\PHPUnit\SlowTestDetector\Comparator; +use Ergebnis\PHPUnit\SlowTestDetector\Count; use Ergebnis\PHPUnit\SlowTestDetector\Duration; use Ergebnis\PHPUnit\SlowTestDetector\Formatter; -use Ergebnis\PHPUnit\SlowTestDetector\MaximumCount; use Ergebnis\PHPUnit\SlowTestDetector\SlowTest; /** @@ -29,7 +29,7 @@ final class DefaultReporter implements Reporter public function __construct( private readonly Formatter\DurationFormatter $durationFormatter, private readonly Duration $maximumDuration, - private readonly MaximumCount $maximumCount, + private readonly Count $maximumCount, ) { $this->durationComparator = new Comparator\DurationComparator(); } diff --git a/test/Unit/MaximumCountTest.php b/test/Unit/CountTest.php similarity index 60% rename from test/Unit/MaximumCountTest.php rename to test/Unit/CountTest.php index 1f6be2fc..0d97fbe3 100644 --- a/test/Unit/MaximumCountTest.php +++ b/test/Unit/CountTest.php @@ -14,28 +14,28 @@ namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Unit; use Ergebnis\DataProvider; +use Ergebnis\PHPUnit\SlowTestDetector\Count; use Ergebnis\PHPUnit\SlowTestDetector\Exception; -use Ergebnis\PHPUnit\SlowTestDetector\MaximumCount; use PHPUnit\Framework; -#[Framework\Attributes\CoversClass(MaximumCount::class)] -#[Framework\Attributes\UsesClass(Exception\InvalidMaximumCount::class)] -final class MaximumCountTest extends Framework\TestCase +#[Framework\Attributes\CoversClass(Count::class)] +#[Framework\Attributes\UsesClass(Exception\InvalidCount::class)] +final class CountTest extends Framework\TestCase { #[Framework\Attributes\DataProviderExternal(DataProvider\IntProvider::class, 'lessThanZero')] #[Framework\Attributes\DataProviderExternal(DataProvider\IntProvider::class, 'zero')] public function testFromIntRejectsInvalidValue(int $value): void { - $this->expectException(Exception\InvalidMaximumCount::class); + $this->expectException(Exception\InvalidCount::class); - MaximumCount::fromInt($value); + Count::fromInt($value); } #[Framework\Attributes\DataProviderExternal(DataProvider\IntProvider::class, 'greaterThanZero')] - public function testFromSecondsReturnsMaximumCount(int $value): void + public function testFromIntReturnsCount(int $value): void { - $maximumCount = MaximumCount::fromInt($value); + $count = Count::fromInt($value); - self::assertSame($value, $maximumCount->toInt()); + self::assertSame($value, $count->toInt()); } } diff --git a/test/Unit/Exception/InvalidMaximumCountTest.php b/test/Unit/Exception/InvalidCountTest.php similarity index 78% rename from test/Unit/Exception/InvalidMaximumCountTest.php rename to test/Unit/Exception/InvalidCountTest.php index c12cf330..c9f520d1 100644 --- a/test/Unit/Exception/InvalidMaximumCountTest.php +++ b/test/Unit/Exception/InvalidCountTest.php @@ -17,8 +17,8 @@ use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; -#[Framework\Attributes\CoversClass(Exception\InvalidMaximumCount::class)] -final class InvalidMaximumCountTest extends Framework\TestCase +#[Framework\Attributes\CoversClass(Exception\InvalidCount::class)] +final class InvalidCountTest extends Framework\TestCase { use Test\Util\Helper; @@ -26,7 +26,7 @@ public function testNotGreaterThanZeroReturnsException(): void { $value = self::faker()->numberBetween(); - $exception = Exception\InvalidMaximumCount::notGreaterThanZero($value); + $exception = Exception\InvalidCount::notGreaterThanZero($value); $message = \sprintf( 'Value should be greater than 0, but %d is not.',