From d039a5d62a9ac6ababae70d9d96422ca59f2b2d4 Mon Sep 17 00:00:00 2001 From: Brett Parson Date: Fri, 21 Aug 2026 13:55:37 -0500 Subject: Scaffold miniroute routing/middleware kernel --- tests/Fixtures/ClassLevelController.php | 18 ++++++++++++++ tests/Fixtures/FakeController.php | 33 +++++++++++++++++++++++++ tests/Fixtures/FakeMiddleware.php | 30 +++++++++++++++++++++++ tests/Fixtures/FakeResolver.php | 28 +++++++++++++++++++++ tests/Fixtures/TestRequest.php | 40 ++++++++++++++++++++++++++++++ tests/Fixtures/TestResponse.php | 43 +++++++++++++++++++++++++++++++++ 6 files changed, 192 insertions(+) create mode 100644 tests/Fixtures/ClassLevelController.php create mode 100644 tests/Fixtures/FakeController.php create mode 100644 tests/Fixtures/FakeMiddleware.php create mode 100644 tests/Fixtures/FakeResolver.php create mode 100644 tests/Fixtures/TestRequest.php create mode 100644 tests/Fixtures/TestResponse.php (limited to 'tests/Fixtures') diff --git a/tests/Fixtures/ClassLevelController.php b/tests/Fixtures/ClassLevelController.php new file mode 100644 index 0000000..88ef6e6 --- /dev/null +++ b/tests/Fixtures/ClassLevelController.php @@ -0,0 +1,18 @@ +param('slug')); + } + + #[Post('/entries')] + #[Middleware(FakeMiddleware::class)] + public function store(RequestInterface $request): ResponseInterface + { + return new TestResponse(200, 'store'); + } +} diff --git a/tests/Fixtures/FakeMiddleware.php b/tests/Fixtures/FakeMiddleware.php new file mode 100644 index 0000000..d684e7c --- /dev/null +++ b/tests/Fixtures/FakeMiddleware.php @@ -0,0 +1,30 @@ +|null */ + private ?ArrayObject $log; + + public function __construct( + private readonly string $name = 'fake', + ?ArrayObject $log = null, + ) { + $this->log = $log; + } + + public function handle(RequestInterface $request, callable $next): ResponseInterface + { + $this->log?->append($this->name); + + return $next($request); + } +} diff --git a/tests/Fixtures/FakeResolver.php b/tests/Fixtures/FakeResolver.php new file mode 100644 index 0000000..af6ec1f --- /dev/null +++ b/tests/Fixtures/FakeResolver.php @@ -0,0 +1,28 @@ + */ + private array $bindings = []; + + public function bind(string $class, object $instance): void + { + $this->bindings[$class] = $instance; + } + + public function resolve(string $class): object + { + if (!array_key_exists($class, $this->bindings)) { + throw new RuntimeException("No binding for {$class}"); + } + + return $this->bindings[$class]; + } +} diff --git a/tests/Fixtures/TestRequest.php b/tests/Fixtures/TestRequest.php new file mode 100644 index 0000000..c449610 --- /dev/null +++ b/tests/Fixtures/TestRequest.php @@ -0,0 +1,40 @@ + $params + */ + public function __construct( + private readonly string $method, + private readonly string $path, + private readonly array $params = [], + ) { + } + + public function method(): string + { + return $this->method; + } + + public function path(): string + { + return $this->path; + } + + public function param(string $name, string $default = ''): string + { + return $this->params[$name] ?? $default; + } + + public function withParams(array $params): RequestInterface + { + return new self($this->method, $this->path, $params); + } +} diff --git a/tests/Fixtures/TestResponse.php b/tests/Fixtures/TestResponse.php new file mode 100644 index 0000000..25a0307 --- /dev/null +++ b/tests/Fixtures/TestResponse.php @@ -0,0 +1,43 @@ + $headers + */ + public function __construct( + private readonly int $status, + private readonly string $body, + private readonly array $headers = [], + ) { + } + + public function status(): int + { + return $this->status; + } + + public function body(): string + { + return $this->body; + } + + public function withHeader(string $name, string $value): ResponseInterface + { + return new self($this->status, $this->body, array_merge($this->headers, [$name => $value])); + } + + /** + * @return array + */ + public function headers(): array + { + return $this->headers; + } +} -- cgit v1.2.3