From 999507fe42f450da418f09dfb8e321feb99b3b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Fri, 1 Feb 2019 22:47:10 +0100 Subject: [PATCH 1/9] Begin work on tests --- .travis.yml | 6 +++ composer.json | 9 +++++ phpunit.xml | 31 +++++++++++++++ src/Testing/HttpKernel.php | 81 ++++++++++++++++++++++++++++++++++++++ tests/HelloWorldTest.php | 11 ++++++ tests/TestCase.php | 34 ++++++++++++++++ 6 files changed, 172 insertions(+) create mode 100644 .travis.yml create mode 100644 phpunit.xml create mode 100644 src/Testing/HttpKernel.php create mode 100644 tests/HelloWorldTest.php create mode 100644 tests/TestCase.php diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..8645f4ea --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: php +php: + - '7.1' + - '7.2' + +script: vendor/bin/phpunit \ No newline at end of file diff --git a/composer.json b/composer.json index 5513346c..3ee667cf 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,10 @@ "illuminate/support": "^5.7", "webpatser/laravel-uuid": "^3.0" }, + "require-dev": { + "orchestra/testbench": "~3.0", + "laravel/framework": "5.7.*" + }, "autoload": { "psr-4": { "Stancl\\Tenancy\\": "src/" @@ -21,6 +25,11 @@ "src/helpers.php" ] }, + "autoload-dev": { + "psr-4": { + "Stancl\\Tenancy\\Tests\\": "tests/" + } + }, "extra": { "laravel": { "providers": [ diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 00000000..2e630c0b --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,31 @@ + + + + + ./tests + + + + + ./app + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Testing/HttpKernel.php b/src/Testing/HttpKernel.php new file mode 100644 index 00000000..88553ec7 --- /dev/null +++ b/src/Testing/HttpKernel.php @@ -0,0 +1,81 @@ + [ + \App\Http\Middleware\EncryptCookies::class, + \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, + \Illuminate\Session\Middleware\StartSession::class, + // \Illuminate\Session\Middleware\AuthenticateSession::class, + \Illuminate\View\Middleware\ShareErrorsFromSession::class, + \App\Http\Middleware\VerifyCsrfToken::class, + \Illuminate\Routing\Middleware\SubstituteBindings::class, + ], + + 'tenancy' => [ + \Stancl\Tenancy\Middleware\InitializeTenancy::class, + ], + + 'api' => [ + 'throttle:60,1', + 'bindings', + ], + ]; + + /** + * The application's route middleware. + * + * These middleware may be assigned to groups or used individually. + * + * @var array + */ + protected $routeMiddleware = [ + 'auth' => \App\Http\Middleware\Authenticate::class, + 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, + 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, + 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, + 'can' => \Illuminate\Auth\Middleware\Authorize::class, + 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, + 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, + 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, + 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, + + 'tenancy' => \Stancl\Tenancy\Middleware\InitializeTenancy::class, + ]; + + /** + * The priority-sorted list of middleware. + * + * This forces non-global middleware to always be in the given order. + * + * @var array + */ + protected $middlewarePriority = [ + \Stancl\Tenancy\Middleware\InitializeTenancy::class, + ]; +} diff --git a/tests/HelloWorldTest.php b/tests/HelloWorldTest.php new file mode 100644 index 00000000..f27efce1 --- /dev/null +++ b/tests/HelloWorldTest.php @@ -0,0 +1,11 @@ +assertTrue(true); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 00000000..a33d3ad7 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,34 @@ +singleton('Illuminate\Contracts\Http\Kernel', \Stancl\Tenancy\Testing\HttpKernel::class); + } +} From 6c5d9aa441d5479a521cc4d3ad02741e47bb710b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Fri, 1 Feb 2019 23:15:01 +0100 Subject: [PATCH 2/9] Add install section to .travis.yml --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8645f4ea..bc905319 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,7 @@ php: - '7.1' - '7.2' +install: + - travis_retry composer install --no-interaction --prefer-source --dev + script: vendor/bin/phpunit \ No newline at end of file From 80da9e1cf56573301d07cb233e404ed2ebad29e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Fri, 1 Feb 2019 23:19:05 +0100 Subject: [PATCH 3/9] Remove --prefer-source flag --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bc905319..6b87c31e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,6 @@ php: - '7.2' install: - - travis_retry composer install --no-interaction --prefer-source --dev + - travis_retry composer install --no-interaction --dev script: vendor/bin/phpunit \ No newline at end of file From 5caec784bfa0717db7e43c9ae004d4bd9ac9cd5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Fri, 1 Feb 2019 23:28:42 +0100 Subject: [PATCH 4/9] Remove unnecessary --dev flag --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6b87c31e..bb8990ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,6 @@ php: - '7.2' install: - - travis_retry composer install --no-interaction --dev + - travis_retry composer install --no-interaction script: vendor/bin/phpunit \ No newline at end of file From 6b57d20c9b82eb4e4f5ede6f97db367aca0d6be9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Fri, 1 Feb 2019 23:59:08 +0100 Subject: [PATCH 5/9] Add Codecov support --- .travis.yml | 5 ++++- README.md | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bb8990ec..2b7d3028 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,4 +6,7 @@ php: install: - travis_retry composer install --no-interaction -script: vendor/bin/phpunit \ No newline at end of file +script: vendor/bin/phpunit --coverage-clover=coverage.xml + +after_success: + - bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/README.md b/README.md index 43e2fc4b..ef23d722 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ ![Laravel 5.7](https://img.shields.io/badge/laravel-5.7-red.svg) ![Beta - experimental](https://img.shields.io/badge/beta-experimental-yellow.svg) +![Travis CI build](https://travis-ci.com/stancl/tenancy.svg?branch=master) +![codecov](https://codecov.io/gh/stancl/tenancy/branch/master/graph/badge.svg) ### *A Laravel multi-database tenancy implementation that respects your code.* From 1547c134f1e69422e7070d21ea7746b8bfe8b099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sat, 2 Feb 2019 00:03:29 +0100 Subject: [PATCH 6/9] Make TenantRouteServiceProvider check if the route file exists before requiring it --- src/TenantRouteServiceProvider.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/TenantRouteServiceProvider.php b/src/TenantRouteServiceProvider.php index b0a54e7a..92897780 100644 --- a/src/TenantRouteServiceProvider.php +++ b/src/TenantRouteServiceProvider.php @@ -9,7 +9,8 @@ class TenantRouteServiceProvider extends RouteServiceProvider { public function map() { - if (! in_array(request()->getHost(), $this->app['config']['tenancy.exempt_domains'] ?? [])) { + if (! in_array(request()->getHost(), $this->app['config']['tenancy.exempt_domains'] ?? []) + && file_exists(base_path('routes/tenant.php'))) { Route::middleware(['web', 'tenancy']) ->namespace($this->app['config']['tenant_route_namespace'] ?? 'App\Http\Controllers') ->group(base_path('routes/tenant.php')); From e251a2b8847860f9aa6d2cad5cfb6f4bcb6e7958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sat, 2 Feb 2019 00:10:16 +0100 Subject: [PATCH 7/9] Remove HelloWorldTest --- .travis.yml | 4 ++++ tests/HelloWorldTest.php | 11 ----------- 2 files changed, 4 insertions(+), 11 deletions(-) delete mode 100644 tests/HelloWorldTest.php diff --git a/.travis.yml b/.travis.yml index 2b7d3028..1cba89eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,10 @@ php: - '7.1' - '7.2' +branches: + only: + - master + install: - travis_retry composer install --no-interaction diff --git a/tests/HelloWorldTest.php b/tests/HelloWorldTest.php deleted file mode 100644 index f27efce1..00000000 --- a/tests/HelloWorldTest.php +++ /dev/null @@ -1,11 +0,0 @@ -assertTrue(true); - } -} From 79e3be78ff49c97404af3df0c8b8820fc02202cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sat, 2 Feb 2019 00:12:08 +0100 Subject: [PATCH 8/9] Add Codecov token --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 1cba89eb..1433d9ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,5 @@ install: script: vendor/bin/phpunit --coverage-clover=coverage.xml after_success: + - export CODECOV_TOKEN="24382d15-84e7-4a55-bea4-c4df96a24a9b" - bash <(curl -s https://codecov.io/bash) \ No newline at end of file From d1b2775eee28c506a0c400efcaf0cf0df8a817b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sat, 2 Feb 2019 00:15:00 +0100 Subject: [PATCH 9/9] Change codecov alt [ci skip] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ef23d722..484c54bc 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ![Laravel 5.7](https://img.shields.io/badge/laravel-5.7-red.svg) ![Beta - experimental](https://img.shields.io/badge/beta-experimental-yellow.svg) ![Travis CI build](https://travis-ci.com/stancl/tenancy.svg?branch=master) -![codecov](https://codecov.io/gh/stancl/tenancy/branch/master/graph/badge.svg) +![Code coverage](https://codecov.io/gh/stancl/tenancy/branch/master/graph/badge.svg) ### *A Laravel multi-database tenancy implementation that respects your code.*