1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 22:54:03 +00:00

Add 5.8 support (#33)

This commit is contained in:
Samuel Štancl 2019-02-27 18:22:34 +01:00 committed by GitHub
parent 725b43ce8c
commit 78fd7d43f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 15 deletions

View file

@ -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 */

View file

@ -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'));

View file

@ -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);
}
}