diff --git a/.travis.yml b/.travis.yml index 87f9f300..d1a607ff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ -# env: -# - LARAVEL_VERSION="^6.0" TESTBENCH_VERSION="~4.0" REDIS_DRIVER=phpredis +env: + - LARAVEL_VERSION="^7.0" + - LARAVEL_VERSION="^6.0" -language: php -php: - - '7.2' +# language: php +# php: +# - '7.4' services: - docker @@ -11,10 +12,9 @@ services: before_install: - docker-compose up -d -# install: -# - travis_retry docker-compose exec test composer require --no-interaction "laravel/framework:$LARAVEL_VERSION" "orchestra/testbench:$TESTBENCH_VERSION" 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: - export DB_USERNAME=root DB_PASSWORD="" DB_DATABASE=tenancy CODECOV_TOKEN="24382d15-84e7-4a55-bea4-c4df96a24a9b" diff --git a/Dockerfile b/Dockerfile index 285a645f..75132249 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,32 +4,35 @@ LABEL maintainer="Samuel Štancl" ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get update \ - && apt-get install -y curl zip unzip git sqlite3 \ - php7.2-fpm php7.2-cli \ - php7.2-pgsql php7.2-sqlite3 php7.2-gd \ - php7.2-curl php7.2-memcached \ - php7.2-imap php7.2-mysql php7.2-mbstring \ - php7.2-xml php7.2-zip php7.2-bcmath php7.2-soap \ - php7.2-intl php7.2-readline php7.2-xdebug \ +RUN apt-get update +RUN apt-get install -y software-properties-common +RUN add-apt-repository -y ppa:ondrej/php + +RUN apt-get install -y curl zip unzip git sqlite3 \ + php7.4-fpm php7.4-cli \ + php7.4-pgsql php7.4-sqlite3 php7.4-gd \ + 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 -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \ && mkdir /run/php 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 echo "extension=redis.so" > /etc/php/7.2/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.2/mods-available/redis.ini /etc/php/7.2/cli/conf.d/20-redis.ini +RUN echo "extension=redis.so" > /etc/php/7.4/mods-available/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.4/mods-available/redis.ini /etc/php/7.4/cli/conf.d/20-redis.ini 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 \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* -WORKDIR /var/www/html \ No newline at end of file +WORKDIR /var/www/html diff --git a/composer.json b/composer.json index 21e4f143..d68dd1a7 100644 --- a/composer.json +++ b/composer.json @@ -11,17 +11,16 @@ ], "require": { "ext-json": "*", - "illuminate/support": "^6.0", + "illuminate/support": "^6.0|^7.0", "facade/ignition-contracts": "^1.0", "ramsey/uuid": "^3.7" }, "require-dev": { - "vlucas/phpdotenv": "^3.3", - "laravel/telescope": "^2.0", - "laravel/framework": "^6.0", - "orchestra/testbench-browser-kit": "^4.0", + "vlucas/phpdotenv": "^3.3|^4.0", + "laravel/framework": "^6.0|^7.0", + "orchestra/testbench-browser-kit": "^4.0|^5.0", "league/flysystem-aws-s3-v3": "~1.0", - "phpunit/phpcov": "^6.0" + "phpunit/phpcov": "^6.0|^7.0" }, "autoload": { "psr-4": { diff --git a/src/Commands/Install.php b/src/Commands/Install.php index 426bf1d3..224d1ded 100644 --- a/src/Commands/Install.php +++ b/src/Commands/Install.php @@ -36,13 +36,7 @@ class Install extends Command ]); $this->info('✔️ Created config/tenancy.php'); - $newKernel = str_replace( - 'protected $middlewarePriority = [', - "protected \$middlewarePriority = [ - \Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class, - \Stancl\Tenancy\Middleware\InitializeTenancy::class,", - file_get_contents(app_path('Http/Kernel.php')) - ); + $newKernel = $this->setMiddlewarePriority(); $newKernel = str_replace("'web' => [", "'web' => [ \Stancl\Tenancy\Middleware\PreventAccessFromTenantDomains::class,", $newKernel); @@ -77,4 +71,34 @@ class Install extends Command $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')) + ); + } + } } diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index 6bcf6fd9..39bb46e2 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -127,7 +127,11 @@ class CommandsTest extends TestCase 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') ->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_000020_create_domains_table.php')); $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 */ diff --git a/tests/Etc/defaultHttpKernel.stub b/tests/Etc/defaultHttpKernelv6.stub similarity index 100% rename from tests/Etc/defaultHttpKernel.stub rename to tests/Etc/defaultHttpKernelv6.stub diff --git a/tests/Etc/defaultHttpKernelv7.stub b/tests/Etc/defaultHttpKernelv7.stub new file mode 100644 index 00000000..d98a24d5 --- /dev/null +++ b/tests/Etc/defaultHttpKernelv7.stub @@ -0,0 +1,66 @@ + [ + \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, + ]; +} \ No newline at end of file diff --git a/tests/Etc/modifiedHttpKernel.stub b/tests/Etc/modifiedHttpKernelv6.stub similarity index 100% rename from tests/Etc/modifiedHttpKernel.stub rename to tests/Etc/modifiedHttpKernelv6.stub diff --git a/tests/Etc/modifiedHttpKernelv7.stub b/tests/Etc/modifiedHttpKernelv7.stub new file mode 100644 index 00000000..037a57f4 --- /dev/null +++ b/tests/Etc/modifiedHttpKernelv7.stub @@ -0,0 +1,80 @@ + [ + \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, + ]; +} \ No newline at end of file