mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 13:54:03 +00:00
Laravel 7 support (#304)
* Laravel 7 support * Remove language from travis.yml * Fix travis.yml * Consistent indentation in travis.yml * Use dev-master for phpcov * Cleanup * switch up envs * verify both laravel versions are used * 6 -> 7 * Fix travis yml * Use stable phpcov * Different installation for Laravel 7 * Indentation * Fix dockerfile * Fix indentation * Fix tests * Remove fail() calls
This commit is contained in:
parent
526f0826a4
commit
30bab68b6a
9 changed files with 218 additions and 37 deletions
16
.travis.yml
16
.travis.yml
|
|
@ -1,9 +1,10 @@
|
||||||
# env:
|
env:
|
||||||
# - LARAVEL_VERSION="^6.0" TESTBENCH_VERSION="~4.0" REDIS_DRIVER=phpredis
|
- LARAVEL_VERSION="^7.0"
|
||||||
|
- LARAVEL_VERSION="^6.0"
|
||||||
|
|
||||||
language: php
|
# language: php
|
||||||
php:
|
# php:
|
||||||
- '7.2'
|
# - '7.4'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- docker
|
- docker
|
||||||
|
|
@ -11,10 +12,9 @@ services:
|
||||||
before_install:
|
before_install:
|
||||||
- docker-compose up -d
|
- docker-compose up -d
|
||||||
|
|
||||||
# install:
|
|
||||||
# - travis_retry docker-compose exec test composer require --no-interaction "laravel/framework:$LARAVEL_VERSION" "orchestra/testbench:$TESTBENCH_VERSION"
|
|
||||||
install:
|
install:
|
||||||
- travis_retry docker-compose exec test composer install --no-interaction
|
- travis_retry docker-compose exec test composer require --no-interaction "laravel/framework:$LARAVEL_VERSION"
|
||||||
|
- travis_retry docker-compose exec test composer install --no-interaction
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- export DB_USERNAME=root DB_PASSWORD="" DB_DATABASE=tenancy CODECOV_TOKEN="24382d15-84e7-4a55-bea4-c4df96a24a9b"
|
- export DB_USERNAME=root DB_PASSWORD="" DB_DATABASE=tenancy CODECOV_TOKEN="24382d15-84e7-4a55-bea4-c4df96a24a9b"
|
||||||
|
|
|
||||||
29
Dockerfile
29
Dockerfile
|
|
@ -4,29 +4,32 @@ LABEL maintainer="Samuel Štancl"
|
||||||
|
|
||||||
ENV DEBIAN_FRONTEND=noninteractive
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
RUN apt-get update \
|
RUN apt-get update
|
||||||
&& apt-get install -y curl zip unzip git sqlite3 \
|
RUN apt-get install -y software-properties-common
|
||||||
php7.2-fpm php7.2-cli \
|
RUN add-apt-repository -y ppa:ondrej/php
|
||||||
php7.2-pgsql php7.2-sqlite3 php7.2-gd \
|
|
||||||
php7.2-curl php7.2-memcached \
|
RUN apt-get install -y curl zip unzip git sqlite3 \
|
||||||
php7.2-imap php7.2-mysql php7.2-mbstring \
|
php7.4-fpm php7.4-cli \
|
||||||
php7.2-xml php7.2-zip php7.2-bcmath php7.2-soap \
|
php7.4-pgsql php7.4-sqlite3 php7.4-gd \
|
||||||
php7.2-intl php7.2-readline php7.2-xdebug \
|
php7.4-curl php7.4-memcached \
|
||||||
|
php7.4-imap php7.4-mysql php7.4-mbstring \
|
||||||
|
php7.4-xml php7.4-zip php7.4-bcmath php7.4-soap \
|
||||||
|
php7.4-intl php7.4-readline php7.4-xdebug \
|
||||||
php-msgpack php-igbinary \
|
php-msgpack php-igbinary \
|
||||||
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
|
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
|
||||||
&& mkdir /run/php
|
&& mkdir /run/php
|
||||||
|
|
||||||
RUN apt-get install -y python3
|
RUN apt-get install -y python3
|
||||||
|
|
||||||
RUN apt-get install -y php7.2-dev php-pear
|
RUN apt-get install -y php7.4-dev php-pear
|
||||||
|
|
||||||
RUN pecl install redis-4.3.0
|
RUN pecl install redis-4.3.0
|
||||||
RUN echo "extension=redis.so" > /etc/php/7.2/mods-available/redis.ini
|
RUN echo "extension=redis.so" > /etc/php/7.4/mods-available/redis.ini
|
||||||
RUN ln -sf /etc/php/7.2/mods-available/redis.ini /etc/php/7.2/fpm/conf.d/20-redis.ini
|
RUN ln -sf /etc/php/7.4/mods-available/redis.ini /etc/php/7.4/fpm/conf.d/20-redis.ini
|
||||||
RUN ln -sf /etc/php/7.2/mods-available/redis.ini /etc/php/7.2/cli/conf.d/20-redis.ini
|
RUN ln -sf /etc/php/7.4/mods-available/redis.ini /etc/php/7.4/cli/conf.d/20-redis.ini
|
||||||
|
|
||||||
RUN pecl install xdebug
|
RUN pecl install xdebug
|
||||||
RUN echo 'zend_extension=/usr/lib/php/20170718/xdebug.so' > /etc/php/7.2/cli/conf.d/20-xdebug.ini
|
RUN echo 'zend_extension=/usr/lib/php/20190902/xdebug.so' > /etc/php/7.4/cli/conf.d/20-xdebug.ini
|
||||||
|
|
||||||
RUN apt-get -y autoremove \
|
RUN apt-get -y autoremove \
|
||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
|
|
|
||||||
|
|
@ -11,17 +11,16 @@
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"illuminate/support": "^6.0",
|
"illuminate/support": "^6.0|^7.0",
|
||||||
"facade/ignition-contracts": "^1.0",
|
"facade/ignition-contracts": "^1.0",
|
||||||
"ramsey/uuid": "^3.7"
|
"ramsey/uuid": "^3.7"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"vlucas/phpdotenv": "^3.3",
|
"vlucas/phpdotenv": "^3.3|^4.0",
|
||||||
"laravel/telescope": "^2.0",
|
"laravel/framework": "^6.0|^7.0",
|
||||||
"laravel/framework": "^6.0",
|
"orchestra/testbench-browser-kit": "^4.0|^5.0",
|
||||||
"orchestra/testbench-browser-kit": "^4.0",
|
|
||||||
"league/flysystem-aws-s3-v3": "~1.0",
|
"league/flysystem-aws-s3-v3": "~1.0",
|
||||||
"phpunit/phpcov": "^6.0"
|
"phpunit/phpcov": "^6.0|^7.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|
|
||||||
|
|
@ -36,13 +36,7 @@ class Install extends Command
|
||||||
]);
|
]);
|
||||||
$this->info('✔️ Created config/tenancy.php');
|
$this->info('✔️ Created config/tenancy.php');
|
||||||
|
|
||||||
$newKernel = str_replace(
|
$newKernel = $this->setMiddlewarePriority();
|
||||||
'protected $middlewarePriority = [',
|
|
||||||
"protected \$middlewarePriority = [
|
|
||||||
\Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class,
|
|
||||||
\Stancl\Tenancy\Middleware\InitializeTenancy::class,",
|
|
||||||
file_get_contents(app_path('Http/Kernel.php'))
|
|
||||||
);
|
|
||||||
|
|
||||||
$newKernel = str_replace("'web' => [", "'web' => [
|
$newKernel = str_replace("'web' => [", "'web' => [
|
||||||
\Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class,", $newKernel);
|
\Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class,", $newKernel);
|
||||||
|
|
@ -77,4 +71,34 @@ class Install extends Command
|
||||||
|
|
||||||
$this->comment('✨️ stancl/tenancy installed successfully.');
|
$this->comment('✨️ stancl/tenancy installed successfully.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function setMiddlewarePriority(): string
|
||||||
|
{
|
||||||
|
if (app()->version()[0] === '6') {
|
||||||
|
return str_replace(
|
||||||
|
'protected $middlewarePriority = [',
|
||||||
|
"protected \$middlewarePriority = [
|
||||||
|
\Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class,
|
||||||
|
\Stancl\Tenancy\Middleware\InitializeTenancy::class,",
|
||||||
|
file_get_contents(app_path('Http/Kernel.php'))
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return str_replace(
|
||||||
|
"];\n}",
|
||||||
|
"];\n\n protected \$middlewarePriority = [
|
||||||
|
\Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class,
|
||||||
|
\Stancl\Tenancy\Middleware\InitializeTenancy::class,
|
||||||
|
\Illuminate\Session\Middleware\StartSession::class,
|
||||||
|
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||||
|
\Illuminate\Contracts\Auth\Middleware\AuthenticatesRequests::class,
|
||||||
|
\Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||||
|
\Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||||
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
|
\Illuminate\Auth\Middleware\Authorize::class,
|
||||||
|
];
|
||||||
|
}",
|
||||||
|
file_get_contents(app_path('Http/Kernel.php'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,11 @@ class CommandsTest extends TestCase
|
||||||
mkdir($dir, 0777, true);
|
mkdir($dir, 0777, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
file_put_contents(app_path('Http/Kernel.php'), file_get_contents(__DIR__ . '/Etc/defaultHttpKernel.stub'));
|
if (app()->version()[0] === '6') {
|
||||||
|
file_put_contents(app_path('Http/Kernel.php'), file_get_contents(__DIR__ . '/Etc/defaultHttpKernelv6.stub'));
|
||||||
|
} else {
|
||||||
|
file_put_contents(app_path('Http/Kernel.php'), file_get_contents(__DIR__ . '/Etc/defaultHttpKernelv7.stub'));
|
||||||
|
}
|
||||||
|
|
||||||
$this->artisan('tenancy:install')
|
$this->artisan('tenancy:install')
|
||||||
->expectsQuestion('Do you wish to publish the migrations that create these tables?', 'yes');
|
->expectsQuestion('Do you wish to publish the migrations that create these tables?', 'yes');
|
||||||
|
|
@ -136,7 +140,12 @@ class CommandsTest extends TestCase
|
||||||
$this->assertFileExists(database_path('migrations/2019_09_15_000010_create_tenants_table.php'));
|
$this->assertFileExists(database_path('migrations/2019_09_15_000010_create_tenants_table.php'));
|
||||||
$this->assertFileExists(database_path('migrations/2019_09_15_000020_create_domains_table.php'));
|
$this->assertFileExists(database_path('migrations/2019_09_15_000020_create_domains_table.php'));
|
||||||
$this->assertDirectoryExists(database_path('migrations/tenant'));
|
$this->assertDirectoryExists(database_path('migrations/tenant'));
|
||||||
$this->assertSame(file_get_contents(__DIR__ . '/Etc/modifiedHttpKernel.stub'), file_get_contents(app_path('Http/Kernel.php')));
|
|
||||||
|
if (app()->version()[0] === '6') {
|
||||||
|
$this->assertSame(file_get_contents(__DIR__ . '/Etc/modifiedHttpKernelv6.stub'), file_get_contents(app_path('Http/Kernel.php')));
|
||||||
|
} else {
|
||||||
|
$this->assertSame(file_get_contents(__DIR__ . '/Etc/modifiedHttpKernelv7.stub'), file_get_contents(app_path('Http/Kernel.php')));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|
|
||||||
66
tests/Etc/defaultHttpKernelv7.stub
Normal file
66
tests/Etc/defaultHttpKernelv7.stub
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||||
|
|
||||||
|
class Kernel extends HttpKernel
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The application's global HTTP middleware stack.
|
||||||
|
*
|
||||||
|
* These middleware are run during every request to your application.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $middleware = [
|
||||||
|
\App\Http\Middleware\TrustProxies::class,
|
||||||
|
\Fruitcake\Cors\HandleCors::class,
|
||||||
|
\App\Http\Middleware\CheckForMaintenanceMode::class,
|
||||||
|
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||||
|
\App\Http\Middleware\TrimStrings::class,
|
||||||
|
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The application's route middleware groups.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $middlewareGroups = [
|
||||||
|
'web' => [
|
||||||
|
\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,
|
||||||
|
],
|
||||||
|
|
||||||
|
'api' => [
|
||||||
|
'throttle:60,1',
|
||||||
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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,
|
||||||
|
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||||
|
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||||
|
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||||
|
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
80
tests/Etc/modifiedHttpKernelv7.stub
Normal file
80
tests/Etc/modifiedHttpKernelv7.stub
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||||
|
|
||||||
|
class Kernel extends HttpKernel
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The application's global HTTP middleware stack.
|
||||||
|
*
|
||||||
|
* These middleware are run during every request to your application.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $middleware = [
|
||||||
|
\App\Http\Middleware\TrustProxies::class,
|
||||||
|
\Fruitcake\Cors\HandleCors::class,
|
||||||
|
\App\Http\Middleware\CheckForMaintenanceMode::class,
|
||||||
|
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||||
|
\App\Http\Middleware\TrimStrings::class,
|
||||||
|
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The application's route middleware groups.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $middlewareGroups = [
|
||||||
|
'web' => [
|
||||||
|
\Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class,
|
||||||
|
\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,
|
||||||
|
],
|
||||||
|
|
||||||
|
'api' => [
|
||||||
|
\Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class,
|
||||||
|
'throttle:60,1',
|
||||||
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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,
|
||||||
|
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||||
|
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||||
|
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||||
|
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $middlewarePriority = [
|
||||||
|
\Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class,
|
||||||
|
\Stancl\Tenancy\Middleware\InitializeTenancy::class,
|
||||||
|
\Illuminate\Session\Middleware\StartSession::class,
|
||||||
|
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||||
|
\Illuminate\Contracts\Auth\Middleware\AuthenticatesRequests::class,
|
||||||
|
\Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||||
|
\Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||||
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
|
\Illuminate\Auth\Middleware\Authorize::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue