Skip to content

Commit

Permalink
prepare release
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralbot committed Jan 7, 2025
1 parent 0d92d6f commit 9640c2f
Show file tree
Hide file tree
Showing 38 changed files with 364 additions and 450 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
"require": {
"php": ">=8.1",
"ext-json": "*",
"spiral/core": "^3.15",
"spiral/hmvc": "^3.15",
"spiral/http": "^3.15",
"spiral/interceptors": "^3.15",
"spiral/core": "^3.14.9",
"spiral/hmvc": "^3.14.9",
"spiral/http": "^3.14.9",
"spiral/interceptors": "^3.14.9",
"cocur/slugify": "^3.2 || ^4.0",
"spiral/telemetry": "^3.15",
"spiral/telemetry": "^3.14.9",
"doctrine/inflector": "^1.4|^2.0",
"psr/event-dispatcher": "^1.0"
},
Expand Down
4 changes: 0 additions & 4 deletions src/CoreHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface;
use Spiral\Core\CoreInterface;
Expand Down Expand Up @@ -125,9 +124,6 @@ public function handle(Request $request): Response
new CallContext(
Target::fromPair($controller, $action),
$parameters,
[
ServerRequestInterface::class => $request,
],
),
),
attributes: [
Expand Down
9 changes: 4 additions & 5 deletions src/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Spiral\Http\CallableHandler;
use Spiral\Router\Exception\RouteException;
use Spiral\Router\Exception\TargetException;
use Spiral\Router\Traits\LazyPipelineTrait;
use Spiral\Router\Traits\PipelineTrait;

/**
Expand Down Expand Up @@ -91,7 +90,7 @@ public function withContainer(ContainerInterface $container): ContainerizedInter
$route->target = clone $route->target;
}

$route->pipeline = $route->makeLazyPipeline();
$route->pipeline = $route->makePipeline();

return $route;
}
Expand Down Expand Up @@ -130,9 +129,9 @@ public function handle(ServerRequestInterface $request): ResponseInterface
*/
protected function requestHandler(): RequestHandlerInterface
{
$this->hasContainer() or throw new RouteException(
'Unable to configure route pipeline without associated container.',
);
if (!$this->hasContainer()) {
throw new RouteException('Unable to configure route pipeline without associated container');
}

if ($this->target instanceof TargetInterface) {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface

return $this->tracer->trace(
name: 'Routing',
callback: function (SpanInterface $span) use ($request): ResponseInterface {
callback: function (SpanInterface $span) use ($request) {
try {
$route = $this->matchRoute($request, $routeName);
} catch (RouteException $e) {
Expand Down
24 changes: 2 additions & 22 deletions src/Traits/PipelineTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Psr\Container\ContainerExceptionInterface;
use Psr\Http\Server\MiddlewareInterface;
use Spiral\Core\Container\Autowire;
use Spiral\Http\LazyPipeline;
use Spiral\Http\Pipeline;
use Spiral\Router\Exception\RouteException;
use Spiral\Router\PipelineFactory;
Expand All @@ -20,7 +19,7 @@ trait PipelineTrait
{
use ContainerTrait;

protected Pipeline|LazyPipeline|null $pipeline = null;
protected ?Pipeline $pipeline = null;

/** @psalm-var array<array-key, MiddlewareType> */
protected array $middleware = [];
Expand Down Expand Up @@ -54,7 +53,7 @@ public function withMiddleware(...$middleware): RouteInterface
}

if ($route->pipeline !== null) {
$route->pipeline = $route->makeLazyPipeline();
$route->pipeline = $route->makePipeline();
}

return $route;
Expand All @@ -74,8 +73,6 @@ public function withPipeline(Pipeline $pipeline): static
* Get associated route pipeline.
*
* @throws RouteException
*
* @deprecated Will be removed in Spiral v4.0. Use {@see makeLazyPipeline()} instead.
*/
protected function makePipeline(): Pipeline
{
Expand All @@ -88,21 +85,4 @@ protected function makePipeline(): Pipeline
throw new RouteException($e->getMessage(), $e->getCode(), $e);
}
}

/**
* Get associated route pipeline.
*
* @throws RouteException
*/
protected function makeLazyPipeline(): LazyPipeline
{
\assert($this->container !== null);
try {
/** @var LazyPipeline $pipeline */
$pipeline = $this->container->get(LazyPipeline::class);
return $pipeline->withMiddleware(...$this->middleware);
} catch (ContainerExceptionInterface $e) {
throw new RouteException($e->getMessage(), $e->getCode(), $e);
}
}
}
2 changes: 1 addition & 1 deletion src/UriHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function match(UriInterface $uri, array $defaults): ?array
}

$matches = \array_intersect_key(
\array_filter($matches, static fn (string $value): bool => $value !== ''),
\array_filter($matches, static fn (string $value) => $value !== ''),
$this->options
);

Expand Down
13 changes: 4 additions & 9 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ abstract class BaseTestCase extends TestCase
protected Container $container;
protected Router $router;

protected function getContainer(): Container
{
return $this->container;
}

protected function setUp(): void
{
$this->initContainer();
Expand All @@ -54,11 +49,11 @@ protected function makeRouter(string $basePath = '', ?EventDispatcherInterface $
$basePath,
new UriHandler(
new UriFactory(),
new Slugify(),
new Slugify()
),
$this->container,
$dispatcher,
new NullTracer($this->container),
new NullTracer($this->container)
);
}

Expand Down Expand Up @@ -93,8 +88,8 @@ private function initContainer(): void
new LoaderRegistry([
new PhpFileLoader($this->container, $this->container),
new TestLoader(),
]),
),
])
)
);

