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/Unit/BasicStrategyTest.php | |
| parent | 5fe7c87967ff29c4a8f03a9186918d8359f4887e (diff) | |
Make basic routing work
Diffstat (limited to 'tests/Unit/BasicStrategyTest.php')
| -rw-r--r-- | tests/Unit/BasicStrategyTest.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/Unit/BasicStrategyTest.php b/tests/Unit/BasicStrategyTest.php new file mode 100644 index 0000000..2a0b550 --- /dev/null +++ b/tests/Unit/BasicStrategyTest.php @@ -0,0 +1,44 @@ +<?php + +use Lightscale\Router\BasicStrategy; +use Lightscale\Router\Enums\HttpMethod; +use Lightscale\Router\Exceptions\NotFoundException; +use Lightscale\Router\Route; +use Lightscale\Router\RouteCall; +use Lightscale\Router\Test\Utils\TestCallable; +use Nyholm\Psr7\Factory\Psr17Factory; + +it('initialises') + ->expect(fn() => new BasicStrategy) + ->toBeInstanceOf(BasicStrategy::class); + +it('throws on not found', function() { + (new BasicStrategy)->notFound( + (new Psr17Factory)->createServerRequest( + HttpMethod::Get->value, + '/testing/testing' + ) + ); +})->throws(NotFoundException::class); + +it('calls route', function () { + $factory = new Psr17Factory; + $response = $factory->createResponse(200, 'OK'); + $cb = TestCallable::make(fn () => $response); + $res = (new BasicStrategy)->runRoute($rc = new RouteCall( + $factory->createServerRequest( + HttpMethod::Get->value, + '/testing/testing' + ), + new Route( + HttpMethod::Get, + $cb + ), + [] + )); + + $cb->assertIsCalled(); + $call = $cb->getLastCall(); + expect($call->args[0] ?? null)->toBe($rc); + expect($res)->toBe($response); +}); |
