Skip to content

Commit 50c56b7

Browse files
authored
Databases: Make method databases() static (#98)
It is used as `DataProvider` in unit-tests and phpUnit10 requires it to be static. https://docs.phpunit.de/en/10.5/writing-tests-for-phpunit.html#data-providers
2 parents 5efc779 + d5f2d4b commit 50c56b7

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/Test/Databases.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ abstract protected function dropSchema(Connection $db, string $driver): void;
5656
*
5757
* @return array<string, Connection[]>
5858
*/
59-
public function databases(): array
59+
public static function databases(): array
6060
{
6161
$supportedAdapters = ['mssql', 'mysql', 'oracle', 'pgsql', 'sqlite'];
6262

6363
$connections = [];
6464
foreach ($supportedAdapters as $driver) {
6565
if (isset($_SERVER[strtoupper($driver) . '_TESTDB'])) {
66-
$connections[$driver] = [$this->createConnection($driver)];
66+
$connections[$driver] = [static::createConnection($driver)];
6767
}
6868
}
6969

@@ -79,7 +79,7 @@ public function databases(): array
7979
*
8080
* @throws RuntimeException if the environment variable is not set
8181
*/
82-
private function getEnvVariable(string $name): string
82+
private static function getEnvVariable(string $name): string
8383
{
8484
$value = getenv($name);
8585
if ($value === false) {
@@ -96,15 +96,15 @@ private function getEnvVariable(string $name): string
9696
*
9797
* @return Connection
9898
*/
99-
private function createConnection(string $driver): Connection
99+
private static function createConnection(string $driver): Connection
100100
{
101101
return new Connection([
102102
'db' => $driver,
103-
'host' => $this->getEnvVariable(strtoupper($driver) . '_TESTDB_HOST'),
104-
'port' => $this->getEnvVariable(strtoupper($driver) . '_TESTDB_PORT'),
105-
'username' => $this->getEnvVariable(strtoupper($driver) . '_TESTDB_USER'),
106-
'password' => $this->getEnvVariable(strtoupper($driver) . '_TESTDB_PASSWORD'),
107-
'dbname' => $this->getEnvVariable(strtoupper($driver) . '_TESTDB'),
103+
'host' => static::getEnvVariable(strtoupper($driver) . '_TESTDB_HOST'),
104+
'port' => static::getEnvVariable(strtoupper($driver) . '_TESTDB_PORT'),
105+
'username' => static::getEnvVariable(strtoupper($driver) . '_TESTDB_USER'),
106+
'password' => static::getEnvVariable(strtoupper($driver) . '_TESTDB_PASSWORD'),
107+
'dbname' => static::getEnvVariable(strtoupper($driver) . '_TESTDB'),
108108
]);
109109
}
110110

@@ -122,8 +122,8 @@ protected function setUpDatabases(): void
122122
$this->createSchema($providedData[0], $this->dataName());
123123
}
124124
} else {
125-
$this->createSchema($this->createConnection('mysql'), 'mysql');
126-
$this->createSchema($this->createConnection('pgsql'), 'pgsql');
125+
$this->createSchema(static::createConnection('mysql'), 'mysql');
126+
$this->createSchema(static::createConnection('pgsql'), 'pgsql');
127127
}
128128
}
129129

@@ -141,8 +141,8 @@ protected function tearDownDatabases(): void
141141
$this->dropSchema($providedData[0], $this->dataName());
142142
}
143143
} else {
144-
$this->dropSchema($this->createConnection('mysql'), 'mysql');
145-
$this->dropSchema($this->createConnection('pgsql'), 'pgsql');
144+
$this->dropSchema(static::createConnection('mysql'), 'mysql');
145+
$this->dropSchema(static::createConnection('pgsql'), 'pgsql');
146146
}
147147
}
148148
}

0 commit comments

Comments
 (0)