Skip to content

Commit

Permalink
More test, MSI 100% (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik authored Jun 7, 2023
1 parent d7a31ab commit c821611
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,28 @@ public function testWithCors(): void
$this->assertCount(3, $routeCollection->getRoutes());
}

public function testWithCorsWithHostRoutes(): void
{
$group = Group::create()
->routes(
Route::get('/info')
->action(static fn () => 'info')
->host('yii.dev'),
Route::get('/info')
->action(static fn () => 'info')
->host('yii.test'),
)
->withCors(
static fn () => new Response(204)
);

$collector = new RouteCollector();
$collector->addGroup($group);
$routeCollection = new RouteCollection($collector);

$this->assertCount(4, $routeCollection->getRoutes());
}

public function testWithCorsDoesntDuplicateRoutes(): void
{
$group = Group::create()
Expand Down
30 changes: 30 additions & 0 deletions tests/Middleware/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,36 @@ static function (ServerRequestInterface $request, RequestHandlerInterface $handl
$this->assertSame('test from options handler', $response->getHeaderLine('Test'));
}

public function testNestedGroupWithCorsHandlers(): void
{
$group = Group::create()
->routes(
Group::create()
->routes(
Route::post('/post')->action(static fn () => new Response(204)),
)
->withCors(
static function (ServerRequestInterface $request, RequestHandlerInterface $handler) {
$response = $handler->handle($request);
return $response->withHeader('Test', 'test from options handler');
}
)
);

$collector = new RouteCollector();
$collector->addGroup($group);
$routeCollection = new RouteCollection($collector);

$request = new ServerRequest('OPTIONS', '/post');
$response = $this->processWithRouter($request, $routeCollection);
$this->assertSame(204, $response->getStatusCode());
$this->assertSame('test from options handler', $response->getHeaderLine('Test'));
$request = new ServerRequest('POST', '/post');
$response = $this->processWithRouter($request, $routeCollection);
$this->assertSame(204, $response->getStatusCode());
$this->assertSame('test from options handler', $response->getHeaderLine('Test'));
}

public function testWithCorsHandler(): void
{
$request = new ServerRequest('OPTIONS', '/options');
Expand Down

0 comments on commit c821611

Please sign in to comment.