From 4fcc171e8edfcd384f5e87fd9b0da80f0b89e66f Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 15 Jul 2022 17:52:57 +0900 Subject: [PATCH] fix: shield:setup adds routes in wrong location --- src/Commands/Setup.php | 2 +- tests/Commands/Setup/ContentReplacerTest.php | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Commands/Setup.php b/src/Commands/Setup.php index 45473a2af..b9c01f48b 100644 --- a/src/Commands/Setup.php +++ b/src/Commands/Setup.php @@ -211,7 +211,7 @@ private function setupRoutes() $file = 'Config/Routes.php'; $check = 'service(\'auth\')->routes($routes);'; - $pattern = '/(.*)(\n' . preg_quote('$routes->', '/') . '[^\n]+?\n)/su'; + $pattern = '/(.*)(\n' . preg_quote('$routes->', '/') . '[^\n]+?;\n)/su'; $replace = '$1$2' . "\n" . $check . "\n"; $this->add($file, $check, $pattern, $replace); diff --git a/tests/Commands/Setup/ContentReplacerTest.php b/tests/Commands/Setup/ContentReplacerTest.php index 7f750d75e..a861bc849 100644 --- a/tests/Commands/Setup/ContentReplacerTest.php +++ b/tests/Commands/Setup/ContentReplacerTest.php @@ -61,6 +61,11 @@ public function testAddAfter(): void $routes->get('/', 'Home::index'); + $routes->group('admin', static function ($routes) { + $routes->get('users', 'Admin\Users::index'); + $routes->get('blog', 'Admin\Blog::index'); + }); + /** * You will have access to the $routes object within that file without * needing to reload it. @@ -69,7 +74,7 @@ public function testAddAfter(): void FILE; $text = 'service(\'auth\')->routes($routes);'; - $pattern = '/(.*)(\n' . preg_quote('$routes->', '/') . '[^\n]+?\n)/su'; + $pattern = '/(.*)(\n' . preg_quote('$routes->', '/') . '[^\n]+?;\n)/su'; $replace = '$1$2' . "\n" . $text . "\n"; $output = $replacer->add($content, $text, $pattern, $replace); @@ -88,6 +93,11 @@ public function testAddAfter(): void service('auth')->routes($routes); + $routes->group('admin', static function ($routes) { + $routes->get('users', 'Admin\Users::index'); + $routes->get('blog', 'Admin\Blog::index'); + }); + /** * You will have access to the $routes object within that file without * needing to reload it.