From f147c87c0f160dd18f3d3c2f66fc4d030300d6d8 Mon Sep 17 00:00:00 2001 From: Illia Vasylevskyi Date: Fri, 5 Jul 2024 11:01:12 -0600 Subject: [PATCH] Lint --- src/Database/LibSQLConnector.php | 4 +- src/Database/LibSQLDatabase.php | 10 ++--- tests/Feature/ConnectionsSetupTest.php | 56 +++++++++++++------------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/Database/LibSQLConnector.php b/src/Database/LibSQLConnector.php index 21342c4..cadcfde 100644 --- a/src/Database/LibSQLConnector.php +++ b/src/Database/LibSQLConnector.php @@ -21,10 +21,10 @@ public function connect(array $config): LibSQLDatabase protected function checkConfig(array $config): void { if (empty($config['driver']) || $config['driver'] !== 'libsql') { - throw new \InvalidArgumentException("Got driver - " . $config['driver'] . ", please check your URL and driver config"); + throw new \InvalidArgumentException('Got driver - '.$config['driver'].', please check your URL and driver config'); } if (empty($config['url']) && empty($config['database'])) { - throw new \InvalidArgumentException("URL and database not set, please check your configuration"); + throw new \InvalidArgumentException('URL and database not set, please check your configuration'); } } } diff --git a/src/Database/LibSQLDatabase.php b/src/Database/LibSQLDatabase.php index b9bcead..39e942b 100644 --- a/src/Database/LibSQLDatabase.php +++ b/src/Database/LibSQLDatabase.php @@ -15,9 +15,7 @@ class LibSQLDatabase protected bool $inTransaction = false; - public function __construct(protected array $config = []) - { - } + public function __construct(protected array $config = []) {} public function init(): void { @@ -28,8 +26,8 @@ public function init(): void 'memory' => $this->createLibSQL(':memory:'), 'remote' => $this->createLibSQL("libsql:$path;authToken={$this->config['authToken']}"), 'remote_replica' => $this->createLibSQL([ - "url" => $path, - "authToken" => $this->config['authToken'], + 'url' => $path, + 'authToken' => $this->config['authToken'], 'syncUrl' => $this->config['syncUrl'], 'syncInterval' => $this->config['syncInterval'], 'read_your_writes' => $this->config['readYourWrites'], @@ -143,7 +141,7 @@ private function setConnectionMode(string $path, string $url = '', string $token $this->connection_mode = 'remote_replica'; } elseif (str_starts_with($path, 'file:') !== false) { $this->connection_mode = 'local'; - } elseif (! empty($path) && ! empty($token) && $remoteOnly === true) { + } elseif (! empty($path) && ! empty($token) && $remoteOnly === true) { $this->connection_mode = 'remote'; } elseif ($path === 'memory') { $this->connection_mode = 'memory'; diff --git a/tests/Feature/ConnectionsSetupTest.php b/tests/Feature/ConnectionsSetupTest.php index 900e5fd..7d75189 100644 --- a/tests/Feature/ConnectionsSetupTest.php +++ b/tests/Feature/ConnectionsSetupTest.php @@ -5,11 +5,11 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\File; use LibSQL; +use Mockery; use PHPUnit\Framework\Attributes\DataProvider; use Turso\Driver\Laravel\Database\LibSQLConnection; use Turso\Driver\Laravel\Database\LibSQLConnector; use Turso\Driver\Laravel\Database\LibSQLDatabase; -use Mockery; use Turso\Driver\Laravel\Exceptions\ConfigurationIsNotFound; class ConnectionsSetupTest extends TestCase @@ -40,6 +40,7 @@ public function testInvalidConfig(?string $defaultConnection, array $config, str DB::connection('libsql'); } catch (\Exception $e) { $this->assertEquals($error, $e->getMessage()); + return; } } @@ -60,7 +61,7 @@ public static function invalidConfigsProvider(): \Generator 'prefix' => '', 'database' => null, ], - 'error' => 'URL and database not set, please check your configuration' + 'error' => 'URL and database not set, please check your configuration', ]; yield 'url should be correct for file' => [ 'defaultConnection' => 'libsql', @@ -76,7 +77,7 @@ public static function invalidConfigsProvider(): \Generator 'prefix' => '', 'database' => null, ], - 'error' => 'Got driver - file, please check your URL and driver config' + 'error' => 'Got driver - file, please check your URL and driver config', ]; } @@ -107,10 +108,10 @@ public function testConnectionInMemory(): void $this->assertInstanceOf(LibSQLDatabase::class, $pdo); $this->assertEquals('local', $pdo->getDb()->mode); $this->assertEquals('memory', $pdo->getConnectionMode()); - $result = $connection->select("PRAGMA database_list"); + $result = $connection->select('PRAGMA database_list'); $this->assertNotEmpty($result); - $result = $pdo->query("SELECT sqlite_version()"); - $this->assertNotEmpty($result, "Failed to query SQLite version"); + $result = $pdo->query('SELECT sqlite_version()'); + $this->assertNotEmpty($result, 'Failed to query SQLite version'); } public function testConnectionLocalFile(): void @@ -139,10 +140,10 @@ public function testConnectionLocalFile(): void $this->assertInstanceOf(LibSQLDatabase::class, $pdo); $this->assertEquals('local', $pdo->getDb()->mode); $this->assertEquals('local', $pdo->getConnectionMode()); - $result = $connection->select("PRAGMA database_list"); + $result = $connection->select('PRAGMA database_list'); $this->assertNotEmpty($result); - $result = $pdo->query("SELECT sqlite_version()"); - $this->assertNotEmpty($result, "Failed to query SQLite version"); + $result = $pdo->query('SELECT sqlite_version()'); + $this->assertNotEmpty($result, 'Failed to query SQLite version'); $this->assertTrue(File::exists('tests/_files/test.db'), 'No file created or wrong path'); } @@ -159,26 +160,26 @@ public function testConnectionRemoteReplica(): void 'encryptionKey' => '', 'remoteOnly' => false, 'prefix' => '', - 'database' => 'database.sqlite' + 'database' => 'database.sqlite', ]; $expectedLibSQLParams = [ - "url" => 'file:tests/_files/database.sqlite', - "authToken" => $config['authToken'], + 'url' => 'file:tests/_files/database.sqlite', + 'authToken' => $config['authToken'], 'syncUrl' => $config['syncUrl'], 'syncInterval' => $config['syncInterval'], 'read_your_writes' => $config['readYourWrites'], 'encryptionKey' => $config['encryptionKey'], ]; $constructorConfig = [ - "driver" => "libsql", - "authToken" => "your-database-auth-token-from-turso", - "syncUrl" => "your-database-url-from-turso", - "syncInterval" => 5, - "readYourWrites" => true, - "encryptionKey" => "", - "remoteOnly" => false, - "prefix" => "", - "database" => "file:tests/_files/database.sqlite", + 'driver' => 'libsql', + 'authToken' => 'your-database-auth-token-from-turso', + 'syncUrl' => 'your-database-url-from-turso', + 'syncInterval' => 5, + 'readYourWrites' => true, + 'encryptionKey' => '', + 'remoteOnly' => false, + 'prefix' => '', + 'database' => 'file:tests/_files/database.sqlite', ]; $mockLibSQLDatabase = $this->getMockBuilder(LibSQLDatabase::class) @@ -225,13 +226,13 @@ public function testConnectionRemote(): void 'remoteOnly' => true, 'prefix' => '', ]; - $expectedLibSQLParams = "libsql:dbname=libsql://database-org.turso.io;authToken=your-database-auth-token-from-turso"; + $expectedLibSQLParams = 'libsql:dbname=libsql://database-org.turso.io;authToken=your-database-auth-token-from-turso'; $constructorConfig = [ - "driver" => "libsql", - "authToken" => "your-database-auth-token-from-turso", - "remoteOnly" => true, - "prefix" => "", - "database" => "dbname=libsql://database-org.turso.io", + 'driver' => 'libsql', + 'authToken' => 'your-database-auth-token-from-turso', + 'remoteOnly' => true, + 'prefix' => '', + 'database' => 'dbname=libsql://database-org.turso.io', ]; $mockLibSQLDatabase = $this->getMockBuilder(LibSQLDatabase::class) @@ -279,6 +280,7 @@ public function testNotFoundConfiguration() DB::connection('libsql'); } catch (ConfigurationIsNotFound $e) { $this->assertEquals('Connection not found!', $e->getMessage()); + return; } }