1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 12:54:05 +00:00

Get old tests to pass

This commit is contained in:
Samuel Štancl 2020-05-03 04:00:34 +02:00
parent 65ebc043dc
commit 439b5b1dc1
28 changed files with 154 additions and 100 deletions

View file

@ -5,16 +5,16 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Tests;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Tenant;
class DatabaseManagerTest extends TestCase
{
public $autoInitTenancy = false;
/** @test */
public function reconnect_method_works()
{
$old_connection_name = app(\Illuminate\Database\DatabaseManager::class)->connection()->getName();
tenancy()->init('test.localhost');
$this->createTenant();
$this->initTenancy();
app(\Stancl\Tenancy\DatabaseManager::class)->reconnect();
$new_connection_name = app(\Illuminate\Database\DatabaseManager::class)->connection()->getName();
@ -25,22 +25,30 @@ class DatabaseManagerTest extends TestCase
/** @test */
public function db_name_is_prefixed_with_db_path_when_sqlite_is_used()
{
if (file_exists(database_path('foodb'))) {
unlink(database_path('foodb')); // cleanup
}
config(['database.connections.fooconn.driver' => 'sqlite']);
app(DatabaseManager::class)->createTenantConnection('foodb', 'fooconn');
$tenant = Tenant::new()->withData([
'_tenancy_db_name' => 'foodb',
'_tenancy_db_connection' => 'fooconn',
])->save();
app(DatabaseManager::class)->createTenantConnection($tenant);
$this->assertSame(config('database.connections.fooconn.database'), database_path('foodb'));
$this->assertSame(config('database.connections.tenant.database'), database_path('foodb'));
}
/** @test */
public function the_default_db_is_used_when_template_connection_is_null()
{
$this->assertSame('sqlite', config('database.default'));
$this->assertSame('central', config('database.default'));
config([
'database.connections.sqlite.foo' => 'bar',
'database.connections.central.foo' => 'bar',
'tenancy.database.template_connection' => null,
]);
tenancy()->init('test.localhost');
$this->createTenant();
$this->initTenancy();
$this->assertSame('tenant', config('database.default'));
$this->assertSame('bar', config('database.connections.' . config('database.default') . '.foo'));