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

Add command tests

This commit is contained in:
Samuel Štancl 2019-02-09 11:53:48 +01:00
parent 33fcb8a936
commit e1def355f9
13 changed files with 98 additions and 15 deletions

View file

@ -2,18 +2,65 @@
namespace Stancl\Tenancy\Tests;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schema;
class CommandsTest extends TestCase
{
/** @test */
public function migrate_command_works()
public $autoInitTenancy = false;
public function setUp()
{
$this->markTestIncomplete();
parent::setUp();
config(['tenancy.migrations_directory' => database_path('../migrations')]);
}
/** @test */
public function migrate_command_doesnt_change_the_db_connection()
{
$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->assertEquals($old_connection_name, $new_connection_name);
$this->assertNotEquals('tenant', $new_connection_name);
}
/** @test */
public function migrate_command_works_without_options()
{
Artisan::call('tenants:migrate');
$this->assertFalse(Schema::hasTable('users'));
tenancy()->init();
$this->assertTrue(Schema::hasTable('users'));
}
/** @test */
public function migrate_command_works_with_tenants_option()
{
$tenant = tenant()->create('test.localhost');
Artisan::call('tenants:migrate', [
'--tenants' => [$tenant['uuid']]
]);
$this->assertFalse(Schema::hasTable('users'));
tenancy()->init();
$this->assertFalse(Schema::hasTable('users'));
tenancy()->init('test.localhost');
$this->assertTrue(Schema::hasTable('users'));
}
/** @test */
public function rollback_command_works()
{
$this->markTestIncomplete();
Artisan::call('tenants:migrate');
$this->assertFalse(Schema::hasTable('users'));
tenancy()->init();
$this->assertTrue(Schema::hasTable('users'));
Artisan::call('tenants:rollback');
$this->assertFalse(Schema::hasTable('users'));
}
/** @test */

View file

@ -0,0 +1,20 @@
<?php
namespace Stancl\Tenancy\Tests;
class DatabaseManagerTest extends TestCase
{
public $autoInitTenancy = false;
/** @test */
public function disconnect_method_works()
{
$old_connection_name = app(\Illuminate\Database\DatabaseManager::class)->connection()->getName();
tenancy()->init();
tenancy()->disconnectDatabase();
$new_connection_name = app(\Illuminate\Database\DatabaseManager::class)->connection()->getName();
$this->assertSame($old_connection_name, $new_connection_name);
$this->assertNotEquals('tenant', $new_connection_name);
}
}

View file

@ -1,6 +1,6 @@
<?php
namespace Stancl\Tenancy\Tests;
namespace Stancl\Tenancy\Tests\Etc;
use Illuminate\Foundation\Http\Kernel;

View file

@ -88,7 +88,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
*/
protected function resolveApplicationHttpKernel($app)
{
$app->singleton('Illuminate\Contracts\Http\Kernel', HttpKernel::class);
$app->singleton('Illuminate\Contracts\Http\Kernel', Etc\HttpKernel::class);
}
public function randomString(int $length = 10)