diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..1433d9ac --- /dev/null +++ b/.travis.yml @@ -0,0 +1,17 @@ +language: php +php: + - '7.1' + - '7.2' + +branches: + only: + - master + +install: + - travis_retry composer install --no-interaction + +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 diff --git a/README.md b/README.md index 43e2fc4b..484c54bc 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) +![Code coverage](https://codecov.io/gh/stancl/tenancy/branch/master/graph/badge.svg) ### *A Laravel multi-database tenancy implementation that respects your code.* 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/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')); 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/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); + } +}