Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Illuminate\Tests\Routing; use BadMethodCallException; use FooController; ..

Decoded Output download

<?php
 namespace Illuminate\Tests\Routing; use BadMethodCallException; use FooController; use Illuminate\Container\Container; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Http\Request; use Illuminate\Routing\Router; use Mockery as m; use PHPUnit\Framework\TestCase; use Stringable; class RouteRegistrarTest extends TestCase { protected $router; protected function setUp() : void { parent::setUp(); $this->router = new Router(m::mock(Dispatcher::class), Container::getInstance()); } protected function tearDown() : void { m::close(); } public function testMiddlewareFluentRegistration() { $this->router->middleware(array("one", "two"))->get("users", function () { return "all-users"; }); $this->seeResponse("all-users", Request::create("users", "GET")); $this->assertEquals(array("one", "two"), $this->getRoute()->middleware()); $this->router->middleware("three", "four")->get("users", function () { return "all-users"; }); $this->seeResponse("all-users", Request::create("users", "GET")); $this->assertEquals(array("three", "four"), $this->getRoute()->middleware()); $this->router->get("users", function () { return "all-users"; })->middleware("five", "six"); $this->seeResponse("all-users", Request::create("users", "GET")); $this->assertEquals(array("five", "six"), $this->getRoute()->middleware()); $this->router->middleware("seven")->get("users", function () { return "all-users"; }); $this->seeResponse("all-users", Request::create("users", "GET")); $this->assertEquals(array("seven"), $this->getRoute()->middleware()); } public function testNullNamespaceIsRespected() { $this->router->middleware(array("one"))->namespace(null)->get("users", function () { return "all-users"; }); $this->assertNull($this->getRoute()->getAction()["namespace"]); } public function testMiddlewareAsStringableObject() { $one = new class implements Stringable { public function __toString() { return "one"; } }; $this->router->middleware($one)->get("users", function () { return "all-users"; }); $this->seeResponse("all-users", Request::create("users", "GET")); $this->assertSame(array("one"), $this->getRoute()->middleware()); } public function testMiddlewareAsStringableObjectOnRouteInstance() { $one = new class implements Stringable { public function __toString() { return "one"; } }; $this->router->get("users", function () { return "all-users"; })->middleware($one); $this->seeResponse("all-users", Request::create("users", "GET")); $this->assertSame(array("one"), $this->getRoute()->middleware()); } public function testMiddlewareAsArrayWithStringables() { $one = new class implements Stringable { public function __toString() { return "one"; } }; $this->router->middleware(array($one, "two"))->get("users", function () { return "all-users"; }); $this->seeResponse("all-users", Request::create("users", "GET")); $this->assertSame(array("one", "two"), $this->getRoute()->middleware()); } public function testWithoutMiddlewareRegistration() { $this->router->middleware(array("one", "two"))->get("users", function () { return "all-users"; })->withoutMiddleware("one"); $this->seeResponse("all-users", Request::create("users", "GET")); $this->assertEquals(array("one"), $this->getRoute()->excludedMiddleware()); } public function testGetRouteWithTrashed() { $route = $this->router->get("users", array(RouteRegistrarControllerStub::class, "index"))->withTrashed(); $this->assertTrue($route->allowsTrashedBindings()); } public function testResourceWithTrashed() { $this->router->resource("users", RouteRegistrarControllerStub::class)->only(array("index", "destroy"))->withTrashed(array("index", "destroy")); foreach ($this->router->getRoutes() as $route) { $this->assertTrue($route->allowsTrashedBindings()); } } public function testFallbackRoute() { $route = $this->router->fallback(function () { return "milwad"; }); $this->assertTrue($route->isFallback); } public function testSetFallbackRoute() { $route = $this->router->fallback(function () { return "milwad"; }); $route->setFallback(false); $this->assertFalse($route->isFallback); $route->setFallback(true); $this->assertTrue($route->isFallback); } public function testCanRegisterGetRouteWithClosureAction() { $this->router->middleware("get-middleware")->get("users", function () { return "all-users"; }); $this->seeResponse("all-users", Request::create("users", "GET")); $this->seeMiddleware("get-middleware"); } public function testCanRegisterPostRouteWithClosureAction() { $this->router->middleware("post-middleware")->post("users", function () { return "saved"; }); $this->seeResponse("saved", Request::create("users", "POST")); $this->seeMiddleware("post-middleware"); } public function testCanRegisterAnyRouteWithClosureAction() { $this->router->middleware("test-middleware")->any("users", function () { return "anything"; }); $this->seeResponse("anything", Request::create("users", "PUT")); $this->seeMiddleware("test-middleware"); } public function testCanRegisterMatchRouteWithClosureAction() { $this->router->middleware("match-middleware")->match(array("DELETE"), "users", function () { return "deleted"; }); $this->seeResponse("deleted", Request::create("users", "DELETE")); $this->seeMiddleware("match-middleware"); } public function testCanRegisterRouteWithArrayAndClosureAction() { $this->router->middleware("patch-middleware")->patch("users", array(function () { return "updated"; })); $this->seeResponse("updated", Request::create("users", "PATCH")); $this->seeMiddleware("patch-middleware"); } public function testCanRegisterRouteWithArrayAndClosureUsesAction() { $this->router->middleware("put-middleware")->put("users", array("uses" => function () { return "replaced"; })); $this->seeResponse("replaced", Request::create("users", "PUT")); $this->seeMiddleware("put-middleware"); } public function testCanRegisterRouteWithControllerAction() { $this->router->middleware("controller-middleware")->get("users", RouteRegistrarControllerStub::class . "@index"); $this->seeResponse("controller", Request::create("users", "GET")); $this->seeMiddleware("controller-middleware"); } public function testCanRegisterRouteWithControllerActionArray() { $this->router->middleware("controller-middleware")->get("users", array(RouteRegistrarControllerStub::class, "index")); $this->seeResponse("controller", Request::create("users", "GET")); $this->seeMiddleware("controller-middleware"); } public function testCanRegisterNamespacedGroupRouteWithControllerActionArray() { $this->router->group(array("namespace" => "WhatEver"), function () { $this->router->middleware("controller-middleware")->get("users", array(RouteRegistrarControllerStub::class, "index")); }); $this->seeResponse("controller", Request::create("users", "GET")); $this->seeMiddleware("controller-middleware"); $this->router->group(array("namespace" => "WhatEver"), function () { $this->router->middleware("controller-middleware")->get("users", array("\" . RouteRegistrarControllerStub::class, "index")); }); $this->seeResponse("controller", Request::create("users", "GET")); $this->seeMiddleware("controller-middleware"); } public function testCanRegisterRouteWithArrayAndControllerAction() { $this->router->middleware("controller-middleware")->put("users", array("uses" => RouteRegistrarControllerStub::class . "@index")); $this->seeResponse("controller", Request::create("users", "PUT")); $this->seeMiddleware("controller-middleware"); } public function testCanRegisterGroupWithMiddleware() { $this->router->middleware("group-middleware")->group(function ($router) { $router->get("users", function () { return "all-users"; }); }); $this->seeResponse("all-users", Request::create("users", "GET")); $this->seeMiddleware("group-middleware"); } public function testCanRegisterGroupWithoutMiddleware() { $this->router->withoutMiddleware("one")->group(function ($router) { $router->get("users", function () { return "all-users"; })->middleware(array("one", "two")); }); $this->seeResponse("all-users", Request::create("users", "GET")); $this->assertEquals(array("one"), $this->getRoute()->excludedMiddleware()); } public function testCanRegisterGroupWithStringableMiddleware() { $one = new class implements Stringable { public function __toString() { return "one"; } }; $this->router->middleware($one)->group(function ($router) { $router->get("users", function () { return "all-users"; }); }); $this->seeResponse("all-users", Request::create("users", "GET")); $this->seeMiddleware("one"); } public function testCanRegisterGroupWithNamespace() { $this->router->namespace("App\Http\Controllers")->group(function ($router) { $router->get("users", "UsersController@index"); }); $this->assertSame("App\Http\Controllers\UsersController@index", $this->getRoute()->getAction()["uses"]); } public function testCanRegisterGroupWithPrefix() { $this->router->prefix("api")->group(function ($router) { $router->get("users", "UsersController@index"); }); $this->assertSame("api/users", $this->getRoute()->uri()); } public function testCanRegisterGroupWithPrefixAndWhere() { $this->router->prefix("foo/{bar}")->where(array("bar" => "[0-9]+"))->group(function ($router) { $router->get("here", function () { return "good"; }); }); $this->seeResponse("good", Request::create("foo/12345/here", "GET")); } public function testCanRegisterGroupWithNamePrefix() { $this->router->name("api.")->group(function ($router) { $router->get("users", "UsersController@index")->name("users"); }); $this->assertSame("api.users", $this->getRoute()->getName()); } public function testCanRegisterGroupWithDomain() { $this->router->domain("{account}.myapp.com")->group(function ($router) { $router->get("users", "UsersController@index"); }); $this->assertSame("{account}.myapp.com", $this->getRoute()->getDomain()); } public function testCanRegisterGroupWithDomainAndNamePrefix() { $this->router->domain("{account}.myapp.com")->name("api.")->group(function ($router) { $router->get("users", "UsersController@index")->name("users"); }); $this->assertSame("{account}.myapp.com", $this->getRoute()->getDomain()); $this->assertSame("api.users", $this->getRoute()->getName()); } public function testCanRegisterGroupWithController() { $this->router->controller(RouteRegistrarControllerStub::class)->group(function ($router) { $router->get("users", "index"); }); $this->assertSame(RouteRegistrarControllerStub::class . "@index", $this->getRoute()->getAction()["uses"]); } public function testCanOverrideGroupControllerWithStringSyntax() { $this->router->controller(RouteRegistrarControllerStub::class)->group(function ($router) { $router->get("users", "UserController@index"); }); $this->assertSame("UserController@index", $this->getRoute()->getAction()["uses"]); } public function testCanOverrideGroupControllerWithClosureSyntax() { $this->router->controller(RouteRegistrarControllerStub::class)->group(function ($router) { $router->get("users", function () { return "hello world"; }); }); $this->seeResponse("hello world", Request::create("users", "GET")); } public function testCanOverrideGroupControllerWithInvokableControllerSyntax() { $this->router->controller(RouteRegistrarControllerStub::class)->group(function ($router) { $router->get("users", InvokableRouteRegistrarControllerStub::class); }); $this->assertSame(InvokableRouteRegistrarControllerStub::class . "@__invoke", $this->getRoute()->getAction()["uses"]); } public function testWillUseTheLatestGroupController() { $this->router->controller(RouteRegistrarControllerStub::class)->group(function ($router) { $router->group(array("controller" => FooController::class), function ($router) { $router->get("users", "index"); }); }); $this->assertSame(FooController::class . "@index", $this->getRoute()->getAction()["uses"]); } public function testCanOverrideGroupControllerWithArraySyntax() { $this->router->controller(RouteRegistrarControllerStub::class)->group(function ($router) { $router->get("users", array(FooController::class, "index")); }); $this->assertSame(FooController::class . "@index", $this->getRoute()->getAction()["uses"]); } public function testRouteGroupingWithoutPrefix() { $this->router->group(array(), function ($router) { $router->prefix("bar")->get("baz", array("as" => "baz", function () { return "hello"; })); }); $this->seeResponse("hello", Request::create("bar/baz", "GET")); } public function testRouteGroupChaining() { $this->router->group(array(), function ($router) { $router->get("foo", function () { return "hello"; }); })->group(array(), function ($router) { $router->get("bar", function () { return "goodbye"; }); }); $routeCollection = $this->router->getRoutes(); $this->assertInstanceOf(\Illuminate\Routing\Route::class, $routeCollection->match(Request::create("foo", "GET"))); $this->assertInstanceOf(\Illuminate\Routing\Route::class, $routeCollection->match(Request::create("bar", "GET"))); } public function testRegisteringNonApprovedAttributesThrows() { $this->expectException(BadMethodCallException::class); $this->expectExceptionMessage("Method Illuminate\Routing\RouteRegistrar::unsupportedMethod does not exist."); $this->router->domain("foo")->unsupportedMethod("bar")->group(function ($router) { }); } public function testCanRegisterResource() { $this->router->middleware("resource-middleware")->resource("users", RouteRegistrarControllerStub::class); $this->seeResponse("deleted", Request::create("users/1", "DELETE")); $this->seeMiddleware("resource-middleware"); } public function testCanRegisterResourcesWithExceptOption() { $this->router->resources(array("resource-one" => RouteRegistrarControllerStubOne::class, "resource-two" => RouteRegistrarControllerStubTwo::class, "resource-three" => RouteRegistrarControllerStubThree::class), array("except" => array("create", "show"))); $this->assertCount(15, $this->router->getRoutes()); foreach (array("one", "two", "three") as $resource) { $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".index")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".store")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".edit")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".update")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".destroy")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".create")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".show")); } } public function testCanRegisterResourcesWithOnlyOption() { $this->router->resources(array("resource-one" => RouteRegistrarControllerStubOne::class, "resource-two" => RouteRegistrarControllerStubTwo::class, "resource-three" => RouteRegistrarControllerStubThree::class), array("only" => array("create", "show"))); $this->assertCount(6, $this->router->getRoutes()); foreach (array("one", "two", "three") as $resource) { $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".create")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".show")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".index")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".store")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".edit")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".update")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".destroy")); } } public function testCanRegisterResourcesWithoutOption() { $this->router->resources(array("resource-one" => RouteRegistrarControllerStubOne::class, "resource-two" => RouteRegistrarControllerStubTwo::class, "resource-three" => RouteRegistrarControllerStubThree::class)); $this->assertCount(21, $this->router->getRoutes()); foreach (array("one", "two", "three") as $resource) { $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".index")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".create")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".store")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".show")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".edit")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".update")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".destroy")); } } public function testCanRegisterResourceWithMissingOption() { $this->router->middleware("resource-middleware")->resource("users", RouteRegistrarControllerStub::class)->missing(function () { return "missing"; }); $this->assertIsCallable($this->router->getRoutes()->getByName("users.show")->getMissing()); $this->assertIsCallable($this->router->getRoutes()->getByName("users.edit")->getMissing()); $this->assertIsCallable($this->router->getRoutes()->getByName("users.update")->getMissing()); $this->assertIsCallable($this->router->getRoutes()->getByName("users.destroy")->getMissing()); $this->assertNull($this->router->getRoutes()->getByName("users.index")->getMissing()); $this->assertNull($this->router->getRoutes()->getByName("users.create")->getMissing()); $this->assertNull($this->router->getRoutes()->getByName("users.store")->getMissing()); } public function testCanAccessRegisteredResourceRoutesAsRouteCollection() { $resource = $this->router->middleware("resource-middleware")->resource("users", RouteRegistrarControllerStub::class)->register(); $this->assertCount(7, $resource->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.index")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.create")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.store")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.show")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.edit")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.update")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.destroy")); } public function testCanLimitMethodsOnRegisteredResource() { $this->router->resource("users", RouteRegistrarControllerStub::class)->only("index", "show", "destroy"); $this->assertCount(3, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.index")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.show")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.destroy")); } public function testCanExcludeMethodsOnRegisteredResource() { $this->router->resource("users", RouteRegistrarControllerStub::class)->except(array("index", "create", "store", "show", "edit")); $this->assertCount(2, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.update")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.destroy")); } public function testCanLimitAndExcludeMethodsOnRegisteredResource() { $this->router->resource("users", RouteRegistrarControllerStub::class)->only("index", "show", "destroy")->except("destroy"); $this->assertCount(2, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.index")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.show")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("users.destroy")); } public function testCanSetShallowOptionOnRegisteredResource() { $this->router->resource("users.tasks", RouteRegistrarControllerStub::class)->shallow(); $this->assertCount(7, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.tasks.index")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("tasks.show")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("users.tasks.show")); } public function testCanSetScopedOptionOnRegisteredResource() { $this->router->resource("users.tasks", RouteRegistrarControllerStub::class)->scoped(); $this->assertSame(array("user" => null), $this->router->getRoutes()->getByName("users.tasks.index")->bindingFields()); $this->assertSame(array("user" => null, "task" => null), $this->router->getRoutes()->getByName("users.tasks.show")->bindingFields()); $this->router->resource("users.tasks", RouteRegistrarControllerStub::class)->scoped(array("task" => "slug")); $this->assertSame(array("user" => null), $this->router->getRoutes()->getByName("users.tasks.index")->bindingFields()); $this->assertSame(array("user" => null, "task" => "slug"), $this->router->getRoutes()->getByName("users.tasks.show")->bindingFields()); } public function testCanExcludeMethodsOnRegisteredApiResource() { $this->router->apiResource("users", RouteRegistrarControllerStub::class)->except(array("index", "show", "store")); $this->assertCount(2, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.update")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.destroy")); } public function testCanRegisterApiResourcesWithExceptOption() { $this->router->apiResources(array("resource-one" => RouteRegistrarControllerStubOne::class, "resource-two" => RouteRegistrarControllerStubTwo::class, "resource-three" => RouteRegistrarControllerStubThree::class), array("except" => array("create", "show"))); $this->assertCount(12, $this->router->getRoutes()); foreach (array("one", "two", "three") as $resource) { $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".index")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".store")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".update")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".destroy")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".create")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".show")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".edit")); } } public function testCanRegisterApiResourcesWithOnlyOption() { $this->router->apiResources(array("resource-one" => RouteRegistrarControllerStubOne::class, "resource-two" => RouteRegistrarControllerStubTwo::class, "resource-three" => RouteRegistrarControllerStubThree::class), array("only" => array("index", "show"))); $this->assertCount(6, $this->router->getRoutes()); foreach (array("one", "two", "three") as $resource) { $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".index")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".show")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".store")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".update")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".destroy")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".create")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".edit")); } } public function testCanRegisterApiResourcesWithoutOption() { $this->router->apiResources(array("resource-one" => RouteRegistrarControllerStubOne::class, "resource-two" => RouteRegistrarControllerStubTwo::class, "resource-three" => RouteRegistrarControllerStubThree::class)); $this->assertCount(15, $this->router->getRoutes()); foreach (array("one", "two", "three") as $resource) { $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".index")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".show")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".store")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".update")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".destroy")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".create")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("resource-" . $resource . ".edit")); } } public function testUserCanRegisterApiResource() { $this->router->apiResource("users", RouteRegistrarControllerStub::class); $this->assertCount(5, $this->router->getRoutes()); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("users.create")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("users.edit")); } public function testUserCanRegisterApiResourceWithExceptOption() { $this->router->apiResource("users", RouteRegistrarControllerStub::class, array("except" => array("destroy"))); $this->assertCount(4, $this->router->getRoutes()); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("users.create")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("users.edit")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("users.destroy")); } public function testUserCanRegisterApiResourceWithOnlyOption() { $this->router->apiResource("users", RouteRegistrarControllerStub::class, array("only" => array("index", "show"))); $this->assertCount(2, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.index")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("users.show")); } public function testCanNameRoutesOnRegisteredResource() { $this->router->resource("comments", RouteRegistrarControllerStub::class)->only("create", "store")->names("reply"); $this->router->resource("users", RouteRegistrarControllerStub::class)->only("create", "store")->names(array("create" => "user.build", "store" => "user.save")); $this->router->resource("posts", RouteRegistrarControllerStub::class)->only("create", "destroy")->name("create", "posts.make")->name("destroy", "posts.remove"); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("reply.create")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("reply.store")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.build")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.save")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("posts.make")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("posts.remove")); } public function testCanOverrideParametersOnRegisteredResource() { $this->router->resource("users", RouteRegistrarControllerStub::class)->parameters(array("users" => "admin_user")); $this->router->resource("posts", RouteRegistrarControllerStub::class)->parameter("posts", "topic"); $this->assertStringContainsString("admin_user", $this->router->getRoutes()->getByName("users.show")->uri); $this->assertStringContainsString("topic", $this->router->getRoutes()->getByName("posts.show")->uri); } public function testCanSetMiddlewareOnRegisteredResource() { $this->router->resource("users", RouteRegistrarControllerStub::class)->middleware(RouteRegistrarMiddlewareStub::class); $this->seeMiddleware(RouteRegistrarMiddlewareStub::class); } public function testResourceWithoutMiddlewareRegistration() { $this->router->resource("users", RouteRegistrarControllerStub::class)->only("index")->middleware(array("one", "two"))->withoutMiddleware("one"); $this->seeResponse("controller", Request::create("users", "GET")); $this->assertEquals(array("one"), $this->getRoute()->excludedMiddleware()); } public function testResourceWithMiddlewareAsStringable() { $one = new class implements Stringable { public function __toString() { return "one"; } }; $this->router->resource("users", RouteRegistrarControllerStub::class)->only("index")->middleware(array($one, "two"))->withoutMiddleware("one"); $this->seeResponse("controller", Request::create("users", "GET")); $this->assertEquals(array("one", "two"), $this->getRoute()->middleware()); $this->assertEquals(array("one"), $this->getRoute()->excludedMiddleware()); } public function testResourceWheres() { $wheres = array("user" => "\d+", "test" => "[a-z]+"); $this->router->resource("users", RouteRegistrarControllerStub::class)->where($wheres); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testWhereNumberRegistration() { $wheres = array("foo" => "[0-9]+", "bar" => "[0-9]+"); $this->router->get("/{foo}/{bar}")->whereNumber(array("foo", "bar")); $this->router->get("/api/{bar}/{foo}")->whereNumber(array("bar", "foo")); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testWhereAlphaRegistration() { $wheres = array("foo" => "[a-zA-Z]+", "bar" => "[a-zA-Z]+"); $this->router->get("/{foo}/{bar}")->whereAlpha(array("foo", "bar")); $this->router->get("/api/{bar}/{foo}")->whereAlpha(array("bar", "foo")); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testWhereAlphaNumericRegistration() { $wheres = array("1a2b3c" => "[a-zA-Z0-9]+"); $this->router->get("/{foo}")->whereAlphaNumeric(array("1a2b3c")); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testWhereInRegistration() { $wheres = array("foo" => "one|two", "bar" => "one|two"); $this->router->get("/{foo}/{bar}")->whereIn(array("foo", "bar"), array("one", "two")); $this->router->get("/api/{bar}/{foo}")->whereIn(array("bar", "foo"), array("one", "two")); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testGroupWhereNumberRegistrationOnRouteRegistrar() { $wheres = array("foo" => "[0-9]+", "bar" => "[0-9]+"); $this->router->prefix("/{foo}/{bar}")->whereNumber(array("foo", "bar"))->group(function ($router) { $router->get("/"); }); $this->router->prefix("/api/{bar}/{foo}")->whereNumber(array("bar", "foo"))->group(function ($router) { $router->get("/"); }); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testGroupWhereAlphaRegistrationOnRouteRegistrar() { $wheres = array("foo" => "[a-zA-Z]+", "bar" => "[a-zA-Z]+"); $this->router->prefix("/{foo}/{bar}")->whereAlpha(array("foo", "bar"))->group(function ($router) { $router->get("/"); }); $this->router->prefix("/api/{bar}/{foo}")->whereAlpha(array("bar", "foo"))->group(function ($router) { $router->get("/"); }); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testGroupWhereAlphaNumericRegistrationOnRouteRegistrar() { $wheres = array("1a2b3c" => "[a-zA-Z0-9]+"); $this->router->prefix("/{foo}")->whereAlphaNumeric(array("1a2b3c"))->group(function ($router) { $router->get("/"); }); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testGroupWhereInRegistrationOnRouteRegistrar() { $wheres = array("foo" => "one|two", "bar" => "one|two"); $this->router->prefix("/{foo}/{bar}")->whereIn(array("foo", "bar"), array("one", "two"))->group(function ($router) { $router->get("/"); }); $this->router->prefix("/api/{bar}/{foo}")->whereIn(array("bar", "foo"), array("one", "two"))->group(function ($router) { $router->get("/"); }); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testGroupWhereNumberRegistrationOnRouter() { $wheres = array("foo" => "[0-9]+", "bar" => "[0-9]+"); $this->router->whereNumber(array("foo", "bar"))->prefix("/{foo}/{bar}")->group(function ($router) { $router->get("/"); }); $this->router->whereNumber(array("bar", "foo"))->prefix("/api/{bar}/{foo}")->group(function ($router) { $router->get("/"); }); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testGroupWhereAlphaRegistrationOnRouter() { $wheres = array("foo" => "[a-zA-Z]+", "bar" => "[a-zA-Z]+"); $this->router->whereAlpha(array("foo", "bar"))->prefix("/{foo}/{bar}")->group(function ($router) { $router->get("/"); }); $this->router->whereAlpha(array("bar", "foo"))->prefix("/api/{bar}/{foo}")->group(function ($router) { $router->get("/"); }); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testGroupWhereAlphaNumericRegistrationOnRouter() { $wheres = array("1a2b3c" => "[a-zA-Z0-9]+"); $this->router->whereAlphaNumeric(array("1a2b3c"))->prefix("/{foo}")->group(function ($router) { $router->get("/"); }); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testGroupWhereInRegistrationOnRouter() { $wheres = array("foo" => "one|two", "bar" => "one|two"); $this->router->whereIn(array("foo", "bar"), array("one", "two"))->prefix("/{foo}/{bar}")->group(function ($router) { $router->get("/"); }); $this->router->whereIn(array("bar", "foo"), array("one", "two"))->prefix("/api/{bar}/{foo}")->group(function ($router) { $router->get("/"); }); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testCanSetRouteName() { $this->router->as("users.index")->get("users", function () { return "all-users"; }); $this->seeResponse("all-users", Request::create("users", "GET")); $this->assertSame("users.index", $this->getRoute()->getName()); } public function testCanSetRouteNameUsingNameAlias() { $this->router->name("users.index")->get("users", function () { return "all-users"; }); $this->seeResponse("all-users", Request::create("users", "GET")); $this->assertSame("users.index", $this->getRoute()->getName()); } public function testPushMiddlewareToGroup() { $this->router->middlewareGroup("web", array()); $this->router->pushMiddlewareToGroup("web", "test-middleware"); $this->assertEquals(array("test-middleware"), $this->router->getMiddlewareGroups()["web"]); } public function testPushMiddlewareToGroupUnregisteredGroup() { $this->router->pushMiddlewareToGroup("web", "test-middleware"); $this->assertEquals(array("test-middleware"), $this->router->getMiddlewareGroups()["web"]); } public function testPushMiddlewareToGroupDuplicatedMiddleware() { $this->router->pushMiddlewareToGroup("web", "test-middleware"); $this->router->pushMiddlewareToGroup("web", "test-middleware"); $this->assertEquals(array("test-middleware"), $this->router->getMiddlewareGroups()["web"]); } public function testCanRemoveMiddlewareFromGroup() { $this->router->pushMiddlewareToGroup("web", "test-middleware"); $this->router->removeMiddlewareFromGroup("web", "test-middleware"); $this->assertEquals(array(), $this->router->getMiddlewareGroups()["web"]); } public function testCanRemoveMiddlewareFromGroupNotUnregisteredMiddleware() { $this->router->middlewareGroup("web", array()); $this->router->removeMiddlewareFromGroup("web", "different-test-middleware"); $this->assertEquals(array(), $this->router->getMiddlewareGroups()["web"]); } public function testCanRemoveMiddlewareFromGroupUnregisteredGroup() { $this->router->removeMiddlewareFromGroup("web", array("test-middleware")); $this->assertEquals(array(), $this->router->getMiddlewareGroups()); } public function testCanRegisterSingleton() { $this->router->singleton("user", RouteRegistrarControllerStub::class); $this->assertCount(3, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.show")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.edit")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.update")); } public function testCanRegisterApiSingleton() { $this->router->apiSingleton("user", RouteRegistrarControllerStub::class); $this->assertCount(2, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.show")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.update")); } public function testCanRegisterCreatableSingleton() { $this->router->singleton("user", RouteRegistrarControllerStub::class)->creatable(); $this->assertCount(6, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.create")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.store")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.show")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.edit")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.update")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.destroy")); } public function testCanRegisterCreatableApiSingleton() { $this->router->apiSingleton("user", RouteRegistrarControllerStub::class)->creatable(); $this->assertCount(4, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.store")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.show")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.update")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.destroy")); } public function testSingletonCreatableNotDestroyable() { $this->router->singleton("user", RouteRegistrarControllerStub::class)->creatable()->except("destroy"); $this->assertCount(5, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.create")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.store")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.show")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.edit")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.update")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("user.destroy")); } public function testApiSingletonCreatableNotDestroyable() { $this->router->apiSingleton("user", RouteRegistrarControllerStub::class)->creatable()->except("destroy"); $this->assertCount(3, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.store")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.show")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.update")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("user.destroy")); } public function testSingletonCanBeDestroyable() { $this->router->singleton("user", RouteRegistrarControllerStub::class)->destroyable(); $this->assertCount(4, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.show")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.edit")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.update")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.destroy")); } public function testApiSingletonCanBeDestroyable() { $this->router->apiSingleton("user", RouteRegistrarControllerStub::class)->destroyable(); $this->assertCount(3, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.show")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.update")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.destroy")); } public function testSingletonCanBeOnlyCreatable() { $this->router->singleton("user", RouteRegistrarControllerStub::class)->creatable()->only("create", "store"); $this->assertCount(2, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.create")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.store")); } public function testApiSingletonCanBeOnlyCreatable() { $this->router->apiSingleton("user", RouteRegistrarControllerStub::class)->creatable()->only("store"); $this->assertCount(1, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.store")); } public function testSingletonDoesntAllowIncludingUnsupportedMethods() { $this->router->singleton("post", RouteRegistrarControllerStub::class)->only("index", "store", "create", "destroy"); $this->assertCount(0, $this->router->getRoutes()); $this->router->apiSingleton("user", RouteRegistrarControllerStub::class)->only("index", "store", "create", "destroy"); $this->assertCount(0, $this->router->getRoutes()); } public function testApiSingletonCanIncludeAnySingletonMethods() { $this->router->apiSingleton("user", RouteRegistrarControllerStub::class)->only("edit"); $this->assertCount(1, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("user.edit")); } protected function getRoute() { return last($this->router->getRoutes()->get()); } protected function seeMiddleware($middleware) { $this->assertEquals($middleware, $this->getRoute()->middleware()[0]); } protected function seeResponse($content, Request $request) { $route = $this->getRoute(); $this->assertTrue($route->matches($request)); $this->assertEquals($content, $route->bind($request)->run()); } } class RouteRegistrarControllerStub { public function index() { return "controller"; } public function destroy() { return "deleted"; } } class InvokableRouteRegistrarControllerStub { public function __invoke() { return "controller"; } } class RouteRegistrarMiddlewareStub { } ?>

Did this file decode correctly?

Original Code

<?php
 namespace Illuminate\Tests\Routing; use BadMethodCallException; use FooController; use Illuminate\Container\Container; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Http\Request; use Illuminate\Routing\Router; use Mockery as m; use PHPUnit\Framework\TestCase; use Stringable; class RouteRegistrarTest extends TestCase { protected $router; protected function setUp() : void { parent::setUp(); $this->router = new Router(m::mock(Dispatcher::class), Container::getInstance()); } protected function tearDown() : void { m::close(); } public function testMiddlewareFluentRegistration() { $this->router->middleware(array("\157\x6e\x65", "\x74\x77\x6f"))->get("\165\x73\145\x72\x73", function () { return "\x61\x6c\x6c\55\x75\x73\145\162\x73"; }); $this->seeResponse("\141\x6c\x6c\55\x75\x73\x65\x72\x73", Request::create("\x75\x73\x65\x72\163", "\107\x45\124")); $this->assertEquals(array("\x6f\x6e\x65", "\164\167\157"), $this->getRoute()->middleware()); $this->router->middleware("\164\x68\162\x65\145", "\146\157\165\162")->get("\165\x73\x65\162\163", function () { return "\141\x6c\154\x2d\x75\163\x65\162\x73"; }); $this->seeResponse("\141\x6c\x6c\55\x75\163\x65\162\x73", Request::create("\x75\x73\145\x72\163", "\107\105\x54")); $this->assertEquals(array("\164\x68\162\145\x65", "\146\x6f\x75\x72"), $this->getRoute()->middleware()); $this->router->get("\x75\x73\145\x72\x73", function () { return "\x61\154\x6c\55\x75\163\145\162\163"; })->middleware("\x66\x69\166\145", "\x73\x69\170"); $this->seeResponse("\141\x6c\154\x2d\165\x73\145\x72\163", Request::create("\x75\163\145\x72\x73", "\x47\105\x54")); $this->assertEquals(array("\146\151\x76\x65", "\163\151\170"), $this->getRoute()->middleware()); $this->router->middleware("\163\145\166\145\156")->get("\165\163\x65\x72\x73", function () { return "\141\154\154\55\x75\x73\145\x72\x73"; }); $this->seeResponse("\141\x6c\x6c\55\x75\x73\x65\x72\163", Request::create("\x75\x73\145\162\x73", "\x47\105\124")); $this->assertEquals(array("\x73\x65\x76\x65\156"), $this->getRoute()->middleware()); } public function testNullNamespaceIsRespected() { $this->router->middleware(array("\x6f\x6e\x65"))->namespace(null)->get("\165\x73\x65\x72\x73", function () { return "\141\154\x6c\x2d\x75\x73\x65\162\x73"; }); $this->assertNull($this->getRoute()->getAction()["\x6e\x61\x6d\x65\x73\x70\x61\x63\x65"]); } public function testMiddlewareAsStringableObject() { $one = new class implements Stringable { public function __toString() { return "\157\x6e\145"; } }; $this->router->middleware($one)->get("\x75\163\145\x72\x73", function () { return "\x61\154\154\55\165\x73\145\162\163"; }); $this->seeResponse("\141\x6c\154\x2d\x75\163\145\162\163", Request::create("\x75\x73\145\162\x73", "\x47\x45\124")); $this->assertSame(array("\x6f\156\145"), $this->getRoute()->middleware()); } public function testMiddlewareAsStringableObjectOnRouteInstance() { $one = new class implements Stringable { public function __toString() { return "\157\156\x65"; } }; $this->router->get("\165\x73\x65\162\x73", function () { return "\x61\x6c\154\55\165\x73\x65\x72\163"; })->middleware($one); $this->seeResponse("\x61\x6c\x6c\x2d\x75\x73\145\162\x73", Request::create("\x75\x73\x65\x72\x73", "\x47\105\x54")); $this->assertSame(array("\157\156\145"), $this->getRoute()->middleware()); } public function testMiddlewareAsArrayWithStringables() { $one = new class implements Stringable { public function __toString() { return "\157\156\145"; } }; $this->router->middleware(array($one, "\164\167\157"))->get("\x75\163\x65\x72\163", function () { return "\x61\154\154\55\165\163\x65\162\163"; }); $this->seeResponse("\x61\x6c\154\55\x75\163\145\x72\x73", Request::create("\x75\x73\x65\x72\163", "\x47\105\124")); $this->assertSame(array("\x6f\x6e\145", "\x74\167\157"), $this->getRoute()->middleware()); } public function testWithoutMiddlewareRegistration() { $this->router->middleware(array("\x6f\156\x65", "\164\167\157"))->get("\165\163\x65\x72\x73", function () { return "\x61\x6c\x6c\x2d\x75\163\x65\162\x73"; })->withoutMiddleware("\157\x6e\x65"); $this->seeResponse("\141\154\x6c\55\x75\x73\145\x72\x73", Request::create("\x75\x73\145\x72\163", "\x47\105\x54")); $this->assertEquals(array("\x6f\x6e\x65"), $this->getRoute()->excludedMiddleware()); } public function testGetRouteWithTrashed() { $route = $this->router->get("\165\163\x65\162\163", array(RouteRegistrarControllerStub::class, "\151\x6e\x64\x65\x78"))->withTrashed(); $this->assertTrue($route->allowsTrashedBindings()); } public function testResourceWithTrashed() { $this->router->resource("\165\163\x65\x72\163", RouteRegistrarControllerStub::class)->only(array("\x69\156\144\145\170", "\x64\x65\163\164\162\x6f\x79"))->withTrashed(array("\151\x6e\144\145\170", "\x64\x65\x73\x74\x72\x6f\171")); foreach ($this->router->getRoutes() as $route) { $this->assertTrue($route->allowsTrashedBindings()); } } public function testFallbackRoute() { $route = $this->router->fallback(function () { return "\x6d\151\154\167\141\144"; }); $this->assertTrue($route->isFallback); } public function testSetFallbackRoute() { $route = $this->router->fallback(function () { return "\x6d\151\154\x77\141\144"; }); $route->setFallback(false); $this->assertFalse($route->isFallback); $route->setFallback(true); $this->assertTrue($route->isFallback); } public function testCanRegisterGetRouteWithClosureAction() { $this->router->middleware("\147\145\164\55\155\151\x64\x64\x6c\x65\167\x61\162\145")->get("\165\163\145\x72\163", function () { return "\141\154\x6c\55\165\163\x65\x72\163"; }); $this->seeResponse("\141\154\x6c\x2d\x75\163\x65\162\x73", Request::create("\165\x73\145\162\x73", "\107\105\124")); $this->seeMiddleware("\x67\145\164\x2d\x6d\151\x64\x64\x6c\x65\167\x61\162\145"); } public function testCanRegisterPostRouteWithClosureAction() { $this->router->middleware("\160\x6f\163\x74\x2d\x6d\x69\144\x64\154\145\167\x61\162\x65")->post("\165\x73\145\162\x73", function () { return "\x73\x61\x76\145\x64"; }); $this->seeResponse("\x73\141\166\x65\144", Request::create("\x75\163\x65\162\163", "\x50\x4f\123\x54")); $this->seeMiddleware("\x70\157\163\164\55\155\151\x64\144\x6c\x65\x77\x61\162\x65"); } public function testCanRegisterAnyRouteWithClosureAction() { $this->router->middleware("\x74\145\163\164\x2d\x6d\x69\144\x64\154\145\167\141\162\x65")->any("\x75\x73\x65\x72\x73", function () { return "\141\156\171\x74\x68\151\x6e\x67"; }); $this->seeResponse("\141\156\x79\164\x68\x69\x6e\147", Request::create("\x75\163\x65\162\x73", "\120\125\x54")); $this->seeMiddleware("\x74\145\163\x74\55\x6d\x69\144\x64\x6c\x65\x77\x61\x72\x65"); } public function testCanRegisterMatchRouteWithClosureAction() { $this->router->middleware("\155\141\x74\143\x68\55\x6d\x69\144\144\x6c\x65\167\x61\x72\x65")->match(array("\104\x45\x4c\105\124\x45"), "\165\163\x65\162\x73", function () { return "\x64\x65\154\145\x74\x65\x64"; }); $this->seeResponse("\x64\145\x6c\145\164\x65\x64", Request::create("\165\163\x65\162\163", "\104\x45\x4c\105\x54\105")); $this->seeMiddleware("\155\141\x74\143\x68\x2d\x6d\151\144\x64\x6c\x65\167\x61\162\145"); } public function testCanRegisterRouteWithArrayAndClosureAction() { $this->router->middleware("\160\141\x74\143\x68\x2d\155\151\144\x64\154\145\x77\141\162\x65")->patch("\x75\x73\145\162\x73", array(function () { return "\x75\160\x64\141\x74\145\x64"; })); $this->seeResponse("\x75\x70\144\141\x74\x65\x64", Request::create("\x75\163\x65\x72\x73", "\120\x41\124\103\110")); $this->seeMiddleware("\160\141\x74\143\x68\55\x6d\151\x64\x64\x6c\x65\167\141\162\145"); } public function testCanRegisterRouteWithArrayAndClosureUsesAction() { $this->router->middleware("\160\x75\164\x2d\x6d\151\x64\144\x6c\x65\167\141\x72\145")->put("\x75\163\145\x72\163", array("\165\163\x65\163" => function () { return "\x72\145\160\154\x61\143\x65\x64"; })); $this->seeResponse("\162\x65\x70\x6c\141\143\145\x64", Request::create("\x75\x73\145\x72\163", "\120\125\124")); $this->seeMiddleware("\160\x75\x74\55\155\151\x64\144\154\145\x77\x61\162\x65"); } public function testCanRegisterRouteWithControllerAction() { $this->router->middleware("\143\157\x6e\x74\162\157\154\154\145\162\x2d\155\x69\144\x64\154\145\x77\141\162\x65")->get("\x75\163\x65\x72\x73", RouteRegistrarControllerStub::class . "\x40\x69\156\144\x65\x78"); $this->seeResponse("\x63\x6f\156\x74\x72\x6f\x6c\154\145\x72", Request::create("\165\x73\x65\162\163", "\107\105\124")); $this->seeMiddleware("\143\157\x6e\164\162\x6f\154\x6c\145\x72\55\155\151\x64\144\x6c\x65\167\141\162\x65"); } public function testCanRegisterRouteWithControllerActionArray() { $this->router->middleware("\143\x6f\156\164\162\157\154\x6c\x65\x72\x2d\x6d\x69\144\x64\154\x65\x77\x61\x72\145")->get("\165\163\145\x72\163", array(RouteRegistrarControllerStub::class, "\x69\x6e\x64\x65\x78")); $this->seeResponse("\x63\x6f\x6e\164\162\157\x6c\x6c\x65\x72", Request::create("\x75\x73\x65\162\x73", "\x47\105\x54")); $this->seeMiddleware("\143\157\x6e\164\162\x6f\x6c\x6c\145\162\55\155\x69\144\144\x6c\145\167\x61\162\x65"); } public function testCanRegisterNamespacedGroupRouteWithControllerActionArray() { $this->router->group(array("\156\141\x6d\x65\x73\x70\141\x63\x65" => "\127\x68\141\164\x45\x76\145\x72"), function () { $this->router->middleware("\143\157\156\164\162\x6f\154\154\x65\x72\55\155\x69\144\144\154\x65\x77\x61\162\x65")->get("\165\163\145\162\x73", array(RouteRegistrarControllerStub::class, "\151\x6e\144\x65\170")); }); $this->seeResponse("\x63\x6f\x6e\x74\162\x6f\154\154\145\162", Request::create("\x75\163\x65\x72\x73", "\x47\105\124")); $this->seeMiddleware("\143\x6f\x6e\164\x72\157\154\x6c\145\162\x2d\155\151\x64\x64\154\x65\167\141\x72\x65"); $this->router->group(array("\156\x61\155\x65\163\x70\x61\143\145" => "\127\150\141\164\x45\166\x65\162"), function () { $this->router->middleware("\143\x6f\156\164\x72\x6f\154\x6c\x65\162\x2d\155\151\144\144\x6c\x65\167\141\x72\145")->get("\165\x73\x65\x72\163", array("\134" . RouteRegistrarControllerStub::class, "\x69\x6e\144\x65\170")); }); $this->seeResponse("\143\x6f\x6e\164\x72\x6f\x6c\154\x65\162", Request::create("\165\x73\145\162\163", "\107\105\x54")); $this->seeMiddleware("\x63\x6f\156\x74\x72\x6f\x6c\x6c\x65\162\x2d\x6d\151\144\144\x6c\x65\167\x61\162\145"); } public function testCanRegisterRouteWithArrayAndControllerAction() { $this->router->middleware("\143\x6f\x6e\x74\x72\x6f\154\x6c\x65\x72\55\x6d\151\144\144\x6c\145\x77\x61\x72\145")->put("\x75\163\145\x72\163", array("\x75\x73\x65\x73" => RouteRegistrarControllerStub::class . "\x40\x69\156\x64\145\170")); $this->seeResponse("\x63\157\156\x74\162\157\154\154\x65\162", Request::create("\x75\163\x65\162\x73", "\x50\x55\x54")); $this->seeMiddleware("\x63\x6f\x6e\x74\162\x6f\x6c\154\x65\x72\x2d\x6d\x69\144\144\154\145\x77\x61\162\x65"); } public function testCanRegisterGroupWithMiddleware() { $this->router->middleware("\x67\162\x6f\165\160\55\155\x69\x64\x64\x6c\x65\167\141\x72\145")->group(function ($router) { $router->get("\x75\x73\145\x72\x73", function () { return "\x61\154\154\55\x75\x73\x65\x72\163"; }); }); $this->seeResponse("\x61\154\x6c\x2d\x75\163\145\x72\x73", Request::create("\x75\x73\145\162\163", "\107\105\124")); $this->seeMiddleware("\147\x72\157\165\x70\55\155\151\144\144\154\x65\167\x61\162\145"); } public function testCanRegisterGroupWithoutMiddleware() { $this->router->withoutMiddleware("\157\156\x65")->group(function ($router) { $router->get("\165\x73\x65\162\163", function () { return "\x61\x6c\154\55\165\x73\145\x72\x73"; })->middleware(array("\157\x6e\145", "\164\x77\157")); }); $this->seeResponse("\x61\154\x6c\x2d\x75\163\145\162\163", Request::create("\165\163\x65\162\x73", "\x47\105\124")); $this->assertEquals(array("\157\156\x65"), $this->getRoute()->excludedMiddleware()); } public function testCanRegisterGroupWithStringableMiddleware() { $one = new class implements Stringable { public function __toString() { return "\157\x6e\x65"; } }; $this->router->middleware($one)->group(function ($router) { $router->get("\x75\163\x65\162\x73", function () { return "\x61\154\154\55\165\163\145\162\x73"; }); }); $this->seeResponse("\141\154\154\x2d\165\x73\145\162\x73", Request::create("\x75\x73\x65\x72\x73", "\x47\105\x54")); $this->seeMiddleware("\x6f\156\145"); } public function testCanRegisterGroupWithNamespace() { $this->router->namespace("\x41\x70\160\x5c\110\164\164\160\134\x43\157\x6e\x74\x72\157\x6c\x6c\145\x72\163")->group(function ($router) { $router->get("\165\163\x65\x72\x73", "\x55\163\145\162\x73\103\157\x6e\x74\x72\x6f\x6c\x6c\x65\x72\x40\151\x6e\x64\x65\170"); }); $this->assertSame("\x41\160\160\x5c\x48\x74\x74\x70\134\x43\x6f\156\x74\x72\157\154\x6c\x65\162\163\134\125\x73\145\162\x73\x43\x6f\156\164\162\x6f\x6c\154\145\x72\100\x69\x6e\144\145\x78", $this->getRoute()->getAction()["\x75\x73\x65\x73"]); } public function testCanRegisterGroupWithPrefix() { $this->router->prefix("\141\160\x69")->group(function ($router) { $router->get("\165\x73\145\162\x73", "\x55\x73\145\162\x73\x43\x6f\x6e\x74\x72\x6f\154\154\145\x72\x40\151\156\x64\145\170"); }); $this->assertSame("\x61\160\x69\x2f\165\163\145\162\x73", $this->getRoute()->uri()); } public function testCanRegisterGroupWithPrefixAndWhere() { $this->router->prefix("\146\157\x6f\57\x7b\x62\141\162\x7d")->where(array("\142\x61\162" => "\x5b\60\55\x39\135\x2b"))->group(function ($router) { $router->get("\x68\145\x72\145", function () { return "\147\157\157\x64"; }); }); $this->seeResponse("\x67\x6f\x6f\x64", Request::create("\146\157\157\57\61\62\63\x34\65\x2f\x68\145\x72\x65", "\x47\x45\124")); } public function testCanRegisterGroupWithNamePrefix() { $this->router->name("\141\160\x69\56")->group(function ($router) { $router->get("\x75\163\x65\162\x73", "\125\163\x65\162\163\103\157\156\x74\162\x6f\154\x6c\x65\162\x40\151\x6e\x64\x65\x78")->name("\165\163\x65\162\x73"); }); $this->assertSame("\x61\160\151\56\165\163\x65\x72\163", $this->getRoute()->getName()); } public function testCanRegisterGroupWithDomain() { $this->router->domain("\173\141\x63\x63\x6f\x75\x6e\x74\x7d\56\155\x79\x61\160\x70\56\x63\157\155")->group(function ($router) { $router->get("\x75\163\x65\x72\x73", "\x55\x73\145\x72\163\103\x6f\x6e\164\162\157\x6c\x6c\x65\x72\100\151\156\x64\x65\x78"); }); $this->assertSame("\173\141\143\x63\x6f\x75\156\x74\175\x2e\155\171\141\x70\160\56\143\x6f\x6d", $this->getRoute()->getDomain()); } public function testCanRegisterGroupWithDomainAndNamePrefix() { $this->router->domain("\x7b\x61\x63\x63\157\165\x6e\x74\175\x2e\155\x79\x61\160\x70\56\x63\157\x6d")->name("\141\160\151\x2e")->group(function ($router) { $router->get("\x75\x73\145\162\163", "\125\x73\x65\x72\x73\x43\157\x6e\x74\x72\157\154\154\x65\162\100\x69\156\144\x65\170")->name("\x75\163\x65\x72\x73"); }); $this->assertSame("\173\141\143\143\x6f\x75\x6e\164\x7d\56\155\x79\141\x70\x70\x2e\143\x6f\155", $this->getRoute()->getDomain()); $this->assertSame("\141\160\151\56\165\163\x65\162\x73", $this->getRoute()->getName()); } public function testCanRegisterGroupWithController() { $this->router->controller(RouteRegistrarControllerStub::class)->group(function ($router) { $router->get("\165\x73\145\x72\163", "\x69\156\144\x65\170"); }); $this->assertSame(RouteRegistrarControllerStub::class . "\100\x69\156\144\145\x78", $this->getRoute()->getAction()["\165\163\x65\x73"]); } public function testCanOverrideGroupControllerWithStringSyntax() { $this->router->controller(RouteRegistrarControllerStub::class)->group(function ($router) { $router->get("\x75\x73\145\162\x73", "\125\163\145\162\103\157\x6e\x74\162\x6f\x6c\x6c\145\162\100\151\x6e\144\x65\x78"); }); $this->assertSame("\125\163\145\x72\x43\x6f\156\x74\162\157\154\154\x65\162\x40\x69\156\x64\145\170", $this->getRoute()->getAction()["\x75\163\145\x73"]); } public function testCanOverrideGroupControllerWithClosureSyntax() { $this->router->controller(RouteRegistrarControllerStub::class)->group(function ($router) { $router->get("\165\163\145\x72\x73", function () { return "\x68\x65\154\x6c\x6f\x20\167\x6f\x72\154\144"; }); }); $this->seeResponse("\x68\145\x6c\x6c\x6f\x20\x77\157\162\x6c\x64", Request::create("\165\163\145\162\163", "\107\x45\124")); } public function testCanOverrideGroupControllerWithInvokableControllerSyntax() { $this->router->controller(RouteRegistrarControllerStub::class)->group(function ($router) { $router->get("\x75\163\145\162\163", InvokableRouteRegistrarControllerStub::class); }); $this->assertSame(InvokableRouteRegistrarControllerStub::class . "\100\137\137\151\156\x76\157\x6b\x65", $this->getRoute()->getAction()["\165\x73\145\163"]); } public function testWillUseTheLatestGroupController() { $this->router->controller(RouteRegistrarControllerStub::class)->group(function ($router) { $router->group(array("\x63\x6f\156\x74\x72\x6f\x6c\x6c\145\162" => FooController::class), function ($router) { $router->get("\x75\163\145\162\163", "\151\156\144\145\170"); }); }); $this->assertSame(FooController::class . "\100\151\156\144\x65\x78", $this->getRoute()->getAction()["\165\x73\145\163"]); } public function testCanOverrideGroupControllerWithArraySyntax() { $this->router->controller(RouteRegistrarControllerStub::class)->group(function ($router) { $router->get("\165\x73\x65\162\x73", array(FooController::class, "\x69\x6e\x64\145\x78")); }); $this->assertSame(FooController::class . "\100\x69\x6e\144\x65\170", $this->getRoute()->getAction()["\x75\163\x65\163"]); } public function testRouteGroupingWithoutPrefix() { $this->router->group(array(), function ($router) { $router->prefix("\x62\141\x72")->get("\x62\141\172", array("\141\x73" => "\142\141\172", function () { return "\150\145\154\154\157"; })); }); $this->seeResponse("\x68\x65\154\154\157", Request::create("\142\x61\x72\57\142\x61\x7a", "\107\x45\x54")); } public function testRouteGroupChaining() { $this->router->group(array(), function ($router) { $router->get("\146\157\x6f", function () { return "\150\145\154\154\x6f"; }); })->group(array(), function ($router) { $router->get("\142\141\x72", function () { return "\x67\157\157\144\142\171\145"; }); }); $routeCollection = $this->router->getRoutes(); $this->assertInstanceOf(\Illuminate\Routing\Route::class, $routeCollection->match(Request::create("\146\x6f\x6f", "\x47\x45\124"))); $this->assertInstanceOf(\Illuminate\Routing\Route::class, $routeCollection->match(Request::create("\x62\141\162", "\x47\105\x54"))); } public function testRegisteringNonApprovedAttributesThrows() { $this->expectException(BadMethodCallException::class); $this->expectExceptionMessage("\x4d\x65\164\150\x6f\x64\x20\x49\x6c\154\x75\x6d\151\x6e\x61\x74\145\x5c\x52\157\x75\164\x69\156\x67\134\x52\157\x75\x74\x65\122\145\147\151\163\x74\162\141\x72\x3a\72\165\156\x73\165\160\x70\x6f\x72\x74\145\x64\115\145\x74\150\x6f\x64\40\144\157\145\x73\x20\x6e\x6f\164\x20\145\x78\151\163\x74\x2e"); $this->router->domain("\146\157\157")->unsupportedMethod("\142\141\x72")->group(function ($router) { }); } public function testCanRegisterResource() { $this->router->middleware("\x72\x65\x73\x6f\x75\x72\x63\x65\55\155\151\144\144\x6c\145\167\x61\162\x65")->resource("\x75\x73\145\x72\163", RouteRegistrarControllerStub::class); $this->seeResponse("\144\145\x6c\145\x74\x65\144", Request::create("\165\163\x65\162\163\57\61", "\x44\x45\x4c\x45\124\x45")); $this->seeMiddleware("\x72\145\x73\157\165\162\143\x65\55\155\151\144\x64\x6c\x65\167\x61\x72\145"); } public function testCanRegisterResourcesWithExceptOption() { $this->router->resources(array("\x72\145\163\157\x75\x72\x63\145\x2d\x6f\156\145" => RouteRegistrarControllerStubOne::class, "\162\x65\163\x6f\165\162\x63\145\x2d\x74\x77\157" => RouteRegistrarControllerStubTwo::class, "\162\145\163\x6f\x75\162\143\x65\x2d\x74\150\162\x65\x65" => RouteRegistrarControllerStubThree::class), array("\145\170\x63\x65\x70\x74" => array("\x63\162\x65\141\x74\x65", "\163\150\157\x77"))); $this->assertCount(15, $this->router->getRoutes()); foreach (array("\x6f\x6e\145", "\164\167\x6f", "\164\x68\162\x65\145") as $resource) { $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\162\145\x73\x6f\x75\x72\x63\145\x2d" . $resource . "\x2e\151\156\x64\145\170")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\162\x65\163\x6f\165\x72\143\145\55" . $resource . "\56\163\164\x6f\162\145")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x72\x65\163\x6f\x75\x72\143\x65\x2d" . $resource . "\x2e\x65\144\151\x74")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\162\x65\x73\x6f\x75\x72\x63\x65\55" . $resource . "\x2e\165\x70\144\x61\x74\x65")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\162\x65\163\157\x75\x72\143\x65\x2d" . $resource . "\x2e\144\145\163\164\x72\157\x79")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\162\145\163\157\165\162\143\x65\55" . $resource . "\x2e\x63\162\x65\x61\x74\145")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\162\145\x73\157\165\x72\x63\145\x2d" . $resource . "\x2e\x73\x68\157\167")); } } public function testCanRegisterResourcesWithOnlyOption() { $this->router->resources(array("\162\145\163\x6f\165\162\x63\x65\x2d\x6f\156\x65" => RouteRegistrarControllerStubOne::class, "\162\x65\x73\157\165\x72\x63\145\55\x74\x77\157" => RouteRegistrarControllerStubTwo::class, "\x72\x65\163\x6f\x75\162\143\145\x2d\x74\150\x72\145\x65" => RouteRegistrarControllerStubThree::class), array("\157\156\154\x79" => array("\143\162\x65\x61\x74\x65", "\x73\x68\157\x77"))); $this->assertCount(6, $this->router->getRoutes()); foreach (array("\x6f\156\x65", "\164\x77\157", "\x74\x68\x72\x65\145") as $resource) { $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x72\145\x73\157\165\162\x63\145\x2d" . $resource . "\56\143\x72\145\141\x74\x65")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x72\145\x73\x6f\165\x72\143\x65\55" . $resource . "\x2e\x73\150\157\167")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\162\x65\163\157\165\162\x63\x65\x2d" . $resource . "\56\x69\x6e\144\145\x78")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\162\145\x73\157\165\162\x63\x65\x2d" . $resource . "\56\163\164\x6f\162\x65")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\162\x65\x73\x6f\165\162\x63\145\55" . $resource . "\56\145\x64\151\164")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\162\145\163\157\x75\162\x63\x65\x2d" . $resource . "\x2e\x75\160\x64\141\164\x65")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\x72\145\x73\x6f\x75\162\x63\145\x2d" . $resource . "\x2e\x64\x65\163\x74\162\x6f\x79")); } } public function testCanRegisterResourcesWithoutOption() { $this->router->resources(array("\x72\145\163\x6f\165\x72\143\145\x2d\x6f\156\x65" => RouteRegistrarControllerStubOne::class, "\x72\x65\x73\x6f\x75\162\143\145\55\164\167\157" => RouteRegistrarControllerStubTwo::class, "\x72\145\x73\x6f\165\x72\x63\x65\x2d\x74\150\x72\145\x65" => RouteRegistrarControllerStubThree::class)); $this->assertCount(21, $this->router->getRoutes()); foreach (array("\x6f\156\145", "\x74\167\157", "\164\x68\x72\x65\145") as $resource) { $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x72\x65\x73\157\165\162\143\x65\55" . $resource . "\56\x69\x6e\144\145\x78")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\162\145\x73\157\165\x72\143\x65\x2d" . $resource . "\56\143\162\x65\141\x74\x65")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\162\145\163\x6f\x75\162\x63\x65\x2d" . $resource . "\56\163\164\x6f\x72\x65")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x72\145\163\x6f\165\162\143\145\x2d" . $resource . "\x2e\163\150\157\167")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x72\x65\x73\157\165\x72\143\145\x2d" . $resource . "\56\x65\x64\x69\164")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\162\x65\x73\x6f\x75\162\143\145\55" . $resource . "\x2e\x75\x70\x64\141\x74\x65")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\162\145\x73\x6f\165\162\143\x65\55" . $resource . "\56\144\x65\163\x74\x72\157\171")); } } public function testCanRegisterResourceWithMissingOption() { $this->router->middleware("\162\145\163\157\x75\x72\x63\145\55\x6d\x69\144\144\x6c\x65\167\141\x72\x65")->resource("\165\x73\145\x72\163", RouteRegistrarControllerStub::class)->missing(function () { return "\155\x69\163\163\151\156\x67"; }); $this->assertIsCallable($this->router->getRoutes()->getByName("\x75\x73\145\x72\163\56\x73\x68\x6f\x77")->getMissing()); $this->assertIsCallable($this->router->getRoutes()->getByName("\x75\163\x65\x72\x73\x2e\145\x64\151\164")->getMissing()); $this->assertIsCallable($this->router->getRoutes()->getByName("\165\x73\x65\x72\x73\x2e\165\160\144\141\164\145")->getMissing()); $this->assertIsCallable($this->router->getRoutes()->getByName("\165\x73\x65\x72\163\x2e\x64\145\163\164\162\x6f\x79")->getMissing()); $this->assertNull($this->router->getRoutes()->getByName("\x75\x73\x65\162\163\x2e\151\156\144\x65\x78")->getMissing()); $this->assertNull($this->router->getRoutes()->getByName("\x75\163\x65\162\x73\x2e\x63\x72\x65\x61\x74\145")->getMissing()); $this->assertNull($this->router->getRoutes()->getByName("\165\163\145\x72\163\x2e\163\164\x6f\x72\x65")->getMissing()); } public function testCanAccessRegisteredResourceRoutesAsRouteCollection() { $resource = $this->router->middleware("\162\145\x73\157\x75\162\x63\x65\x2d\155\x69\x64\144\x6c\145\167\x61\162\145")->resource("\165\163\x65\162\163", RouteRegistrarControllerStub::class)->register(); $this->assertCount(7, $resource->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\x73\145\x72\163\56\151\x6e\x64\x65\x78")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\x73\x65\x72\163\56\x63\x72\145\x61\x74\145")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\163\145\162\x73\x2e\163\164\x6f\x72\x65")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\163\x65\162\163\x2e\163\150\157\x77")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\x73\x65\162\x73\x2e\145\144\x69\164")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\x73\x65\x72\x73\x2e\165\x70\144\141\164\145")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\x73\x65\x72\163\x2e\x64\145\163\164\162\x6f\x79")); } public function testCanLimitMethodsOnRegisteredResource() { $this->router->resource("\x75\163\x65\x72\163", RouteRegistrarControllerStub::class)->only("\151\x6e\144\x65\170", "\x73\x68\157\x77", "\x64\145\x73\x74\162\157\171"); $this->assertCount(3, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\x73\x65\x72\163\x2e\x69\156\144\x65\170")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\x73\x65\162\163\x2e\163\150\x6f\x77")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\x73\145\162\x73\56\x64\145\163\x74\x72\x6f\x79")); } public function testCanExcludeMethodsOnRegisteredResource() { $this->router->resource("\x75\x73\x65\162\x73", RouteRegistrarControllerStub::class)->except(array("\151\156\x64\145\x78", "\x63\162\x65\141\x74\145", "\x73\164\157\x72\145", "\x73\x68\x6f\x77", "\145\144\151\164")); $this->assertCount(2, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\163\145\162\163\x2e\x75\x70\144\141\164\145")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\x73\145\162\x73\56\144\145\163\x74\162\157\171")); } public function testCanLimitAndExcludeMethodsOnRegisteredResource() { $this->router->resource("\x75\x73\145\x72\x73", RouteRegistrarControllerStub::class)->only("\x69\x6e\144\145\x78", "\x73\150\157\167", "\x64\x65\x73\x74\162\157\171")->except("\144\145\163\164\x72\157\x79"); $this->assertCount(2, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\163\145\162\163\56\x69\156\x64\x65\170")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\163\145\x72\x73\x2e\163\x68\157\x77")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\x75\163\x65\x72\163\x2e\x64\x65\x73\x74\162\157\x79")); } public function testCanSetShallowOptionOnRegisteredResource() { $this->router->resource("\165\x73\145\162\x73\56\164\141\163\153\x73", RouteRegistrarControllerStub::class)->shallow(); $this->assertCount(7, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\x73\145\x72\163\x2e\164\141\163\153\163\56\151\156\144\x65\170")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x74\x61\163\153\163\x2e\163\150\157\x77")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\x75\163\145\162\x73\56\164\x61\x73\153\x73\56\x73\x68\x6f\167")); } public function testCanSetScopedOptionOnRegisteredResource() { $this->router->resource("\165\x73\x65\x72\x73\56\x74\141\x73\x6b\x73", RouteRegistrarControllerStub::class)->scoped(); $this->assertSame(array("\165\163\145\x72" => null), $this->router->getRoutes()->getByName("\165\x73\145\x72\163\x2e\164\x61\163\153\x73\x2e\151\156\x64\145\170")->bindingFields()); $this->assertSame(array("\x75\x73\145\162" => null, "\164\x61\x73\x6b" => null), $this->router->getRoutes()->getByName("\165\x73\x65\x72\163\x2e\164\141\x73\153\x73\56\163\x68\x6f\x77")->bindingFields()); $this->router->resource("\x75\x73\x65\162\x73\56\164\141\163\x6b\x73", RouteRegistrarControllerStub::class)->scoped(array("\x74\x61\163\153" => "\163\x6c\x75\147")); $this->assertSame(array("\165\x73\145\162" => null), $this->router->getRoutes()->getByName("\x75\163\x65\162\163\56\x74\141\x73\153\163\x2e\x69\156\x64\145\x78")->bindingFields()); $this->assertSame(array("\165\x73\145\162" => null, "\x74\141\x73\153" => "\163\154\165\x67"), $this->router->getRoutes()->getByName("\165\163\145\x72\163\x2e\x74\141\x73\x6b\163\x2e\x73\x68\x6f\167")->bindingFields()); } public function testCanExcludeMethodsOnRegisteredApiResource() { $this->router->apiResource("\x75\x73\145\x72\x73", RouteRegistrarControllerStub::class)->except(array("\151\x6e\x64\x65\x78", "\x73\150\157\x77", "\x73\164\x6f\x72\x65")); $this->assertCount(2, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\x73\145\162\163\x2e\165\160\x64\141\164\x65")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\163\145\162\x73\56\144\145\x73\x74\162\x6f\x79")); } public function testCanRegisterApiResourcesWithExceptOption() { $this->router->apiResources(array("\x72\145\163\157\165\x72\143\x65\55\157\x6e\x65" => RouteRegistrarControllerStubOne::class, "\162\145\163\157\165\162\143\x65\x2d\164\x77\x6f" => RouteRegistrarControllerStubTwo::class, "\x72\x65\x73\157\165\x72\143\x65\55\164\150\x72\x65\145" => RouteRegistrarControllerStubThree::class), array("\x65\170\x63\x65\x70\164" => array("\x63\x72\145\x61\x74\145", "\x73\150\157\167"))); $this->assertCount(12, $this->router->getRoutes()); foreach (array("\x6f\156\145", "\164\x77\157", "\x74\x68\x72\145\145") as $resource) { $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\162\145\163\x6f\165\x72\x63\145\55" . $resource . "\x2e\x69\156\x64\145\x78")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x72\x65\163\x6f\x75\x72\x63\145\x2d" . $resource . "\x2e\163\x74\157\x72\x65")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x72\145\x73\x6f\x75\162\x63\145\x2d" . $resource . "\56\x75\160\144\x61\164\x65")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\162\x65\163\x6f\165\162\143\x65\x2d" . $resource . "\x2e\x64\x65\x73\x74\x72\x6f\x79")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\162\145\163\157\x75\x72\x63\145\x2d" . $resource . "\x2e\143\x72\145\x61\164\x65")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\x72\x65\163\157\165\x72\x63\x65\55" . $resource . "\56\x73\x68\157\x77")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\162\145\x73\x6f\x75\x72\x63\x65\55" . $resource . "\56\145\x64\x69\164")); } } public function testCanRegisterApiResourcesWithOnlyOption() { $this->router->apiResources(array("\x72\145\163\157\x75\162\x63\145\55\157\156\145" => RouteRegistrarControllerStubOne::class, "\162\145\x73\x6f\x75\162\x63\x65\x2d\164\x77\x6f" => RouteRegistrarControllerStubTwo::class, "\x72\145\163\x6f\165\x72\143\x65\x2d\164\x68\x72\145\x65" => RouteRegistrarControllerStubThree::class), array("\157\156\x6c\171" => array("\x69\x6e\144\145\170", "\163\150\x6f\x77"))); $this->assertCount(6, $this->router->getRoutes()); foreach (array("\x6f\x6e\x65", "\x74\167\x6f", "\x74\150\162\x65\145") as $resource) { $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\162\x65\x73\157\165\162\143\x65\55" . $resource . "\x2e\151\x6e\144\x65\x78")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x72\x65\163\x6f\x75\162\143\145\55" . $resource . "\56\163\150\157\167")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\162\145\163\x6f\x75\x72\x63\x65\x2d" . $resource . "\56\163\164\157\162\145")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\162\145\163\157\x75\x72\x63\x65\55" . $resource . "\56\165\x70\x64\141\164\x65")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\x72\x65\163\157\165\162\x63\145\55" . $resource . "\56\144\145\163\x74\x72\157\x79")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\162\145\163\x6f\165\162\143\145\55" . $resource . "\56\143\x72\145\x61\164\x65")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\162\x65\163\157\165\x72\x63\145\55" . $resource . "\x2e\145\x64\x69\164")); } } public function testCanRegisterApiResourcesWithoutOption() { $this->router->apiResources(array("\162\145\x73\157\165\162\143\145\x2d\157\156\x65" => RouteRegistrarControllerStubOne::class, "\162\145\x73\157\x75\162\143\x65\x2d\164\167\157" => RouteRegistrarControllerStubTwo::class, "\x72\145\x73\x6f\165\162\x63\x65\x2d\164\x68\x72\x65\x65" => RouteRegistrarControllerStubThree::class)); $this->assertCount(15, $this->router->getRoutes()); foreach (array("\157\x6e\145", "\x74\167\x6f", "\x74\150\x72\145\145") as $resource) { $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x72\145\163\157\165\x72\x63\145\x2d" . $resource . "\x2e\151\x6e\x64\x65\170")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x72\145\163\157\x75\x72\x63\x65\x2d" . $resource . "\56\163\150\x6f\x77")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x72\145\x73\x6f\165\x72\143\145\x2d" . $resource . "\x2e\x73\164\x6f\x72\145")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\162\145\x73\157\165\162\x63\x65\55" . $resource . "\x2e\x75\160\144\x61\x74\x65")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\162\145\x73\x6f\x75\162\x63\145\x2d" . $resource . "\x2e\x64\145\x73\x74\x72\157\x79")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\162\145\x73\157\165\x72\143\x65\x2d" . $resource . "\56\x63\x72\145\141\x74\145")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\x72\145\163\157\x75\162\x63\145\55" . $resource . "\56\145\x64\151\x74")); } } public function testUserCanRegisterApiResource() { $this->router->apiResource("\165\163\x65\162\x73", RouteRegistrarControllerStub::class); $this->assertCount(5, $this->router->getRoutes()); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\165\163\145\x72\163\56\x63\162\145\x61\164\145")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\x75\163\x65\162\163\x2e\145\144\x69\x74")); } public function testUserCanRegisterApiResourceWithExceptOption() { $this->router->apiResource("\x75\x73\x65\162\163", RouteRegistrarControllerStub::class, array("\145\x78\x63\145\160\x74" => array("\144\145\163\164\x72\x6f\171"))); $this->assertCount(4, $this->router->getRoutes()); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\x75\163\x65\x72\163\56\x63\x72\x65\141\x74\x65")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\x75\163\145\x72\x73\x2e\145\x64\x69\164")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\x75\163\x65\162\163\56\x64\145\x73\164\162\157\171")); } public function testUserCanRegisterApiResourceWithOnlyOption() { $this->router->apiResource("\165\x73\145\162\163", RouteRegistrarControllerStub::class, array("\157\156\154\171" => array("\x69\x6e\144\145\170", "\163\x68\x6f\167"))); $this->assertCount(2, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\x73\x65\x72\163\x2e\x69\x6e\144\145\x78")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\163\145\162\x73\56\163\150\157\167")); } public function testCanNameRoutesOnRegisteredResource() { $this->router->resource("\x63\157\x6d\155\145\156\164\x73", RouteRegistrarControllerStub::class)->only("\143\x72\x65\141\x74\x65", "\163\x74\x6f\x72\x65")->names("\162\145\x70\x6c\171"); $this->router->resource("\x75\163\x65\162\x73", RouteRegistrarControllerStub::class)->only("\x63\x72\145\x61\164\x65", "\x73\x74\x6f\162\x65")->names(array("\143\162\145\x61\x74\x65" => "\165\163\x65\162\x2e\x62\165\x69\x6c\x64", "\163\164\x6f\x72\145" => "\165\163\x65\162\x2e\163\141\166\145")); $this->router->resource("\160\157\x73\164\x73", RouteRegistrarControllerStub::class)->only("\143\162\145\141\x74\x65", "\x64\x65\163\x74\x72\157\x79")->name("\x63\x72\x65\x61\164\x65", "\x70\x6f\163\164\163\56\155\141\153\145")->name("\144\x65\x73\x74\162\157\171", "\x70\x6f\x73\164\163\x2e\x72\145\155\157\x76\x65"); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\162\145\x70\154\x79\56\143\x72\x65\x61\x74\x65")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\162\145\x70\154\171\x2e\x73\164\x6f\162\x65")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\x73\x65\x72\x2e\x62\165\x69\x6c\144")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\163\145\x72\x2e\x73\x61\166\x65")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x70\157\163\x74\163\x2e\x6d\141\x6b\145")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\160\157\x73\x74\x73\x2e\x72\x65\155\157\x76\x65")); } public function testCanOverrideParametersOnRegisteredResource() { $this->router->resource("\x75\x73\145\162\163", RouteRegistrarControllerStub::class)->parameters(array("\165\x73\145\162\x73" => "\x61\144\x6d\151\x6e\x5f\x75\x73\x65\162")); $this->router->resource("\160\157\163\164\163", RouteRegistrarControllerStub::class)->parameter("\x70\x6f\163\164\163", "\x74\157\160\x69\x63"); $this->assertStringContainsString("\141\144\x6d\151\x6e\x5f\x75\x73\x65\162", $this->router->getRoutes()->getByName("\x75\x73\x65\162\x73\x2e\x73\150\x6f\167")->uri); $this->assertStringContainsString("\164\x6f\160\x69\x63", $this->router->getRoutes()->getByName("\x70\x6f\163\x74\x73\x2e\163\150\157\x77")->uri); } public function testCanSetMiddlewareOnRegisteredResource() { $this->router->resource("\x75\163\x65\x72\x73", RouteRegistrarControllerStub::class)->middleware(RouteRegistrarMiddlewareStub::class); $this->seeMiddleware(RouteRegistrarMiddlewareStub::class); } public function testResourceWithoutMiddlewareRegistration() { $this->router->resource("\x75\x73\145\x72\x73", RouteRegistrarControllerStub::class)->only("\x69\156\144\145\x78")->middleware(array("\x6f\156\x65", "\164\x77\x6f"))->withoutMiddleware("\x6f\156\x65"); $this->seeResponse("\x63\x6f\156\x74\162\x6f\154\x6c\145\162", Request::create("\165\163\x65\162\x73", "\107\x45\x54")); $this->assertEquals(array("\x6f\156\145"), $this->getRoute()->excludedMiddleware()); } public function testResourceWithMiddlewareAsStringable() { $one = new class implements Stringable { public function __toString() { return "\157\156\145"; } }; $this->router->resource("\x75\x73\x65\x72\x73", RouteRegistrarControllerStub::class)->only("\x69\x6e\144\145\170")->middleware(array($one, "\x74\167\157"))->withoutMiddleware("\157\x6e\x65"); $this->seeResponse("\143\157\x6e\x74\x72\157\x6c\154\145\162", Request::create("\165\x73\145\162\x73", "\x47\105\124")); $this->assertEquals(array("\x6f\x6e\x65", "\164\167\x6f"), $this->getRoute()->middleware()); $this->assertEquals(array("\x6f\156\145"), $this->getRoute()->excludedMiddleware()); } public function testResourceWheres() { $wheres = array("\x75\163\145\162" => "\134\144\x2b", "\x74\x65\x73\164" => "\x5b\x61\x2d\x7a\135\x2b"); $this->router->resource("\x75\x73\145\x72\x73", RouteRegistrarControllerStub::class)->where($wheres); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testWhereNumberRegistration() { $wheres = array("\146\x6f\157" => "\x5b\x30\x2d\x39\x5d\x2b", "\x62\141\162" => "\x5b\60\55\71\135\53"); $this->router->get("\x2f\x7b\x66\157\x6f\x7d\57\x7b\142\141\x72\x7d")->whereNumber(array("\146\x6f\157", "\x62\x61\162")); $this->router->get("\57\141\160\151\x2f\x7b\x62\141\x72\x7d\57\x7b\146\157\x6f\x7d")->whereNumber(array("\x62\x61\162", "\x66\x6f\157")); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testWhereAlphaRegistration() { $wheres = array("\x66\157\x6f" => "\x5b\141\x2d\x7a\x41\55\x5a\x5d\x2b", "\142\x61\x72" => "\133\141\x2d\172\x41\55\x5a\135\53"); $this->router->get("\x2f\173\146\157\x6f\x7d\57\173\x62\x61\x72\x7d")->whereAlpha(array("\146\157\x6f", "\142\x61\162")); $this->router->get("\x2f\141\160\151\57\173\x62\x61\162\175\x2f\x7b\146\157\x6f\x7d")->whereAlpha(array("\x62\141\x72", "\x66\157\157")); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testWhereAlphaNumericRegistration() { $wheres = array("\61\141\62\x62\x33\x63" => "\x5b\x61\55\x7a\101\x2d\132\x30\55\x39\135\x2b"); $this->router->get("\57\173\x66\x6f\x6f\x7d")->whereAlphaNumeric(array("\61\x61\62\142\63\x63")); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testWhereInRegistration() { $wheres = array("\146\x6f\157" => "\157\156\x65\x7c\x74\x77\157", "\x62\x61\162" => "\157\156\145\174\164\167\x6f"); $this->router->get("\57\173\x66\157\x6f\x7d\x2f\173\x62\x61\162\x7d")->whereIn(array("\x66\x6f\x6f", "\142\141\x72"), array("\x6f\156\145", "\164\x77\157")); $this->router->get("\x2f\x61\x70\x69\57\x7b\x62\141\x72\175\57\173\146\x6f\x6f\x7d")->whereIn(array("\x62\141\x72", "\x66\x6f\157"), array("\157\x6e\x65", "\164\167\157")); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testGroupWhereNumberRegistrationOnRouteRegistrar() { $wheres = array("\x66\157\x6f" => "\133\x30\55\71\135\x2b", "\x62\x61\x72" => "\x5b\60\x2d\x39\x5d\53"); $this->router->prefix("\57\x7b\x66\x6f\157\175\57\x7b\x62\141\162\x7d")->whereNumber(array("\146\157\157", "\142\141\x72"))->group(function ($router) { $router->get("\57"); }); $this->router->prefix("\x2f\x61\160\x69\57\x7b\x62\x61\x72\x7d\57\x7b\x66\157\157\x7d")->whereNumber(array("\x62\141\162", "\x66\157\157"))->group(function ($router) { $router->get("\x2f"); }); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testGroupWhereAlphaRegistrationOnRouteRegistrar() { $wheres = array("\x66\x6f\x6f" => "\133\141\55\x7a\101\x2d\132\x5d\53", "\x62\141\x72" => "\x5b\x61\x2d\x7a\x41\x2d\x5a\x5d\x2b"); $this->router->prefix("\x2f\173\146\x6f\x6f\x7d\57\x7b\142\x61\162\x7d")->whereAlpha(array("\x66\x6f\157", "\x62\x61\162"))->group(function ($router) { $router->get("\x2f"); }); $this->router->prefix("\x2f\x61\160\x69\57\173\142\x61\x72\175\x2f\173\x66\x6f\x6f\175")->whereAlpha(array("\142\141\162", "\146\x6f\x6f"))->group(function ($router) { $router->get("\57"); }); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testGroupWhereAlphaNumericRegistrationOnRouteRegistrar() { $wheres = array("\x31\141\62\x62\x33\x63" => "\133\141\x2d\172\x41\55\x5a\60\55\71\x5d\x2b"); $this->router->prefix("\x2f\x7b\x66\157\x6f\x7d")->whereAlphaNumeric(array("\61\141\62\142\63\143"))->group(function ($router) { $router->get("\x2f"); }); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testGroupWhereInRegistrationOnRouteRegistrar() { $wheres = array("\146\x6f\157" => "\x6f\156\x65\x7c\164\167\x6f", "\142\141\x72" => "\157\x6e\145\x7c\x74\167\157"); $this->router->prefix("\x2f\173\146\157\x6f\175\57\173\x62\141\x72\x7d")->whereIn(array("\146\157\157", "\142\x61\162"), array("\x6f\x6e\x65", "\x74\x77\x6f"))->group(function ($router) { $router->get("\x2f"); }); $this->router->prefix("\x2f\141\160\151\x2f\173\x62\x61\162\x7d\x2f\173\x66\x6f\157\175")->whereIn(array("\142\141\162", "\x66\157\157"), array("\157\x6e\145", "\164\167\x6f"))->group(function ($router) { $router->get("\x2f"); }); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testGroupWhereNumberRegistrationOnRouter() { $wheres = array("\x66\x6f\x6f" => "\133\60\x2d\71\135\53", "\x62\x61\162" => "\133\60\55\x39\135\x2b"); $this->router->whereNumber(array("\x66\x6f\157", "\142\141\x72"))->prefix("\57\x7b\x66\x6f\157\175\x2f\173\142\141\x72\175")->group(function ($router) { $router->get("\57"); }); $this->router->whereNumber(array("\142\x61\162", "\x66\x6f\157"))->prefix("\57\x61\160\151\57\173\x62\x61\x72\175\x2f\173\146\x6f\x6f\175")->group(function ($router) { $router->get("\x2f"); }); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testGroupWhereAlphaRegistrationOnRouter() { $wheres = array("\x66\157\157" => "\x5b\x61\55\x7a\101\x2d\x5a\x5d\x2b", "\x62\x61\x72" => "\133\141\x2d\172\101\x2d\x5a\135\53"); $this->router->whereAlpha(array("\x66\157\x6f", "\142\141\162"))->prefix("\57\173\x66\157\x6f\x7d\57\173\142\141\x72\175")->group(function ($router) { $router->get("\x2f"); }); $this->router->whereAlpha(array("\142\x61\x72", "\146\x6f\157"))->prefix("\x2f\x61\x70\151\57\173\x62\141\x72\x7d\x2f\x7b\x66\x6f\157\175")->group(function ($router) { $router->get("\x2f"); }); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testGroupWhereAlphaNumericRegistrationOnRouter() { $wheres = array("\x31\141\62\x62\63\143" => "\133\x61\55\172\x41\55\x5a\x30\55\x39\135\53"); $this->router->whereAlphaNumeric(array("\x31\x61\x32\x62\x33\143"))->prefix("\x2f\x7b\x66\x6f\157\175")->group(function ($router) { $router->get("\x2f"); }); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testGroupWhereInRegistrationOnRouter() { $wheres = array("\x66\157\x6f" => "\x6f\156\x65\174\x74\167\157", "\142\x61\162" => "\x6f\156\145\174\164\x77\157"); $this->router->whereIn(array("\x66\x6f\157", "\x62\141\162"), array("\157\156\145", "\x74\167\157"))->prefix("\57\x7b\146\x6f\x6f\x7d\57\x7b\142\141\162\x7d")->group(function ($router) { $router->get("\x2f"); }); $this->router->whereIn(array("\142\x61\x72", "\x66\157\x6f"), array("\157\156\145", "\x74\167\157"))->prefix("\57\x61\x70\151\x2f\173\x62\x61\162\x7d\57\173\x66\x6f\157\175")->group(function ($router) { $router->get("\57"); }); foreach ($this->router->getRoutes() as $route) { $this->assertEquals($wheres, $route->wheres); } } public function testCanSetRouteName() { $this->router->as("\x75\x73\145\x72\163\x2e\x69\156\144\145\x78")->get("\165\163\x65\162\x73", function () { return "\x61\154\x6c\x2d\x75\x73\145\162\x73"; }); $this->seeResponse("\x61\154\154\55\x75\x73\x65\x72\163", Request::create("\165\163\145\x72\x73", "\107\x45\124")); $this->assertSame("\165\163\145\x72\x73\56\151\156\144\x65\170", $this->getRoute()->getName()); } public function testCanSetRouteNameUsingNameAlias() { $this->router->name("\x75\x73\x65\162\x73\x2e\151\x6e\x64\145\x78")->get("\165\x73\145\x72\x73", function () { return "\x61\x6c\x6c\55\165\163\x65\x72\x73"; }); $this->seeResponse("\141\x6c\x6c\55\x75\163\145\162\163", Request::create("\165\x73\x65\162\163", "\x47\x45\x54")); $this->assertSame("\x75\163\145\x72\x73\56\151\156\x64\145\x78", $this->getRoute()->getName()); } public function testPushMiddlewareToGroup() { $this->router->middlewareGroup("\x77\145\x62", array()); $this->router->pushMiddlewareToGroup("\167\x65\x62", "\x74\145\x73\164\x2d\155\x69\144\x64\x6c\x65\x77\x61\162\145"); $this->assertEquals(array("\164\x65\x73\164\55\x6d\x69\x64\144\154\x65\x77\x61\162\x65"), $this->router->getMiddlewareGroups()["\x77\x65\x62"]); } public function testPushMiddlewareToGroupUnregisteredGroup() { $this->router->pushMiddlewareToGroup("\x77\x65\142", "\164\x65\x73\x74\55\x6d\x69\x64\144\x6c\x65\167\x61\x72\145"); $this->assertEquals(array("\x74\145\x73\x74\55\x6d\151\144\x64\154\x65\x77\141\x72\x65"), $this->router->getMiddlewareGroups()["\x77\145\142"]); } public function testPushMiddlewareToGroupDuplicatedMiddleware() { $this->router->pushMiddlewareToGroup("\167\145\x62", "\x74\x65\x73\x74\x2d\x6d\151\144\144\154\145\167\x61\x72\x65"); $this->router->pushMiddlewareToGroup("\x77\x65\142", "\x74\145\x73\164\x2d\155\151\x64\x64\x6c\145\167\x61\x72\x65"); $this->assertEquals(array("\164\x65\x73\164\x2d\155\151\x64\144\154\x65\x77\x61\x72\x65"), $this->router->getMiddlewareGroups()["\x77\145\142"]); } public function testCanRemoveMiddlewareFromGroup() { $this->router->pushMiddlewareToGroup("\x77\145\x62", "\164\145\163\x74\55\x6d\x69\x64\x64\154\x65\x77\x61\x72\145"); $this->router->removeMiddlewareFromGroup("\167\145\142", "\x74\x65\x73\164\55\155\x69\144\x64\154\x65\167\141\x72\x65"); $this->assertEquals(array(), $this->router->getMiddlewareGroups()["\x77\145\x62"]); } public function testCanRemoveMiddlewareFromGroupNotUnregisteredMiddleware() { $this->router->middlewareGroup("\x77\x65\x62", array()); $this->router->removeMiddlewareFromGroup("\167\145\x62", "\x64\x69\146\146\x65\162\x65\156\164\55\164\x65\163\x74\x2d\155\151\x64\x64\x6c\x65\167\141\x72\145"); $this->assertEquals(array(), $this->router->getMiddlewareGroups()["\167\x65\142"]); } public function testCanRemoveMiddlewareFromGroupUnregisteredGroup() { $this->router->removeMiddlewareFromGroup("\167\x65\142", array("\x74\145\163\x74\x2d\155\x69\x64\x64\x6c\145\167\141\162\145")); $this->assertEquals(array(), $this->router->getMiddlewareGroups()); } public function testCanRegisterSingleton() { $this->router->singleton("\x75\x73\145\162", RouteRegistrarControllerStub::class); $this->assertCount(3, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\163\x65\162\56\163\150\157\167")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\163\x65\x72\x2e\145\x64\151\164")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\163\x65\x72\56\165\x70\144\141\x74\145")); } public function testCanRegisterApiSingleton() { $this->router->apiSingleton("\x75\163\145\x72", RouteRegistrarControllerStub::class); $this->assertCount(2, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\x73\x65\162\56\x73\150\x6f\167")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\x73\x65\x72\x2e\x75\x70\x64\141\164\145")); } public function testCanRegisterCreatableSingleton() { $this->router->singleton("\165\163\145\x72", RouteRegistrarControllerStub::class)->creatable(); $this->assertCount(6, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\163\x65\x72\x2e\143\x72\145\141\164\145")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\163\145\162\56\x73\x74\x6f\x72\x65")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\163\x65\162\56\x73\x68\157\167")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\163\x65\x72\x2e\x65\144\151\x74")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\163\x65\x72\56\165\160\x64\x61\164\x65")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\x73\x65\x72\56\x64\145\163\164\162\157\171")); } public function testCanRegisterCreatableApiSingleton() { $this->router->apiSingleton("\165\163\145\162", RouteRegistrarControllerStub::class)->creatable(); $this->assertCount(4, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\x73\145\162\56\x73\164\x6f\x72\145")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\x73\145\162\x2e\x73\150\x6f\167")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\163\x65\x72\x2e\x75\x70\144\141\164\145")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\x73\145\x72\56\144\145\163\x74\162\157\171")); } public function testSingletonCreatableNotDestroyable() { $this->router->singleton("\165\x73\x65\x72", RouteRegistrarControllerStub::class)->creatable()->except("\x64\145\x73\x74\162\x6f\171"); $this->assertCount(5, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\x73\x65\162\56\143\x72\145\141\x74\x65")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\163\145\162\x2e\x73\164\157\x72\145")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\x73\x65\x72\56\x73\150\x6f\167")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\163\x65\162\56\145\x64\x69\x74")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\163\145\162\x2e\x75\x70\144\x61\x74\x65")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\165\163\x65\162\x2e\144\x65\x73\164\x72\157\171")); } public function testApiSingletonCreatableNotDestroyable() { $this->router->apiSingleton("\x75\x73\145\162", RouteRegistrarControllerStub::class)->creatable()->except("\x64\x65\163\164\x72\157\171"); $this->assertCount(3, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\163\x65\x72\x2e\x73\x74\x6f\162\145")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\x73\145\x72\56\x73\150\157\167")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\163\x65\162\56\x75\x70\144\x61\x74\145")); $this->assertFalse($this->router->getRoutes()->hasNamedRoute("\165\x73\145\x72\x2e\144\145\x73\x74\x72\157\171")); } public function testSingletonCanBeDestroyable() { $this->router->singleton("\x75\163\x65\x72", RouteRegistrarControllerStub::class)->destroyable(); $this->assertCount(4, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\x73\x65\162\x2e\x73\x68\157\167")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\x73\x65\x72\x2e\x65\144\151\x74")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\163\x65\162\56\165\x70\x64\141\164\x65")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\x73\x65\162\x2e\144\x65\x73\x74\x72\x6f\171")); } public function testApiSingletonCanBeDestroyable() { $this->router->apiSingleton("\165\163\145\x72", RouteRegistrarControllerStub::class)->destroyable(); $this->assertCount(3, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\x73\145\162\56\163\150\x6f\x77")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\x73\x65\x72\56\165\x70\x64\141\x74\145")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\163\145\x72\x2e\144\x65\163\x74\x72\x6f\x79")); } public function testSingletonCanBeOnlyCreatable() { $this->router->singleton("\x75\163\x65\x72", RouteRegistrarControllerStub::class)->creatable()->only("\143\x72\145\x61\164\x65", "\x73\x74\157\x72\x65"); $this->assertCount(2, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\x73\145\x72\56\143\x72\145\141\x74\x65")); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\163\145\x72\x2e\163\x74\x6f\162\x65")); } public function testApiSingletonCanBeOnlyCreatable() { $this->router->apiSingleton("\x75\163\145\162", RouteRegistrarControllerStub::class)->creatable()->only("\x73\164\x6f\x72\x65"); $this->assertCount(1, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\x75\x73\x65\x72\x2e\x73\x74\x6f\x72\x65")); } public function testSingletonDoesntAllowIncludingUnsupportedMethods() { $this->router->singleton("\x70\157\163\164", RouteRegistrarControllerStub::class)->only("\x69\x6e\144\x65\170", "\x73\164\x6f\x72\145", "\x63\162\x65\x61\x74\145", "\144\145\163\x74\162\157\x79"); $this->assertCount(0, $this->router->getRoutes()); $this->router->apiSingleton("\x75\163\x65\162", RouteRegistrarControllerStub::class)->only("\151\156\x64\145\170", "\163\164\x6f\x72\x65", "\x63\x72\145\141\x74\x65", "\x64\145\x73\x74\x72\157\x79"); $this->assertCount(0, $this->router->getRoutes()); } public function testApiSingletonCanIncludeAnySingletonMethods() { $this->router->apiSingleton("\x75\x73\x65\162", RouteRegistrarControllerStub::class)->only("\145\x64\151\164"); $this->assertCount(1, $this->router->getRoutes()); $this->assertTrue($this->router->getRoutes()->hasNamedRoute("\165\x73\x65\162\56\x65\x64\151\164")); } protected function getRoute() { return last($this->router->getRoutes()->get()); } protected function seeMiddleware($middleware) { $this->assertEquals($middleware, $this->getRoute()->middleware()[0]); } protected function seeResponse($content, Request $request) { $route = $this->getRoute(); $this->assertTrue($route->matches($request)); $this->assertEquals($content, $route->bind($request)->run()); } } class RouteRegistrarControllerStub { public function index() { return "\x63\x6f\x6e\164\x72\x6f\154\154\145\162"; } public function destroy() { return "\144\145\154\145\164\x65\x64"; } } class InvokableRouteRegistrarControllerStub { public function __invoke() { return "\143\157\x6e\x74\162\157\x6c\x6c\145\x72"; } } class RouteRegistrarMiddlewareStub { }

Function Calls

None

Variables

None

Stats

MD5 843564f1e3ed87e54b4e88f091aff2b5
Eval Count 0
Decode Time 154 ms