From 416fe2af9fb943daf8c8ad70f69898ba7e775b4b Mon Sep 17 00:00:00 2001 From: Rathes Sachchithananthan Date: Mon, 1 Jan 2018 15:32:04 +0100 Subject: [PATCH 1/5] Adds route() method --- This method allows the user to add Mozhi at the exact place he expects. Therefore the routes are not loaded on boot of the ServiceProvider anymore, but explicitly by adding the method that was added in the commit --- composer.json | 5 ++++- src/Facades/Mozhi.php | 26 ++++++++++++++++++++++++++ src/MozhiServiceProvider.php | 3 --- tests/RouteResolverTest.php | 13 +++++++++++++ tests/TestCase.php | 14 ++++++++++++-- 5 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 src/Facades/Mozhi.php diff --git a/composer.json b/composer.json index de46ed1..bc995d4 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,10 @@ "laravel": { "providers": [ "Aheenam\\Mozhi\\MozhiServiceProvider" - ] + ], + "aliases": { + "Mozhi": "Aheenam\\Mozhi\\Facades\\Mozhi" + } } }, "scripts": { diff --git a/src/Facades/Mozhi.php b/src/Facades/Mozhi.php new file mode 100644 index 0000000..0b3e0ed --- /dev/null +++ b/src/Facades/Mozhi.php @@ -0,0 +1,26 @@ +loadViewsFrom(base_path($this->app['config']['mozhi.theme_path']), 'theme'); - - // load the routes - $this->loadRoutesFrom(__DIR__ . '/routes/web.php'); } diff --git a/tests/RouteResolverTest.php b/tests/RouteResolverTest.php index 3ea2af5..eea64fe 100644 --- a/tests/RouteResolverTest.php +++ b/tests/RouteResolverTest.php @@ -3,6 +3,7 @@ use Aheenam\Mozhi\Models\Page; use Aheenam\Mozhi\RouteResolver; +use Mozhi; class RouteResolverTest extends TestCase { @@ -25,4 +26,16 @@ public function it_returns_null_if_page_does_not_exists () $this->assertNull($page); } + /** @test */ + public function it_resolves_routes_only_where_it_was_defined () + { + $this->app['router']->group(['prefix' => 'test-prefix'], function () { + \Mozhi::routes(); + }); + + $this->get('/test-prefix')->assertStatus(200); + $this->get('/')->assertStatus(404); + + } + } \ No newline at end of file diff --git a/tests/TestCase.php b/tests/TestCase.php index 9ffffe7..a5b0f8b 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -28,6 +28,16 @@ protected function getPackageProviders($app) return [MozhiServiceProvider::class]; } + /** + * add the package facades + */ + protected function getPackageAliases($app) + { + return [ + 'Mozhi' => \Aheenam\Mozhi\Facades\Mozhi::class + ]; + } + /** * Define environment setup. * @@ -42,9 +52,9 @@ protected function getEnvironmentSetUp($app) // Setup default database to use sqlite :memory: $app['config']->set('database.default', 'testing'); $app['config']->set('database.connections.testing', [ - 'driver' => 'sqlite', + 'driver' => 'sqlite', 'database' => ':memory:', - 'prefix' => '', + 'prefix' => '', ]); $app['config']->set('mozhi.content_disk', 'content'); From e1807e41ad976c8b9bb3e4a7e5d05ea5b6c3550a Mon Sep 17 00:00:00 2001 From: Rathes Sachchithananthan Date: Mon, 1 Jan 2018 15:37:24 +0100 Subject: [PATCH 2/5] Update tests --- As older tests did not use the previously added route() method the needed an update. --- tests/FrontControllerTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/FrontControllerTest.php b/tests/FrontControllerTest.php index a98c8f2..17bbe20 100644 --- a/tests/FrontControllerTest.php +++ b/tests/FrontControllerTest.php @@ -10,6 +10,8 @@ class FrontControllerTest extends TestCase /** @test */ public function it_renders_correct_view_on_route() { + \Mozhi::routes(); + $response = $this->get('/no-template') ->assertStatus(200); @@ -26,6 +28,7 @@ public function it_returns_a_404_if_route_not_found() /** @test */ public function it_looks_for_a_index_page_if_slug_is_empty() { + \Mozhi::routes(); $response = $this->get('/') ->assertStatus(200); From eebc6c945f9d577e7ae944a7028e840b41cdf85a Mon Sep 17 00:00:00 2001 From: Rathes Sachchithananthan Date: Fri, 5 Jan 2018 18:00:15 +0100 Subject: [PATCH 3/5] Apply fixes by StyleCI --- src/Facades/Mozhi.php | 7 ++++--- tests/RouteResolverTest.php | 5 +---- tests/TestCase.php | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Facades/Mozhi.php b/src/Facades/Mozhi.php index 0b3e0ed..0cc434b 100644 --- a/src/Facades/Mozhi.php +++ b/src/Facades/Mozhi.php @@ -1,4 +1,5 @@ app['router']->group(['prefix' => 'test-prefix'], function () { \Mozhi::routes(); @@ -34,7 +33,5 @@ public function it_resolves_routes_only_where_it_was_defined () $this->get('/test-prefix')->assertStatus(200); $this->get('/')->assertStatus(404); - } - } diff --git a/tests/TestCase.php b/tests/TestCase.php index 3185b2e..fa2c22e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -28,12 +28,12 @@ protected function getPackageProviders($app) } /** - * add the package facades + * add the package facades. */ protected function getPackageAliases($app) { return [ - 'Mozhi' => \Aheenam\Mozhi\Facades\Mozhi::class + 'Mozhi' => \Aheenam\Mozhi\Facades\Mozhi::class, ]; } From 51360fda02cfb300f1f7fb16768d9bfd1f6e70ea Mon Sep 17 00:00:00 2001 From: Rathes Sachchithananthan Date: Fri, 5 Jan 2018 18:01:48 +0100 Subject: [PATCH 4/5] Apply fixes by StyleCI --- src/Facades/Mozhi.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Facades/Mozhi.php b/src/Facades/Mozhi.php index 0cc434b..00f5183 100644 --- a/src/Facades/Mozhi.php +++ b/src/Facades/Mozhi.php @@ -23,5 +23,4 @@ public static function routes() { require __DIR__.'/../routes/web.php'; } - } \ No newline at end of file From 01355dcd770502f3da51dbaf55f561cebf1af423 Mon Sep 17 00:00:00 2001 From: Rathes Sachchithananthan Date: Fri, 5 Jan 2018 18:08:43 +0100 Subject: [PATCH 5/5] Apply Fixes by StyleCI --- src/Facades/Mozhi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Facades/Mozhi.php b/src/Facades/Mozhi.php index 00f5183..ce81d51 100644 --- a/src/Facades/Mozhi.php +++ b/src/Facades/Mozhi.php @@ -23,4 +23,4 @@ public static function routes() { require __DIR__.'/../routes/web.php'; } -} \ No newline at end of file +}