From 78fd7d43f6f609be9a0d5700c811d40878298c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= <33033094+stancl@users.noreply.github.com> Date: Wed, 27 Feb 2019 18:22:34 +0100 Subject: [PATCH] Add 5.8 support (#33) --- .gitignore | 1 + .travis.yml | 7 +++++-- README.md | 4 +++- composer.json | 12 +++++++----- tests/CacheManagerTest.php | 2 +- tests/CommandsTest.php | 12 ++++++++---- tests/TestCase.php | 18 ++++++++++++++++-- 7 files changed, 41 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index aa20da34..53129d62 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ composer.lock vendor/ .vscode/ psysh +.phpunit.result.cache diff --git a/.travis.yml b/.travis.yml index a3f04c48..5edacf55 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,9 @@ env: - - DB_USERNAME=root DB_PASSWORD="" DB_DATABASE=travis_tenancy CODECOV_TOKEN="24382d15-84e7-4a55-bea4-c4df96a24a9b" + - LARAVEL_VERSION="5.7.*" TESTBENCH_VERSION="~3.7" + - LARAVEL_VERSION="5.8.*" TESTBENCH_VERSION="~3.8" language: php php: - - '7.2' - '7.1' services: @@ -14,10 +14,13 @@ before_install: - echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini install: + - composer require "laravel/framework:$LARAVEL_VERSION" "orchestra/testbench:$TESTBENCH_VERSION" - travis_retry composer install --no-interaction before_script: - mysql -e 'CREATE DATABASE travis_tenancy;' + - export DB_USERNAME=root DB_PASSWORD="" DB_DATABASE=travis_tenancy CODECOV_TOKEN="24382d15-84e7-4a55-bea4-c4df96a24a9b" + - cat vendor/laravel/framework/src/Illuminate/Foundation/Application.php| grep 'const VERSION' script: vendor/bin/phpunit -v --coverage-clover=coverage.xml diff --git a/README.md b/README.md index 712a829e..6506de85 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Tenancy -[![Laravel 5.7](https://img.shields.io/badge/laravel-5.7-red.svg)](https://laravel.com) +[![Laravel 5.7+](https://img.shields.io/badge/laravel-5.7+-red.svg)](https://laravel.com) [![Latest Stable Version](https://poser.pugx.org/stancl/tenancy/version)](https://packagist.org/packages/stancl/tenancy) [![Travis CI build](https://travis-ci.com/stancl/tenancy.svg?branch=master)](https://travis-ci.com/stancl/tenancy) [![codecov](https://codecov.io/gh/stancl/tenancy/branch/master/graph/badge.svg)](https://codecov.io/gh/stancl/tenancy) @@ -25,6 +25,8 @@ composer require stancl/tenancy This package follows [semantic versioning 2.0.0](https://semver.org). Each major release will have its own branch, so that bug fixes can be provided for older versions as well. +Both Laravel 5.7 and 5.8 are supported. + ### Configuring the `InitializeTenancy` middleware The `TenancyServiceProvider` automatically adds the `tenancy` middleware group which can be assigned to routes. You only need to make sure the middleware is top priority. diff --git a/composer.json b/composer.json index 748b1b24..3dedc135 100644 --- a/composer.json +++ b/composer.json @@ -10,14 +10,14 @@ } ], "require": { - "illuminate/support": "^5.7", + "illuminate/support": "5.7.*||5.8.*", "webpatser/laravel-uuid": "^3.0" }, "require-dev": { - "orchestra/testbench": "~3.0", - "laravel/framework": "5.7.*", - "vlucas/phpdotenv": "^2.2", + "vlucas/phpdotenv": "^2.2||^3.3", "psy/psysh": "@stable", + "laravel/framework": "5.7.*||5.8.*", + "orchestra/testbench": "~3.7||~3.8", "league/flysystem-aws-s3-v3": "~1.0" }, "autoload": { @@ -42,5 +42,7 @@ "Tenancy": "Stancl\\Tenancy\\TenancyFacade" } } - } + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/tests/CacheManagerTest.php b/tests/CacheManagerTest.php index 12e34673..5d087ada 100644 --- a/tests/CacheManagerTest.php +++ b/tests/CacheManagerTest.php @@ -7,7 +7,7 @@ class CacheManagerTest extends TestCase /** @test */ public function default_tag_is_automatically_applied() { - $this->assertArraySubset([config('tenancy.cache.tag_base') . tenant('uuid')], cache()->tags('foo')->getTags()->getNames()); + $this->assertArrayIsSubset([config('tenancy.cache.tag_base') . tenant('uuid')], cache()->tags('foo')->getTags()->getNames()); } /** @test */ diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index bd059996..fcdac6ad 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -9,7 +9,7 @@ class CommandsTest extends TestCase { public $autoInitTenancy = false; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -19,10 +19,13 @@ class CommandsTest extends TestCase /** @test */ public function migrate_command_doesnt_change_the_db_connection() { + $this->assertFalse(Schema::hasTable('users')); + $old_connection_name = app(\Illuminate\Database\DatabaseManager::class)->connection()->getName(); Artisan::call('tenants:migrate'); $new_connection_name = app(\Illuminate\Database\DatabaseManager::class)->connection()->getName(); + $this->assertFalse(Schema::hasTable('users')); $this->assertEquals($old_connection_name, $new_connection_name); $this->assertNotEquals('tenant', $new_connection_name); } @@ -30,9 +33,10 @@ class CommandsTest extends TestCase /** @test */ public function migrate_command_works_without_options() { + $this->assertFalse(Schema::hasTable('users')); Artisan::call('tenants:migrate'); $this->assertFalse(Schema::hasTable('users')); - tenancy()->init(); + tenancy()->init('localhost'); $this->assertTrue(Schema::hasTable('users')); } @@ -45,7 +49,7 @@ class CommandsTest extends TestCase ]); $this->assertFalse(Schema::hasTable('users')); - tenancy()->init(); + tenancy()->init('localhost'); $this->assertFalse(Schema::hasTable('users')); tenancy()->init('test.localhost'); @@ -57,7 +61,7 @@ class CommandsTest extends TestCase { Artisan::call('tenants:migrate'); $this->assertFalse(Schema::hasTable('users')); - tenancy()->init(); + tenancy()->init('localhost'); $this->assertTrue(Schema::hasTable('users')); Artisan::call('tenants:rollback'); $this->assertFalse(Schema::hasTable('users')); diff --git a/tests/TestCase.php b/tests/TestCase.php index 84e8f93f..bf7afc45 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -14,7 +14,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -48,7 +48,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase protected function getEnvironmentSetUp($app) { if (file_exists(__DIR__ . '/../.env')) { - (new \Dotenv\Dotenv(__DIR__ . '/..'))->load(); + $this->loadDotEnv(); } $app['config']->set([ @@ -75,6 +75,15 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase ]); } + protected function loadDotEnv() + { + if (app()::VERSION > '5.8.0') { + \Dotenv\Dotenv::create(__DIR__ . '/..')->load(); + } else { + (new \Dotenv\Dotenv(__DIR__ . '/..'))->load(); + } + } + protected function getPackageProviders($app) { return [\Stancl\Tenancy\TenancyServiceProvider::class]; @@ -102,4 +111,9 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase // set one of these environment vars on their computer. return env('CI') && env('TRAVIS') && env('CONTINUOUS_INTEGRATION'); } + + public function assertArrayIsSubset($subset, $array, string $message = ''): void + { + parent::assertTrue(array_intersect($subset, $array) == $subset, $message); + } }