Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/Test/Databases.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ abstract protected function dropSchema(Connection $db, string $driver): void;
*
* @return array<string, Connection[]>
*/
public function databases(): array
public static function databases(): array
{
$supportedAdapters = ['mssql', 'mysql', 'oracle', 'pgsql', 'sqlite'];

$connections = [];
foreach ($supportedAdapters as $driver) {
if (isset($_SERVER[strtoupper($driver) . '_TESTDB'])) {
$connections[$driver] = [$this->createConnection($driver)];
$connections[$driver] = [static::createConnection($driver)];
}
}

Expand All @@ -79,7 +79,7 @@ public function databases(): array
*
* @throws RuntimeException if the environment variable is not set
*/
private function getEnvVariable(string $name): string
private static function getEnvVariable(string $name): string
{
$value = getenv($name);
if ($value === false) {
Expand All @@ -96,15 +96,15 @@ private function getEnvVariable(string $name): string
*
* @return Connection
*/
private function createConnection(string $driver): Connection
private static function createConnection(string $driver): Connection
{
return new Connection([
'db' => $driver,
'host' => $this->getEnvVariable(strtoupper($driver) . '_TESTDB_HOST'),
'port' => $this->getEnvVariable(strtoupper($driver) . '_TESTDB_PORT'),
'username' => $this->getEnvVariable(strtoupper($driver) . '_TESTDB_USER'),
'password' => $this->getEnvVariable(strtoupper($driver) . '_TESTDB_PASSWORD'),
'dbname' => $this->getEnvVariable(strtoupper($driver) . '_TESTDB'),
'host' => static::getEnvVariable(strtoupper($driver) . '_TESTDB_HOST'),
'port' => static::getEnvVariable(strtoupper($driver) . '_TESTDB_PORT'),
'username' => static::getEnvVariable(strtoupper($driver) . '_TESTDB_USER'),
'password' => static::getEnvVariable(strtoupper($driver) . '_TESTDB_PASSWORD'),
'dbname' => static::getEnvVariable(strtoupper($driver) . '_TESTDB'),
]);
}

Expand All @@ -122,8 +122,8 @@ protected function setUpDatabases(): void
$this->createSchema($providedData[0], $this->dataName());
}
} else {
$this->createSchema($this->createConnection('mysql'), 'mysql');
$this->createSchema($this->createConnection('pgsql'), 'pgsql');
$this->createSchema(static::createConnection('mysql'), 'mysql');
$this->createSchema(static::createConnection('pgsql'), 'pgsql');
}
}

Expand All @@ -141,8 +141,8 @@ protected function tearDownDatabases(): void
$this->dropSchema($providedData[0], $this->dataName());
}
} else {
$this->dropSchema($this->createConnection('mysql'), 'mysql');
$this->dropSchema($this->createConnection('pgsql'), 'pgsql');
$this->dropSchema(static::createConnection('mysql'), 'mysql');
$this->dropSchema(static::createConnection('pgsql'), 'pgsql');
}
}
}
Loading