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

[4.x] Finish incomplete and missing tests (#947)

* complete test sqlite manager customize path

* complete test seed command works

* complete uniqe exists test

* Update SingleDatabaseTenancyTest.php

* refactor the ternary into if condition

* custom path

* simplify if condition

* random dir name

* Update SingleDatabaseTenancyTest.php

* Update CommandsTest.php

* prefix random DB name with custom_

Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
Abrar Ahmad 2022-09-24 07:08:44 +05:00 committed by GitHub
parent ab5fa7a247
commit 8e3b74f9d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 12 deletions

View file

@ -10,10 +10,15 @@ use Throwable;
class SQLiteDatabaseManager implements TenantDatabaseManager
{
/**
* SQLite Database path without ending slash.
*/
public static string|null $path = null;
public function createDatabase(TenantWithDatabase $tenant): bool
{
try {
return file_put_contents(database_path($tenant->database()->getName()), '');
return (bool) file_put_contents($this->getPath($tenant->database()->getName()), '');
} catch (Throwable) {
return false;
}
@ -22,7 +27,7 @@ class SQLiteDatabaseManager implements TenantDatabaseManager
public function deleteDatabase(TenantWithDatabase $tenant): bool
{
try {
return unlink(database_path($tenant->database()->getName()));
return unlink($this->getPath($tenant->database()->getName()));
} catch (Throwable) {
return false;
}
@ -30,7 +35,7 @@ class SQLiteDatabaseManager implements TenantDatabaseManager
public function databaseExists(string $name): bool
{
return file_exists(database_path($name));
return file_exists($this->getPath($name));
}
public function makeConnectionConfig(array $baseConfig, string $databaseName): array
@ -44,4 +49,13 @@ class SQLiteDatabaseManager implements TenantDatabaseManager
{
//
}
public function getPath(string $name): string
{
if (static::$path) {
return static::$path . DIRECTORY_SEPARATOR . $name;
}
return database_path($name);
}
}