Jagepard /
Primate-Router
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * @author : Jagepard <[email protected]"> |
||
| 5 | * @license https://mit-license.org/ MIT |
||
| 6 | * |
||
| 7 | * phpunit src/tests/ContainerTest --coverage-html src/tests/coverage-html |
||
| 8 | */ |
||
| 9 | |||
| 10 | namespace Primate\Router\Tests; |
||
| 11 | |||
| 12 | use PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase; |
||
|
0 ignored issues
–
show
|
|||
| 13 | use Primate\Router\Router; |
||
| 14 | use Primate\Router\Tests\Stub\Controllers\MainController; |
||
| 15 | |||
| 16 | class RouterTest extends PHPUnit_Framework_TestCase |
||
| 17 | { |
||
| 18 | protected function setUp(): void |
||
| 19 | { |
||
| 20 | require "./vendor/autoload.php"; |
||
| 21 | } |
||
| 22 | |||
| 23 | protected function setRouteEnvironment(string $requestUri, string $requestMethod, string $pattern): void |
||
| 24 | { |
||
| 25 | $_SERVER["REQUEST_URI"] = $requestUri; |
||
| 26 | $_SERVER["REQUEST_METHOD"] = $requestMethod; |
||
| 27 | |||
| 28 | $router = new Router(); |
||
| 29 | $requestUri = explode('/', trim(parse_url($_SERVER["REQUEST_URI"])["path"], '/')); |
||
| 30 | $router->addRoute($pattern, [MainController::class, "index"], $requestMethod); |
||
| 31 | $router->matchRoute($requestUri); |
||
| 32 | |||
| 33 | $this->expectOutputString('Primate\Router\Tests\Stub\Controllers\MainController::index'); |
||
| 34 | } |
||
| 35 | |||
| 36 | public function testGet(): void |
||
| 37 | { |
||
| 38 | $this->setRouteEnvironment("/test/page?id=98", "GET", "/test/page"); |
||
| 39 | } |
||
| 40 | |||
| 41 | public function testPost(): void |
||
| 42 | { |
||
| 43 | $this->setRouteEnvironment("test/page?some=123", "POST", "/test/page"); |
||
| 44 | } |
||
| 45 | |||
| 46 | public function testPut(): void |
||
| 47 | { |
||
| 48 | $this->setRouteEnvironment("test/page", 'PUT', "/test/page"); |
||
| 49 | } |
||
| 50 | |||
| 51 | public function testPatch(): void |
||
| 52 | { |
||
| 53 | $this->setRouteEnvironment("test/page", 'PATCH', "/test/page"); |
||
| 54 | } |
||
| 55 | |||
| 56 | public function testDelete(): void |
||
| 57 | { |
||
| 58 | $this->setRouteEnvironment("test/page", 'DELETE', "/test/page"); |
||
| 59 | } |
||
| 60 | |||
| 61 | public function testOption(): void |
||
| 62 | { |
||
| 63 | $this->setRouteEnvironment("test/page", 'OPTION', "/test/page"); |
||
| 64 | } |
||
| 65 | |||
| 66 | public function testCallable(): void |
||
| 67 | { |
||
| 68 | $_SERVER["REQUEST_URI"] = "test/page"; |
||
| 69 | $_SERVER["REQUEST_METHOD"] = "GET"; |
||
| 70 | |||
| 71 | $router = new Router(); |
||
| 72 | $requestUri = explode('/', trim(parse_url($_SERVER["REQUEST_URI"])["path"], '/')); |
||
| 73 | $router->addRoute("/test/page", function () { |
||
| 74 | echo "Closure"; |
||
| 75 | }); |
||
| 76 | |||
| 77 | $router->matchRoute($requestUri); |
||
| 78 | |||
| 79 | $this->expectOutputString('Closure'); |
||
| 80 | } |
||
| 81 | |||
| 82 | public function testCallableWithParams(): void |
||
| 83 | { |
||
| 84 | $_SERVER["REQUEST_URI"] = "/closure/john"; |
||
| 85 | $_SERVER["REQUEST_METHOD"] = "POST"; |
||
| 86 | |||
| 87 | $router = new Router(); |
||
| 88 | $requestUri = explode('/', trim(parse_url($_SERVER["REQUEST_URI"])["path"], '/')); |
||
| 89 | |||
| 90 | |||
| 91 | $router->addRoute("/closure/{name}", function ($name) { |
||
| 92 | echo "Closure $name"; |
||
| 93 | }, "POST"); |
||
| 94 | |||
| 95 | $router->matchRoute($requestUri); |
||
| 96 | |||
| 97 | $this->expectOutputString('Closure john'); |
||
| 98 | } |
||
| 99 | } |
||
| 100 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths