Skip to content

Commit

Permalink
Merge pull request #353 from ergebnis/fix/rename
Browse files Browse the repository at this point in the history
Fix: Rename `MaximumCount` to `Count`
  • Loading branch information
localheinz committed Nov 2, 2023
2 parents 070e1f8 + 3dce136 commit a243c02
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
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
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
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
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
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
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());
}
}
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

0 comments on commit a243c02

Please sign in to comment.