Skip to content

Commit

Permalink
Merge pull request #297 from kenjis/fix-setup-routes
Browse files Browse the repository at this point in the history
fix: shield:setup adds routes in wrong location
  • Loading branch information
kenjis authored Jul 15, 2022
2 parents dadd7b3 + 4fcc171 commit 951ca47
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Commands/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion tests/Commands/Setup/ContentReplacerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);

Expand All @@ -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.
Expand Down

0 comments on commit 951ca47

Please sign in to comment.