diff options
| author | Sam Light <sam@lightscale.co.uk> | 2026-06-10 19:00:32 +0100 |
|---|---|---|
| committer | Sam Light <sam@lightscale.co.uk> | 2026-06-10 19:00:32 +0100 |
| commit | 8c0efd0d9317ad92bd55cd6afcd41bdbab827bf8 (patch) | |
| tree | c654456753e90ab38b7bcb89ece3381ad7a40f4a /tests/Utils | |
| parent | 5fe7c87967ff29c4a8f03a9186918d8359f4887e (diff) | |
Make basic routing work
Diffstat (limited to 'tests/Utils')
| -rw-r--r-- | tests/Utils/TestCall.php | 16 | ||||
| -rw-r--r-- | tests/Utils/TestCallable.php | 69 |
2 files changed, 85 insertions, 0 deletions
diff --git a/tests/Utils/TestCall.php b/tests/Utils/TestCall.php new file mode 100644 index 0000000..971e6a7 --- /dev/null +++ b/tests/Utils/TestCall.php @@ -0,0 +1,16 @@ +<?php + +declare(strict_types=1); + +namespace Lightscale\Router\Test\Utils; + +readonly class TestCall +{ + /** + * @param mixed[] $args + */ + public function __construct( + public array $args, + public mixed $return, + ){} +} diff --git a/tests/Utils/TestCallable.php b/tests/Utils/TestCallable.php new file mode 100644 index 0000000..42a3bb5 --- /dev/null +++ b/tests/Utils/TestCallable.php @@ -0,0 +1,69 @@ +<?php + +declare(strict_types=1); + +namespace Lightscale\Router\Test\Utils; + +use Closure; +use PHPUnit\Framework\Assert; + +class TestCallable +{ + private Closure $cb; + + /** @var TestCall[] */ + private array $calls; + + final public function __construct(callable $cb) + { + $this->cb = Closure::fromCallable($cb); + } + + public static function make(callable $cb): static + { + return new static($cb); + } + + public function __invoke(mixed ...$args): mixed + { + $call = new TestCall( + args: $args, + return: ($this->cb)(...$args), + ); + $this->calls[] = $call; + + return $call->return; + } + + public function getCallCount(): int + { + return count($this->calls); + } + + /** @return TestCall[] */ + public function getCalls(): array + { + return $this->calls; + } + + public function getLastCall(): ?TestCall + { + return $this->calls[$this->getCallCount() - 1] ?? null; + } + + public function assertIsCalled(): void + { + Assert::assertGreaterThan(0, $this->getCallCount(), 'Not been called'); + } + + public function assertNotCalled(): void + { + Assert::assertSame(0, $this->getCallCount()); + } + + public function assertCalledTimes(int $amount): void + { + Assert::assertSame($amount, $this->getCallCount()); + } + +} |
