generated from ergebnis/php-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #663 from ergebnis/feature/extract
Enhancement: Extract `MaximumCount`
- Loading branch information
Showing
12 changed files
with
227 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021-2025 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/phpunit-slow-test-detector | ||
*/ | ||
|
||
namespace Ergebnis\PHPUnit\SlowTestDetector\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class InvalidMaximumCount extends \InvalidArgumentException | ||
{ | ||
public static function notGreaterThanZero(int $value): self | ||
{ | ||
return new self(\sprintf( | ||
'Value should be greater than 0, but %d is not.', | ||
$value | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021-2025 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/phpunit-slow-test-detector | ||
*/ | ||
|
||
namespace Ergebnis\PHPUnit\SlowTestDetector; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class MaximumCount | ||
{ | ||
private $count; | ||
|
||
private function __construct(Count $count) | ||
{ | ||
$this->count = $count; | ||
} | ||
|
||
/** | ||
* @throws Exception\InvalidMaximumCount | ||
*/ | ||
public static function fromCount(Count $count): self | ||
{ | ||
if ($count->toInt() <= 0) { | ||
throw Exception\InvalidMaximumCount::notGreaterThanZero($count->toInt()); | ||
} | ||
|
||
return new self($count); | ||
} | ||
|
||
public static function default(): self | ||
{ | ||
return new self(Count::fromInt(10)); | ||
} | ||
|
||
public function toCount(): Count | ||
{ | ||
return $this->count; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021-2025 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/phpunit-slow-test-detector | ||
*/ | ||
|
||
namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Unit\Exception; | ||
|
||
use Ergebnis\PHPUnit\SlowTestDetector\Exception; | ||
use Ergebnis\PHPUnit\SlowTestDetector\Test; | ||
use PHPUnit\Framework; | ||
|
||
/** | ||
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Exception\InvalidMaximumCount | ||
*/ | ||
final class InvalidMaximumCountTest extends Framework\TestCase | ||
{ | ||
use Test\Util\Helper; | ||
|
||
public function testNotGreaterThanZeroReturnsException() | ||
{ | ||
$value = self::faker()->numberBetween(); | ||
|
||
$exception = Exception\InvalidMaximumCount::notGreaterThanZero($value); | ||
|
||
$message = \sprintf( | ||
'Value should be greater than 0, but %d is not.', | ||
$value | ||
); | ||
|
||
self::assertSame($message, $exception->getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021-2025 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/phpunit-slow-test-detector | ||
*/ | ||
|
||
namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Unit; | ||
|
||
use Ergebnis\PHPUnit\SlowTestDetector\Count; | ||
use Ergebnis\PHPUnit\SlowTestDetector\Exception; | ||
use Ergebnis\PHPUnit\SlowTestDetector\MaximumCount; | ||
use Ergebnis\PHPUnit\SlowTestDetector\Test; | ||
use PHPUnit\Framework; | ||
|
||
/** | ||
* @covers \Ergebnis\PHPUnit\SlowTestDetector\MaximumCount | ||
* | ||
* @uses \Ergebnis\PHPUnit\SlowTestDetector\Count | ||
* @uses \Ergebnis\PHPUnit\SlowTestDetector\Exception\InvalidMaximumCount | ||
*/ | ||
final class MaximumCountTest extends Framework\TestCase | ||
{ | ||
use Test\Util\Helper; | ||
|
||
public function testFromCountRejectsInvalidCount() | ||
{ | ||
$count = Count::fromInt(0); | ||
|
||
$this->expectException(Exception\InvalidMaximumCount::class); | ||
|
||
MaximumCount::fromCount($count); | ||
} | ||
|
||
/** | ||
* @dataProvider \Ergebnis\PHPUnit\SlowTestDetector\Test\DataProvider\IntProvider::greaterThanZero | ||
*/ | ||
public function testFromCountReturnsMaximumCount(int $value) | ||
{ | ||
$count = Count::fromInt($value); | ||
|
||
$maximumCount = MaximumCount::fromCount($count); | ||
|
||
self::assertSame($count, $maximumCount->toCount()); | ||
} | ||
|
||
public function testDefaultReturnsMaximumCount() | ||
{ | ||
$maximumCount = MaximumCount::default(); | ||
|
||
$expected = Count::fromInt(10); | ||
|
||
self::assertEquals($expected, $maximumCount->toCount()); | ||
} | ||
} |
Oops, something went wrong.