-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9c68f4
commit 0c23758
Showing
7 changed files
with
154 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace IngeniozIT\Router\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use IngeniozIT\Router\{Router, RouteGroup, Route}; | ||
use Closure; | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD.StaticAccess) | ||
*/ | ||
class SubGroupTest extends TestCase | ||
{ | ||
use PsrTrait; | ||
|
||
private function router(RouteGroup $routeGroup, ?Closure $fallback = null): Router | ||
{ | ||
return new Router($routeGroup, self::container(), $fallback); | ||
} | ||
|
||
public function testCanHaveSubGroups(): void | ||
{ | ||
$routeGroup = new RouteGroup( | ||
routes: [ | ||
new RouteGroup( | ||
routes: [ | ||
Route::get(path: '/sub', callback: static fn() => 'TEST'), | ||
], | ||
), | ||
], | ||
); | ||
$request = self::serverRequest('GET', '/sub'); | ||
|
||
$response = $this->router($routeGroup)->handle($request); | ||
|
||
self::assertEquals('TEST', (string)$response->getBody()); | ||
} | ||
|
||
public function testCanHandleARouteAfterASubGroup(): void | ||
{ | ||
$routeGroup = new RouteGroup( | ||
routes: [ | ||
new RouteGroup( | ||
routes: [ | ||
Route::get(path: '/sub', callback: static fn() => 'TEST'), | ||
], | ||
), | ||
Route::get(path: '/after-sub', callback: static fn() => 'TEST2'), | ||
], | ||
); | ||
$request = self::serverRequest('GET', '/after-sub'); | ||
|
||
$response = $this->router($routeGroup)->handle($request); | ||
|
||
self::assertEquals('TEST2', (string)$response->getBody()); | ||
} | ||
} |