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

Fix tests

This commit is contained in:
Samuel Štancl 2019-09-21 12:04:25 +02:00
parent 3cd97bdcab
commit cd53ff120d
4 changed files with 6 additions and 6 deletions

View file

@ -25,7 +25,7 @@ return [
// 'localhost', // 'localhost',
], ],
'database' => [ 'database' => [
'based_on' => 'mysql', // The connection that will be used as a base for the dynamically created tenant connection. 'based_on' => null, // The connection that will be used as a base for the dynamically created tenant connection. // todo2 test this
'prefix' => 'tenant', 'prefix' => 'tenant',
'suffix' => '', 'suffix' => '',
], ],

View file

@ -56,7 +56,7 @@ class Migrate extends MigrateCommand
// See Illuminate\Database\Migrations\DatabaseMigrationRepository::getConnection. // See Illuminate\Database\Migrations\DatabaseMigrationRepository::getConnection.
// Database connections are cached by Illuminate\Database\ConnectionResolver. // Database connections are cached by Illuminate\Database\ConnectionResolver.
$this->input->setOption('database', 'tenant'); $this->input->setOption('database', 'tenant');
tenancy()->initialize($tenant); // todo2 test that this works with multiple tenants with MySQL tenancy()->initialize($tenant); // todo3 test that this works with multiple tenants with MySQL
// Migrate // Migrate
parent::handle(); parent::handle();

View file

@ -78,7 +78,7 @@ class DatabaseManager
*/ */
public function getBaseConnection(string $connectionName): string public function getBaseConnection(string $connectionName): string
{ {
return $connectionName return ($connectionName !== 'tenant' ? $connectionName : null) // 'tenant' is not a specific connection, it's the default
?? $this->app['config']['tenancy.database.based_on'] ?? $this->app['config']['tenancy.database.based_on']
?? $this->originalDefaultConnectionName; // tenancy.database.based_on === null => use the default connection ?? $this->originalDefaultConnectionName; // tenancy.database.based_on === null => use the default connection
} }
@ -87,9 +87,9 @@ class DatabaseManager
* Get the driver of a database connection. * Get the driver of a database connection.
* *
* @param string $connectionName * @param string $connectionName
* @return string * @return string|null
*/ */
public function getDriver(string $connectionName): string public function getDriver(string $connectionName): ?string
{ {
return $this->app['config']["database.connections.$connectionName.driver"]; return $this->app['config']["database.connections.$connectionName.driver"];
} }

View file

@ -16,7 +16,7 @@ use Stancl\Tenancy\Tenant;
class DatabaseStorageDriver implements StorageDriver class DatabaseStorageDriver implements StorageDriver
{ {
// todo2 write tests verifying that data is decoded and added to the array // todo4 write tests verifying that data is decoded and added to the array
/** @var Application */ /** @var Application */
protected $app; protected $app;