Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Rename MaximumCount to Count #353

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions src/MaximumCount.php → src/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* @internal
*/
final class InvalidMaximumCount extends \InvalidArgumentException
final class InvalidCount extends \InvalidArgumentException
{
public static function notGreaterThanZero(int $value): self
{
Expand Down
4 changes: 2 additions & 2 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Reporter/DefaultReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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();
}
Expand Down
18 changes: 9 additions & 9 deletions test/Unit/MaximumCountTest.php → test/Unit/CountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
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;

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.',
Expand Down