From 55fcf273623cc5d23e0cbdcf1e82b22d658eedc2 Mon Sep 17 00:00:00 2001 From: Amine Ben hammou Date: Wed, 18 Jan 2017 14:18:58 +0000 Subject: [PATCH] add support for lumen 5.3.x --- .../tests/acceptance/RouteCommandCept.php | 35 ++++++++++++++++++- src/Commands/RouteCommand.php | 10 ++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/lumen-test/tests/acceptance/RouteCommandCept.php b/lumen-test/tests/acceptance/RouteCommandCept.php index 446fb74..d22918c 100644 --- a/lumen-test/tests/acceptance/RouteCommandCept.php +++ b/lumen-test/tests/acceptance/RouteCommandCept.php @@ -58,4 +58,37 @@ $I->writeToFile('./app/Http/routes.php', 'get("/", function () use ($app) { return $app->welcome(); }); -'); \ No newline at end of file +'); + + +$I->wantTo('run wn:routes in Lumen 5.3+'); +mkdir('./routes'); +$I->writeToFile('./routes/web.php', 'get("/", function () use ($app) { + return $app->version(); +}); +'); + +$I->runShellCommand('php artisan wn:route foo --controller=customController'); +$I->seeInShellOutput('foo routes generated'); +$I->openFile('./routes/web.php'); +$I->seeInThisFile(" +\$app->get('foo', 'customController@all'); +\$app->get('foo/{id}', 'customController@get'); +\$app->post('foo', 'customController@add'); +\$app->put('foo/{id}', 'customController@put'); +\$app->delete('foo/{id}', 'customController@remove'); +"); +$I->deleteDir('./routes'); diff --git a/src/Commands/RouteCommand.php b/src/Commands/RouteCommand.php index 3e469c9..da619bf 100644 --- a/src/Commands/RouteCommand.php +++ b/src/Commands/RouteCommand.php @@ -13,7 +13,11 @@ class RouteCommand extends BaseCommand { { $resource = $this->argument('resource'); - $content = $this->fs->get('./app/Http/routes.php'); + $routesPath = './routes/web.php'; + if (! $this->fs->exists($routesPath)) + $routesPath = './app/Http/routes.php'; + + $content = $this->fs->get($routesPath); $content .= PHP_EOL . $this->getTemplate('routes') ->with([ @@ -22,7 +26,7 @@ class RouteCommand extends BaseCommand { ]) ->get(); - $this->save($content, './app/Http/routes.php', "{$resource} routes", true); + $this->save($content, $routesPath, "{$resource} routes", true); } protected function getController() @@ -34,4 +38,4 @@ class RouteCommand extends BaseCommand { return $controller; } -} \ No newline at end of file +}