$this->container->bind(HandlerInterface::class, Core::class);
Expand Down
40 changes: 0 additions & 40 deletions tests/BaseTestingCase.php

This file was deleted.

26 changes: 13 additions & 13 deletions tests/CallableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public function testFunctionRoute(): void
$router = $this->makeRouter();
$router->setRoute(
'action',
new Route('/something', static fn(): string => 'hello world')
new Route('/something', fn() => 'hello world')
);

$response = $router->handle(new ServerRequest('GET', new Uri('/something')));
self::assertSame(200, $response->getStatusCode());
self::assertSame('hello world', (string)$response->getBody());
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('hello world', (string)$response->getBody());
}

public function testObjectRoute(): void
Expand All @@ -33,8 +33,8 @@ public function testObjectRoute(): void
);

$response = $router->handle(new ServerRequest('GET', new Uri('/something')));
self::assertSame(200, $response->getStatusCode());
self::assertSame('invoked', (string)$response->getBody());
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('invoked', (string)$response->getBody());
}

public function testObjectViaContainerRoute(): void
Expand All @@ -46,8 +46,8 @@ public function testObjectViaContainerRoute(): void
);

$response = $router->handle(new ServerRequest('GET', new Uri('/something')));
self::assertSame(200, $response->getStatusCode());
self::assertSame('invoked', (string)$response->getBody());
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('invoked', (string)$response->getBody());
}

public function testHandlerRoute(): void
Expand All @@ -59,8 +59,8 @@ public function testHandlerRoute(): void
);

$response = $router->handle(new ServerRequest('GET', new Uri('/something')));
self::assertSame(200, $response->getStatusCode());
self::assertSame('handler', (string)$response->getBody());
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('handler', (string)$response->getBody());
}

public function testHandlerViaContainerRoute(): void
Expand All @@ -72,8 +72,8 @@ public function testHandlerViaContainerRoute(): void
);

$response = $router->handle(new ServerRequest('GET', new Uri('/something')));
self::assertSame(200, $response->getStatusCode());
self::assertSame('handler', (string)$response->getBody());
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('handler', (string)$response->getBody());
}

