Skip to content

Commit 0227664

Browse files
committed
Simplify test config
1 parent 66bde35 commit 0227664

7 files changed

Lines changed: 29 additions & 56 deletions

File tree

.github/workflows/php.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ jobs:
3939
uses: shivammathur/setup-php@v2
4040
with:
4141
php-version: ${{ matrix.php }}
42-
tools: psalm
43-
extensions: sqlsrv-5.10.1
4442

4543
- name: Setup problem matchers for PHPUnit
4644
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
/.idea/
2-
/vendor/
3-
/composer.lock
4-
/test/src/LocalConfig.php
1+
.idea/
52
.phpunit.result.cache
63
.php-cs-fixer.cache
4+
5+
/vendor/
6+
/composer.lock
7+
/test/config.php

test/MssqlDbTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public static function dbProvider(): PeachySql
1717
{
1818
if (!self::$db) {
1919
$c = App::$config;
20-
$server = $c->getMssqlServer();
21-
$username = $c->getMssqlUsername();
22-
$password = $c->getMssqlPassword();
20+
$server = $c->mssqlServer;
21+
$username = $c->mssqlUsername;
22+
$password = $c->mssqlPassword;
2323

2424
$pdo = new PDO("sqlsrv:Server=$server;Database=PeachySQL", $username, $password, [
2525
PDO::ATTR_EMULATE_PREPARES => false,

test/MysqlDbTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static function dbProvider(): PeachySql
1818
if (!self::$db) {
1919
$c = App::$config;
2020

21-
$pdo = new PDO($c->getMysqlDsn(), $c->getMysqlUser(), $c->getMysqlPassword(), [
21+
$pdo = new PDO($c->mysqlDsn, $c->mysqlUser, $c->mysqlPassword, [
2222
PDO::ATTR_EMULATE_PREPARES => false,
2323
]);
2424

test/PgsqlDbTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static function dbProvider(): PeachySql
1919
$c = App::$config;
2020
$dbName = getenv('POSTGRES_HOST') !== false ? 'postgres' : 'PeachySQL';
2121

22-
$pdo = new PDO($c->getPgsqlDsn($dbName), $c->getPgsqlUser(), $c->getPgsqlPassword(), [
22+
$pdo = new PDO($c->getPgsqlDsn($dbName), $c->pgsqlUser, $c->pgsqlPassword, [
2323
PDO::ATTR_EMULATE_PREPARES => false,
2424
]);
2525

test/bootstrap.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
<?php
22

3-
use DevTheorem\Phaster\Test\src\{App, Config, LocalConfig};
3+
use DevTheorem\Phaster\Test\src\{App, Config};
44

55
require 'vendor/autoload.php';
66

7-
if (class_exists(LocalConfig::class)) {
8-
// suppress error when LocalConfig doesn't exist
9-
/** @psalm-suppress MixedAssignment */
10-
App::$config = new LocalConfig();
7+
$configFile = __DIR__ . '/config.php';
8+
9+
if (file_exists($configFile)) {
10+
$config = require $configFile;
11+
12+
if (!$config instanceof Config) {
13+
throw new Exception('Expected config file to return Config instance');
14+
}
15+
16+
App::$config = $config;
1117
} else {
1218
App::$config = new Config();
1319
}

test/src/Config.php

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,21 @@
22

33
namespace DevTheorem\Phaster\Test\src;
44

5-
/**
6-
* Default test config. Values can be overridden with a LocalConfig child class.
7-
*/
85
class Config
96
{
10-
public function getMysqlDsn(): string
11-
{
12-
return "mysql:host=127.0.0.1;port=3306;dbname=Phaster";
13-
}
7+
public string $mssqlServer = '(local)\SQLEXPRESS';
8+
public string $mssqlUsername = '';
9+
public string $mssqlPassword = '';
1410

15-
public function getMysqlUser(): string
16-
{
17-
return 'root';
18-
}
11+
public string $mysqlDsn = 'mysql:host=127.0.0.1;port=3306;dbname=Phaster';
12+
public string $mysqlUser = 'root';
13+
public string $mysqlPassword = '';
1914

20-
public function getMysqlPassword(): string
21-
{
22-
return '';
23-
}
15+
public string $pgsqlUser = 'postgres';
16+
public string $pgsqlPassword = 'postgres';
2417

2518
public function getPgsqlDsn(string $database): string
2619
{
2720
return "pgsql:host=localhost;dbname=$database";
2821
}
29-
30-
public function getPgsqlUser(): string
31-
{
32-
return 'postgres';
33-
}
34-
35-
public function getPgsqlPassword(): string
36-
{
37-
return 'postgres';
38-
}
39-
40-
public function getMssqlServer(): string
41-
{
42-
return '(local)\SQLEXPRESS';
43-
}
44-
45-
public function getMssqlUsername(): string
46-
{
47-
return '';
48-
}
49-
50-
public function getMssqlPassword(): string
51-
{
52-
return '';
53-
}
5422
}

0 commit comments

Comments
 (0)