RoutePatternMatcherTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Knuckles\Scribe\Tests\Unit;
  3. use Illuminate\Routing\Route;
  4. use Knuckles\Scribe\Tools\RoutePatternMatcher;
  5. use PHPUnit\Framework\TestCase;
  6. class RoutePatternMatcherTest extends TestCase
  7. {
  8. /** @test */
  9. public function matches_by_route_name()
  10. {
  11. $route = new Route(["POST"], "/abc", ['as' => 'users.show']);
  12. $this->assertTrue(RoutePatternMatcher::matches($route, ['users.show']));
  13. $this->assertTrue(RoutePatternMatcher::matches($route, ['users.*']));
  14. $this->assertFalse(RoutePatternMatcher::matches($route, ['users.index']));
  15. }
  16. /** @test */
  17. public function matches_by_route_method_and_path()
  18. {
  19. $route = new Route(["POST"], "/abc", ['as' => 'users.show']);
  20. $this->assertTrue(RoutePatternMatcher::matches($route, ["POST /abc"]));
  21. $this->assertTrue(RoutePatternMatcher::matches($route, ["POST abc"]));
  22. $this->assertTrue(RoutePatternMatcher::matches($route, ["POST ab*"]));
  23. $this->assertTrue(RoutePatternMatcher::matches($route, ["POST /ab*"]));
  24. $this->assertTrue(RoutePatternMatcher::matches($route, ["POST *"]));
  25. $this->assertFalse(RoutePatternMatcher::matches($route, ["GET /abc"]));
  26. $this->assertFalse(RoutePatternMatcher::matches($route, ["GET abc"]));
  27. }
  28. /** @test */
  29. public function matches_by_route_path()
  30. {
  31. $route = new Route(["POST"], "/abc", ['as' => 'users.show']);
  32. $this->assertTrue(RoutePatternMatcher::matches($route, ["/abc"]));
  33. $this->assertTrue(RoutePatternMatcher::matches($route, ["abc"]));
  34. $this->assertTrue(RoutePatternMatcher::matches($route, ["ab*"]));
  35. $this->assertTrue(RoutePatternMatcher::matches($route, ["/ab*"]));
  36. $this->assertTrue(RoutePatternMatcher::matches($route, ["*"]));
  37. $this->assertFalse(RoutePatternMatcher::matches($route, ["/d*"]));
  38. }
  39. }