From d61d89299c50ab5f2cc1f034e5ade59d41dfd395 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Tue, 15 Dec 2020 13:33:07 +0300 Subject: [PATCH] Updated tests --- tests/Fixtures/routes.php | 8 ++ tests/RoutesTest.php | 179 ++++++++++++++++++++------------------ 2 files changed, 100 insertions(+), 87 deletions(-) diff --git a/tests/Fixtures/routes.php b/tests/Fixtures/routes.php index cc9db5c..38b2880 100644 --- a/tests/Fixtures/routes.php +++ b/tests/Fixtures/routes.php @@ -38,3 +38,11 @@ app('router') ->get('controllerWebMiddleware', '\Tests\Fixtures\Controller@controllerWebMiddleware') ->name('controllerWebMiddleware'); + +app('router') + ->get('closureNullName', static function () { + }); + +app('router') + ->get('closure', static function () { + })->name('closure'); diff --git a/tests/RoutesTest.php b/tests/RoutesTest.php index 8b7ce90..cb5a22a 100644 --- a/tests/RoutesTest.php +++ b/tests/RoutesTest.php @@ -114,8 +114,16 @@ public function testMapping() $this->routeControllerWebMiddleware($route); break; + case 'closureNullName': + $this->routeClosureNullName($route); + break; + + case 'closure': + $this->routeClosure($route); + break; + default: - dd($route->toArray()); + $this->assertTrue(false); } }); } @@ -128,16 +136,12 @@ protected function routeFoo(Route $route) $this->assertIsArray($route->getMethods()); $this->assertSame(['GET', 'HEAD'], $route->getMethods()); - $this->assertNull($route->getDomain()); $this->assertNull($route->getDomain()); $this->assertIsString($route->getPath()); $this->assertSame('foo', $route->getPath()); $this->assertNull($route->getName()); - $this->assertNull($route->getName()); - - $this->assertNull($route->getModule()); $this->assertNull($route->getModule()); $this->assertIsString($route->getAction()); @@ -150,16 +154,12 @@ protected function routeFoo(Route $route) $this->assertFalse($route->getDeprecated()); $this->assertNull($route->getSummary()); - $this->assertNull($route->getSummary()); - - $this->assertNull($route->getDescription()); $this->assertNull($route->getDescription()); $this->assertIsArray($route->getExceptions()->toArray()); $this->assertSame([], $route->getExceptions()->toArray()); $this->assertTrue($route->getExceptions()->isEmpty()); - $this->assertNull($route->getResponse()); $this->assertNull($route->getResponse()); $this->assertIsBool($route->isApi()); @@ -177,16 +177,12 @@ protected function routeBar(Route $route) $this->assertIsArray($route->getMethods()); $this->assertSame(['PUT', 'PATCH'], $route->getMethods()); - $this->assertNull($route->getDomain()); $this->assertNull($route->getDomain()); $this->assertIsString($route->getPath()); $this->assertSame('bar', $route->getPath()); $this->assertNull($route->getName()); - $this->assertNull($route->getName()); - - $this->assertNull($route->getModule()); $this->assertNull($route->getModule()); $this->assertIsString($route->getAction()); @@ -199,16 +195,12 @@ protected function routeBar(Route $route) $this->assertFalse($route->getDeprecated()); $this->assertNull($route->getSummary()); - $this->assertNull($route->getSummary()); - - $this->assertNull($route->getDescription()); $this->assertNull($route->getDescription()); $this->assertIsArray($route->getExceptions()->toArray()); $this->assertSame([], $route->getExceptions()->toArray()); $this->assertTrue($route->getExceptions()->isEmpty()); - $this->assertNull($route->getResponse()); $this->assertNull($route->getResponse()); $this->assertIsBool($route->isApi()); @@ -226,16 +218,12 @@ protected function routeIgnitionBaq(Route $route) $this->assertIsArray($route->getMethods()); $this->assertSame(['GET', 'HEAD'], $route->getMethods()); - $this->assertNull($route->getDomain()); $this->assertNull($route->getDomain()); $this->assertIsString($route->getPath()); $this->assertSame('_ignition/baq', $route->getPath()); $this->assertNull($route->getName()); - $this->assertNull($route->getName()); - - $this->assertNull($route->getModule()); $this->assertNull($route->getModule()); $this->assertIsString($route->getAction()); @@ -248,16 +236,12 @@ protected function routeIgnitionBaq(Route $route) $this->assertFalse($route->getDeprecated()); $this->assertNull($route->getSummary()); - $this->assertNull($route->getSummary()); - - $this->assertNull($route->getDescription()); $this->assertNull($route->getDescription()); $this->assertIsArray($route->getExceptions()->toArray()); $this->assertSame([], $route->getExceptions()->toArray()); $this->assertTrue($route->getExceptions()->isEmpty()); - $this->assertNull($route->getResponse()); $this->assertNull($route->getResponse()); $this->assertIsBool($route->isApi()); @@ -275,16 +259,12 @@ protected function routeTelescopeBaw(Route $route) $this->assertIsArray($route->getMethods()); $this->assertSame(['GET', 'HEAD'], $route->getMethods()); - $this->assertNull($route->getDomain()); $this->assertNull($route->getDomain()); $this->assertIsString($route->getPath()); $this->assertSame('telescope/baw', $route->getPath()); $this->assertNull($route->getName()); - $this->assertNull($route->getName()); - - $this->assertNull($route->getModule()); $this->assertNull($route->getModule()); $this->assertIsString($route->getAction()); @@ -297,16 +277,12 @@ protected function routeTelescopeBaw(Route $route) $this->assertFalse($route->getDeprecated()); $this->assertNull($route->getSummary()); - $this->assertNull($route->getSummary()); - - $this->assertNull($route->getDescription()); $this->assertNull($route->getDescription()); $this->assertIsArray($route->getExceptions()->toArray()); $this->assertSame([], $route->getExceptions()->toArray()); $this->assertTrue($route->getExceptions()->isEmpty()); - $this->assertNull($route->getResponse()); $this->assertNull($route->getResponse()); $this->assertIsBool($route->isApi()); @@ -324,16 +300,12 @@ protected function routeDebugBarBae(Route $route) $this->assertIsArray($route->getMethods()); $this->assertSame(['GET', 'HEAD'], $route->getMethods()); - $this->assertNull($route->getDomain()); $this->assertNull($route->getDomain()); $this->assertIsString($route->getPath()); $this->assertSame('_debugbar/bae', $route->getPath()); $this->assertNull($route->getName()); - $this->assertNull($route->getName()); - - $this->assertNull($route->getModule()); $this->assertNull($route->getModule()); $this->assertIsString($route->getAction()); @@ -346,16 +318,12 @@ protected function routeDebugBarBae(Route $route) $this->assertFalse($route->getDeprecated()); $this->assertNull($route->getSummary()); - $this->assertNull($route->getSummary()); - - $this->assertNull($route->getDescription()); $this->assertNull($route->getDescription()); $this->assertIsArray($route->getExceptions()->toArray()); $this->assertSame([], $route->getExceptions()->toArray()); $this->assertTrue($route->getExceptions()->isEmpty()); - $this->assertNull($route->getResponse()); $this->assertNull($route->getResponse()); $this->assertIsBool($route->isApi()); @@ -373,7 +341,6 @@ protected function routeSummary(Route $route) $this->assertIsArray($route->getMethods()); $this->assertSame(['GET', 'HEAD'], $route->getMethods()); - $this->assertNull($route->getDomain()); $this->assertNull($route->getDomain()); $this->assertIsString($route->getPath()); @@ -382,7 +349,6 @@ protected function routeSummary(Route $route) $this->assertIsString($route->getName()); $this->assertSame('summary', $route->getName()); - $this->assertNull($route->getModule()); $this->assertNull($route->getModule()); $this->assertIsString($route->getAction()); @@ -397,14 +363,12 @@ protected function routeSummary(Route $route) $this->assertIsString($route->getSummary()); $this->assertSame('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse justo.', $route->getSummary()); - $this->assertNull($route->getDescription()); $this->assertNull($route->getDescription()); $this->assertIsArray($route->getExceptions()->toArray()); $this->assertSame([], $route->getExceptions()->toArray()); $this->assertTrue($route->getExceptions()->isEmpty()); - $this->assertNull($route->getResponse()); $this->assertNull($route->getResponse()); $this->assertIsBool($route->isApi()); @@ -422,7 +386,6 @@ protected function routeDescription(Route $route) $this->assertIsArray($route->getMethods()); $this->assertSame(['GET', 'HEAD'], $route->getMethods()); - $this->assertNull($route->getDomain()); $this->assertNull($route->getDomain()); $this->assertIsString($route->getPath()); @@ -431,7 +394,6 @@ protected function routeDescription(Route $route) $this->assertIsString($route->getName()); $this->assertSame('description', $route->getName()); - $this->assertNull($route->getModule()); $this->assertNull($route->getModule()); $this->assertIsString($route->getAction()); @@ -456,7 +418,6 @@ protected function routeDescription(Route $route) $this->assertSame([], $route->getExceptions()->toArray()); $this->assertTrue($route->getExceptions()->isEmpty()); - $this->assertNull($route->getResponse()); $this->assertNull($route->getResponse()); $this->assertIsBool($route->isApi()); @@ -474,7 +435,6 @@ protected function routeDeprecated(Route $route) $this->assertIsArray($route->getMethods()); $this->assertSame(['GET', 'HEAD'], $route->getMethods()); - $this->assertNull($route->getDomain()); $this->assertNull($route->getDomain()); $this->assertIsString($route->getPath()); @@ -483,7 +443,6 @@ protected function routeDeprecated(Route $route) $this->assertIsString($route->getName()); $this->assertSame('deprecated', $route->getName()); - $this->assertNull($route->getModule()); $this->assertNull($route->getModule()); $this->assertIsString($route->getAction()); @@ -508,7 +467,6 @@ protected function routeDeprecated(Route $route) $this->assertSame([], $route->getExceptions()->toArray()); $this->assertTrue($route->getExceptions()->isEmpty()); - $this->assertNull($route->getResponse()); $this->assertNull($route->getResponse()); $this->assertIsBool($route->isApi()); @@ -526,7 +484,6 @@ protected function routeWithout(Route $route) $this->assertIsArray($route->getMethods()); $this->assertSame(['GET', 'HEAD'], $route->getMethods()); - $this->assertNull($route->getDomain()); $this->assertNull($route->getDomain()); $this->assertIsString($route->getPath()); @@ -535,7 +492,6 @@ protected function routeWithout(Route $route) $this->assertIsString($route->getName()); $this->assertSame('without', $route->getName()); - $this->assertNull($route->getModule()); $this->assertNull($route->getModule()); $this->assertIsString($route->getAction()); @@ -548,16 +504,12 @@ protected function routeWithout(Route $route) $this->assertFalse($route->getDeprecated()); $this->assertNull($route->getSummary()); - $this->assertNull($route->getSummary()); - - $this->assertNull($route->getDescription()); $this->assertNull($route->getDescription()); $this->assertIsArray($route->getExceptions()->toArray()); $this->assertSame([], $route->getExceptions()->toArray()); $this->assertTrue($route->getExceptions()->isEmpty()); - $this->assertNull($route->getResponse()); $this->assertNull($route->getResponse()); $this->assertIsBool($route->isApi()); @@ -575,7 +527,6 @@ protected function routeWithoutDeprecated(Route $route) $this->assertIsArray($route->getMethods()); $this->assertSame(['GET', 'HEAD'], $route->getMethods()); - $this->assertNull($route->getDomain()); $this->assertNull($route->getDomain()); $this->assertIsString($route->getPath()); @@ -584,7 +535,6 @@ protected function routeWithoutDeprecated(Route $route) $this->assertIsString($route->getName()); $this->assertSame('withoutDeprecated', $route->getName()); - $this->assertNull($route->getModule()); $this->assertNull($route->getModule()); $this->assertIsString($route->getAction()); @@ -597,16 +547,12 @@ protected function routeWithoutDeprecated(Route $route) $this->assertTrue($route->getDeprecated()); $this->assertNull($route->getSummary()); - $this->assertNull($route->getSummary()); - - $this->assertNull($route->getDescription()); $this->assertNull($route->getDescription()); $this->assertIsArray($route->getExceptions()->toArray()); $this->assertSame([], $route->getExceptions()->toArray()); $this->assertTrue($route->getExceptions()->isEmpty()); - $this->assertNull($route->getResponse()); $this->assertNull($route->getResponse()); $this->assertIsBool($route->isApi()); @@ -624,7 +570,6 @@ protected function routeRoutingApiMiddleware(Route $route) $this->assertIsArray($route->getMethods()); $this->assertSame(['GET', 'HEAD'], $route->getMethods()); - $this->assertNull($route->getDomain()); $this->assertNull($route->getDomain()); $this->assertIsString($route->getPath()); @@ -633,7 +578,6 @@ protected function routeRoutingApiMiddleware(Route $route) $this->assertIsString($route->getName()); $this->assertSame('routeApiMiddleware', $route->getName()); - $this->assertNull($route->getModule()); $this->assertNull($route->getModule()); $this->assertIsString($route->getAction()); @@ -646,16 +590,12 @@ protected function routeRoutingApiMiddleware(Route $route) $this->assertFalse($route->getDeprecated()); $this->assertNull($route->getSummary()); - $this->assertNull($route->getSummary()); - - $this->assertNull($route->getDescription()); $this->assertNull($route->getDescription()); $this->assertIsArray($route->getExceptions()->toArray()); $this->assertSame([], $route->getExceptions()->toArray()); $this->assertTrue($route->getExceptions()->isEmpty()); - $this->assertNull($route->getResponse()); $this->assertNull($route->getResponse()); $this->assertIsBool($route->isApi()); @@ -673,7 +613,6 @@ protected function routeControllerApiMiddleware(Route $route) $this->assertIsArray($route->getMethods()); $this->assertSame(['GET', 'HEAD'], $route->getMethods()); - $this->assertNull($route->getDomain()); $this->assertNull($route->getDomain()); $this->assertIsString($route->getPath()); @@ -682,7 +621,6 @@ protected function routeControllerApiMiddleware(Route $route) $this->assertIsString($route->getName()); $this->assertSame('controllerApiMiddleware', $route->getName()); - $this->assertNull($route->getModule()); $this->assertNull($route->getModule()); $this->assertIsString($route->getAction()); @@ -695,16 +633,12 @@ protected function routeControllerApiMiddleware(Route $route) $this->assertFalse($route->getDeprecated()); $this->assertNull($route->getSummary()); - $this->assertNull($route->getSummary()); - - $this->assertNull($route->getDescription()); $this->assertNull($route->getDescription()); $this->assertIsArray($route->getExceptions()->toArray()); $this->assertSame([], $route->getExceptions()->toArray()); $this->assertTrue($route->getExceptions()->isEmpty()); - $this->assertNull($route->getResponse()); $this->assertNull($route->getResponse()); $this->assertIsBool($route->isApi()); @@ -722,7 +656,6 @@ protected function routeRoutingWebMiddleware(Route $route) $this->assertIsArray($route->getMethods()); $this->assertSame(['GET', 'HEAD'], $route->getMethods()); - $this->assertNull($route->getDomain()); $this->assertNull($route->getDomain()); $this->assertIsString($route->getPath()); @@ -731,7 +664,6 @@ protected function routeRoutingWebMiddleware(Route $route) $this->assertIsString($route->getName()); $this->assertSame('routeWebMiddleware', $route->getName()); - $this->assertNull($route->getModule()); $this->assertNull($route->getModule()); $this->assertIsString($route->getAction()); @@ -741,19 +673,14 @@ protected function routeRoutingWebMiddleware(Route $route) $this->assertSame(['web'], $route->getMiddlewares()); $this->assertIsBool($route->getDeprecated()); - $this->assertFalse($route->getDeprecated()); - - $this->assertNull($route->getSummary()); $this->assertNull($route->getSummary()); - $this->assertNull($route->getDescription()); $this->assertNull($route->getDescription()); $this->assertIsArray($route->getExceptions()->toArray()); $this->assertSame([], $route->getExceptions()->toArray()); $this->assertTrue($route->getExceptions()->isEmpty()); - $this->assertNull($route->getResponse()); $this->assertNull($route->getResponse()); $this->assertIsBool($route->isApi()); @@ -771,7 +698,6 @@ protected function routeControllerWebMiddleware(Route $route) $this->assertIsArray($route->getMethods()); $this->assertSame(['GET', 'HEAD'], $route->getMethods()); - $this->assertNull($route->getDomain()); $this->assertNull($route->getDomain()); $this->assertIsString($route->getPath()); @@ -780,7 +706,6 @@ protected function routeControllerWebMiddleware(Route $route) $this->assertIsString($route->getName()); $this->assertSame('controllerWebMiddleware', $route->getName()); - $this->assertNull($route->getModule()); $this->assertNull($route->getModule()); $this->assertIsString($route->getAction()); @@ -793,9 +718,47 @@ protected function routeControllerWebMiddleware(Route $route) $this->assertFalse($route->getDeprecated()); $this->assertNull($route->getSummary()); - $this->assertNull($route->getSummary()); - $this->assertNull($route->getDescription()); + + $this->assertIsArray($route->getExceptions()->toArray()); + $this->assertSame([], $route->getExceptions()->toArray()); + $this->assertTrue($route->getExceptions()->isEmpty()); + + $this->assertNull($route->getResponse()); + + $this->assertIsBool($route->isApi()); + $this->assertFalse($route->isApi()); + + $this->assertIsBool($route->isWeb()); + $this->assertTrue($route->isWeb()); + } + + protected function routeClosureNullName(Route $route) + { + $this->assertIsInt($route->getPriority()); + $this->assertSame(15, $route->getPriority()); + + $this->assertIsArray($route->getMethods()); + $this->assertSame(['GET', 'HEAD'], $route->getMethods()); + + $this->assertNull($route->getDomain()); + + $this->assertIsString($route->getPath()); + $this->assertSame('closureNullName', $route->getPath()); + + $this->assertNull($route->getName()); + $this->assertNull($route->getModule()); + + $this->assertIsString($route->getAction()); + $this->assertSame('Closure', $route->getAction()); + + $this->assertIsArray($route->getMiddlewares()); + $this->assertSame([], $route->getMiddlewares()); + + $this->assertIsBool($route->getDeprecated()); + $this->assertFalse($route->getDeprecated()); + + $this->assertNull($route->getSummary()); $this->assertNull($route->getDescription()); $this->assertIsArray($route->getExceptions()->toArray()); @@ -803,12 +766,54 @@ protected function routeControllerWebMiddleware(Route $route) $this->assertTrue($route->getExceptions()->isEmpty()); $this->assertNull($route->getResponse()); + + $this->assertIsBool($route->isApi()); + $this->assertFalse($route->isApi()); + + $this->assertIsBool($route->isWeb()); + $this->assertFalse($route->isWeb()); + } + + protected function routeClosure(Route $route) + { + $this->assertIsInt($route->getPriority()); + $this->assertSame(16, $route->getPriority()); + + $this->assertIsArray($route->getMethods()); + $this->assertSame(['GET', 'HEAD'], $route->getMethods()); + + $this->assertNull($route->getDomain()); + + $this->assertIsString($route->getPath()); + $this->assertSame('closure', $route->getPath()); + + $this->assertIsString($route->getName()); + $this->assertSame('closure', $route->getName()); + + $this->assertNull($route->getModule()); + + $this->assertIsString($route->getAction()); + $this->assertSame('Closure', $route->getAction()); + + $this->assertIsArray($route->getMiddlewares()); + $this->assertSame([], $route->getMiddlewares()); + + $this->assertIsBool($route->getDeprecated()); + $this->assertFalse($route->getDeprecated()); + + $this->assertNull($route->getSummary()); + $this->assertNull($route->getDescription()); + + $this->assertIsArray($route->getExceptions()->toArray()); + $this->assertSame([], $route->getExceptions()->toArray()); + $this->assertTrue($route->getExceptions()->isEmpty()); + $this->assertNull($route->getResponse()); $this->assertIsBool($route->isApi()); $this->assertFalse($route->isApi()); $this->assertIsBool($route->isWeb()); - $this->assertTrue($route->isWeb()); + $this->assertFalse($route->isWeb()); } }