Skip to content

Commit 951ca47

Browse files
authored
Merge pull request #297 from kenjis/fix-setup-routes
fix: shield:setup adds routes in wrong location
2 parents dadd7b3 + 4fcc171 commit 951ca47

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Commands/Setup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private function setupRoutes()
211211
$file = 'Config/Routes.php';
212212

213213
$check = 'service(\'auth\')->routes($routes);';
214-
$pattern = '/(.*)(\n' . preg_quote('$routes->', '/') . '[^\n]+?\n)/su';
214+
$pattern = '/(.*)(\n' . preg_quote('$routes->', '/') . '[^\n]+?;\n)/su';
215215
$replace = '$1$2' . "\n" . $check . "\n";
216216

217217
$this->add($file, $check, $pattern, $replace);

tests/Commands/Setup/ContentReplacerTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public function testAddAfter(): void
6161
6262
$routes->get('/', 'Home::index');
6363
64+
$routes->group('admin', static function ($routes) {
65+
$routes->get('users', 'Admin\Users::index');
66+
$routes->get('blog', 'Admin\Blog::index');
67+
});
68+
6469
/**
6570
* You will have access to the $routes object within that file without
6671
* needing to reload it.
@@ -69,7 +74,7 @@ public function testAddAfter(): void
6974
FILE;
7075

7176
$text = 'service(\'auth\')->routes($routes);';
72-
$pattern = '/(.*)(\n' . preg_quote('$routes->', '/') . '[^\n]+?\n)/su';
77+
$pattern = '/(.*)(\n' . preg_quote('$routes->', '/') . '[^\n]+?;\n)/su';
7378
$replace = '$1$2' . "\n" . $text . "\n";
7479
$output = $replacer->add($content, $text, $pattern, $replace);
7580

@@ -88,6 +93,11 @@ public function testAddAfter(): void
8893
8994
service('auth')->routes($routes);
9095
96+
$routes->group('admin', static function ($routes) {
97+
$routes->get('users', 'Admin\Users::index');
98+
$routes->get('blog', 'Admin\Blog::index');
99+
});
100+
91101
/**
92102
* You will have access to the $routes object within that file without
93103
* needing to reload it.

0 commit comments

Comments
 (0)