Skip to content

Commit 0be1712

Browse files
committed
Simplify test config
1 parent 1614e43 commit 0be1712

9 files changed

Lines changed: 32 additions & 57 deletions

File tree

.github/workflows/php.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,18 @@ jobs:
3838
uses: shivammathur/setup-php@v2
3939
with:
4040
php-version: ${{ matrix.php }}
41-
tools: psalm
42-
extensions: sqlsrv-5.10.1
4341

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

45+
- name: Validate composer.json and composer.lock
46+
run: composer validate --strict
47+
4748
- name: Install Composer dependencies
4849
run: composer install --no-progress
4950

5051
- name: Run Psalm
51-
run: psalm --output-format=github
52+
run: composer analyze -- --output-format=github
5253
if: ${{ matrix.php == '8.3' }}
5354

5455
- name: Run PHPUnit

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
/vendor/
66
/composer.lock
7-
/test/src/LocalConfig.php
7+
/test/config.php

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ From a console in the working directory, execute `composer test` to run all unit
1111

1212
> [!NOTE]
1313
> By default, database tests will attempt to run on a database named `PeachySQL`.
14-
> To override connection settings, create a `LocalConfig.php` class in the `test/src`
15-
> directory which extends `Config` and overrides the desired methods.
14+
> To override connection settings, create a `test/config.php` file which returns
15+
> an instance of `Config` with the desired property values.
1616
1717
## Formatting and static analysis
1818

psalm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
resolveFromConfigFile="true"
55
findUnusedBaselineEntry="true"
66
findUnusedCode="true"
7-
findUnusedPsalmSuppress="false"
7+
findUnusedPsalmSuppress="true"
88
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xmlns="https://getpsalm.org/schema/config"
1010
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"

test/MssqlDbTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public static function dbProvider(): PeachySql
2727
{
2828
if (!self::$db) {
2929
$c = App::$config;
30-
$server = $c->getMssqlServer();
30+
$server = $c->mssqlServer;
3131
$connStr = getenv('MSSQL_CONNECTION_STRING');
32-
$username = $c->getMssqlUsername();
33-
$password = $c->getMssqlPassword();
32+
$username = $c->mssqlUsername;
33+
$password = $c->mssqlPassword;
3434

3535
if ($connStr !== false) {
3636
// running tests with GitHub Actions

test/MysqlDbTest.php

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

31-
$pdo = new PDO($c->getMysqlDsn(), $c->getMysqlUser(), $c->getMysqlPassword(), [
31+
$pdo = new PDO($c->mysqlDsn, $c->mysqlUser, $c->mysqlPassword, [
3232
PDO::ATTR_EMULATE_PREPARES => false,
3333
]);
3434

test/PgsqlDbTest.php

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

37-
$pdo = new PDO($c->getPgsqlDsn($dbName), $c->getPgsqlUser(), $c->getPgsqlPassword(), [
37+
$pdo = new PDO($c->getPgsqlDsn($dbName), $c->pgsqlUser, $c->pgsqlPassword, [
3838
PDO::ATTR_EMULATE_PREPARES => false,
3939
]);
4040

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\PeachySQL\Test\src\{App, Config, LocalConfig};
3+
use DevTheorem\PeachySQL\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\PeachySQL\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=PeachySQL";
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=PeachySQL';
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)