public function testInvalidTarget(): void
Expand All @@ -87,7 +87,7 @@ public function testInvalidTarget(): void
);

$response = $router->handle(new ServerRequest('GET', new Uri('/something')));
self::assertSame(200, $response->getStatusCode());
self::assertSame('handler', (string)$response->getBody());
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('handler', (string)$response->getBody());
}
}
2 changes: 1 addition & 1 deletion tests/ContainerScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Spiral\Tests\Router\Fixtures\UserContextController;
use Spiral\Tests\Router\Stub\IdentityScopedMiddleware;

class ContainerScopeTest extends BaseTestingCase
class ContainerScopeTest extends \Spiral\Testing\TestCase
{
public function defineBootloaders(): array
{
Expand Down
40 changes: 20 additions & 20 deletions tests/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ public function testRoute(): void
);

$response = $router->handle(new ServerRequest('GET', new Uri('/test')));
self::assertSame(200, $response->getStatusCode());
self::assertSame('hello world', (string)$response->getBody());
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('hello world', (string)$response->getBody());

$response = $router->handle(new ServerRequest('GET', new Uri('/echo')));
self::assertSame(200, $response->getStatusCode());
self::assertSame('echoed', (string)$response->getBody());
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('echoed', (string)$response->getBody());

$response = $router->handle(new ServerRequest('GET', new Uri('/id/888')));
self::assertSame(200, $response->getStatusCode());
self::assertSame('888', (string)$response->getBody());
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('888', (string)$response->getBody());
}

public function testOptionalParam(): void
Expand All @@ -63,22 +63,22 @@ public function testOptionalParam(): void
);

$response = $router->handle(new ServerRequest('GET', new Uri('/default')));
self::assertSame(200, $response->getStatusCode());
self::assertSame('default', (string)$response->getBody());
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('default', (string)$response->getBody());

$response = $router->handle(new ServerRequest('GET', new Uri('/default/123')));
self::assertSame(200, $response->getStatusCode());
self::assertSame('123', (string)$response->getBody());
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('123', (string)$response->getBody());
}

public function testFallbackHandler(): void
{
$target = new Action(TestController::class, 'default');
$this->getContainer()->removeBinding(HandlerInterface::class);
$this->getContainer()->removeBinding(CoreInterface::class);
$this->container->removeBinding(HandlerInterface::class);
$this->container->removeBinding(CoreInterface::class);

$core = $target->getHandler($this->getContainer(), []);
$handler = (fn(CoreHandler $core): HandlerInterface|CoreInterface => $core->core)->call($core, $core);
$core = $target->getHandler($this->container, []);
$handler = (fn(CoreHandler $core) => $core->core)->call($core, $core);

self::assertInstanceOf(AutowireHandler::class, $handler);
}
Expand All @@ -92,12 +92,12 @@ public function testOptionalParamWithDefaultInt(): void
);

$response = $router->handle(new ServerRequest('GET', new Uri('/defaultInt')));
self::assertSame(200, $response->getStatusCode());
self::assertSame('int: 1', (string)$response->getBody());
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('int: 1', (string)$response->getBody());

$response = $router->handle(new ServerRequest('GET', new Uri('/defaultInt/123')));
self::assertSame(200, $response->getStatusCode());
self::assertSame('string: 123', (string)$response->getBody());
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('string: 123', (string)$response->getBody());
}

public function testUriGeneration(): void
Expand All @@ -109,10 +109,10 @@ public function testUriGeneration(): void
);

$uri = $router->uri('action/test');
self::assertSame('/test', $uri->getPath());
$this->assertSame('/test', $uri->getPath());

$uri = $router->uri('action/id', ['id' => 100]);
self::assertSame('/id/100', $uri->getPath());
$this->assertSame('/id/100', $uri->getPath());
}

public function testClientException(): void
Expand Down
Loading

0 comments on commit 9640c2f

Please sign in to comment.