-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from gsteel/v4/duplicate-route-coverage
Add test coverage for the duplicate route detector
- Loading branch information
Showing
2 changed files
with
81 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MezzioTest\Router; | ||
|
||
use Mezzio\Router\DuplicateRouteDetector; | ||
use Mezzio\Router\Exception\DuplicateRouteException; | ||
use Mezzio\Router\Route; | ||
use MezzioTest\Router\Asset\NoOpMiddleware; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** @psalm-suppress InternalClass,InternalMethod */ | ||
class DuplicateRouteDetectorTest extends TestCase | ||
{ | ||
private DuplicateRouteDetector $detector; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->detector = new DuplicateRouteDetector(); | ||
} | ||
|
||
public function test2RoutesWithTheSameNameAreExceptional(): void | ||
{ | ||
$a = new Route('/a', new NoOpMiddleware(), Route::HTTP_METHOD_ANY, 'name'); | ||
$b = new Route('/b', new NoOpMiddleware(), Route::HTTP_METHOD_ANY, 'name'); | ||
|
||
$this->detector->detectDuplicate($a); | ||
|
||
$this->expectException(DuplicateRouteException::class); | ||
|
||
$this->detector->detectDuplicate($b); | ||
} | ||
|
||
public function testRoutesOnTheSamePathButWithDifferentMethodsAreNotDuplicates(): void | ||
{ | ||
$a = new Route('/a', new NoOpMiddleware(), ['GET'], 'a'); | ||
$b = new Route('/a', new NoOpMiddleware(), ['POST'], 'b'); | ||
$this->detector->detectDuplicate($a); | ||
$this->detector->detectDuplicate($b); | ||
|
||
$this->expectNotToPerformAssertions(); | ||
} | ||
|
||
public function testRoutesOnTheSamePathAreExceptional(): void | ||
{ | ||
$a = new Route('/a', new NoOpMiddleware(), ['GET'], 'a'); | ||
$b = new Route('/a', new NoOpMiddleware(), ['GET'], 'b'); | ||
$this->detector->detectDuplicate($a); | ||
|
||
$this->expectException(DuplicateRouteException::class); | ||
|
||
$this->detector->detectDuplicate($b); | ||
} | ||
|
||
public function testDuplicateRoutesOnTheSamePathWithMethodIntersectionIsExceptional(): void | ||
{ | ||
$a = new Route('/a', new NoOpMiddleware(), ['GET'], 'a'); | ||
$b = new Route('/a', new NoOpMiddleware(), Route::HTTP_METHOD_ANY, 'b'); | ||
$this->detector->detectDuplicate($a); | ||
|
||
$this->expectException(DuplicateRouteException::class); | ||
|
||
$this->detector->detectDuplicate($b); | ||
} | ||
|
||
public function testDuplicateRoutesOnTheSamePathBothWithAnyMethodAreExceptional(): void | ||
{ | ||
$a = new Route('/a', new NoOpMiddleware(), Route::HTTP_METHOD_ANY, 'a'); | ||
$b = new Route('/a', new NoOpMiddleware(), Route::HTTP_METHOD_ANY, 'b'); | ||
$this->detector->detectDuplicate($a); | ||
|
||
$this->expectException(DuplicateRouteException::class); | ||
|
||
$this->detector->detectDuplicate($b); | ||
} | ||
} |