Skip to content

Commit 1501b31

Browse files
committed
update phpunit workflow
1 parent 8cd75d1 commit 1501b31

File tree

4 files changed

+95
-6
lines changed

4 files changed

+95
-6
lines changed

.github/workflows/phpcpd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ jobs:
3333
coverage: none
3434

3535
- name: Detect duplicate code
36-
run: phpcpd app/ tests/
36+
run: phpcpd src/

.github/workflows/phpunit.yml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,44 @@ on:
2020

2121
jobs:
2222
main:
23-
name: PHP ${{ matrix.php-versions }} Unit Tests
23+
name: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}
2424
runs-on: ubuntu-latest
2525
if: "!contains(github.event.head_commit.message, '[ci skip]')"
2626
strategy:
2727
matrix:
2828
php-versions: ['8.2', '8.3']
29+
db-platforms: ['MySQLi']
30+
31+
mysql:
32+
image: mysql:8.0
33+
env:
34+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
35+
MYSQL_DATABASE: test
36+
ports:
37+
- 3306:3306
38+
options: >-
39+
--health-cmd="mysqladmin ping"
40+
--health-interval=10s
41+
--health-timeout=5s
42+
--health-retries=3
2943
3044
steps:
45+
- name: Free Disk Space (Ubuntu)
46+
uses: jlumbroso/free-disk-space@main
47+
with:
48+
# this might remove tools that are actually needed,
49+
# if set to "true" but frees about 6 GB
50+
tool-cache: false
51+
52+
# all of these default to true, but feel free to set to
53+
# "false" if necessary for your workflow
54+
android: true
55+
dotnet: true
56+
haskell: true
57+
large-packages: false
58+
docker-images: true
59+
swap-storage: true
60+
3161
- name: Checkout
3262
uses: actions/checkout@v4
3363

@@ -62,10 +92,11 @@ jobs:
6292
- name: Test with PHPUnit
6393
run: vendor/bin/phpunit --coverage-text
6494
env:
95+
DB: ${{ matrix.db-platforms }}
6596
TERM: xterm-256color
6697
TACHYCARDIA_MONITOR_GA: enabled
6798

68-
- if: matrix.php-versions == '8.1'
99+
- if: matrix.php-versions == '8.2'
69100
name: Run Coveralls
70101
continue-on-error: true
71102
run: |
@@ -74,7 +105,7 @@ jobs:
74105
env:
75106
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76107
COVERALLS_PARALLEL: true
77-
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }}
108+
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}
78109

79110
coveralls:
80111
needs: [main]

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@
5353
<env name="COMPOSER_DISABLE_XDEBUG_WARN" value="1"/>
5454
<!-- Database configuration -->
5555
<env name="database.tests.strictOn" value="true"/>
56-
<!-- Uncomment to use alternate testing database configuration -->
56+
<!-- Uncomment to use alternate testing database configuration
5757
<env name="database.tests.hostname" value="127.0.0.1"/>
5858
<env name="database.tests.database" value="tests"/>
5959
<env name="database.tests.username" value="root"/>
6060
<env name="database.tests.password" value=""/>
6161
<env name="database.tests.DBDriver" value="MySQLi"/>
6262
<env name="database.tests.DBPrefix" value=""/>
63-
<!---->
63+
-->
6464
</php>
6565
<source>
6666
<include>

tests/_support/Config/Registrar.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Support\Config;
6+
7+
/**
8+
* Class Registrar
9+
*
10+
* Provides a basic registrar class for testing BaseConfig registration functions.
11+
*/
12+
class Registrar
13+
{
14+
/**
15+
* DB config array for testing purposes.
16+
*
17+
* @var array<string, array<string, array<string, bool|int|string>|bool|int|string>>
18+
*/
19+
protected static array $dbConfig = [
20+
'MySQLi' => [
21+
'DSN' => '',
22+
'hostname' => '127.0.0.1',
23+
'username' => 'root',
24+
'password' => '',
25+
'database' => 'test',
26+
'DBDriver' => 'MySQLi',
27+
'DBPrefix' => 'db_',
28+
'pConnect' => false,
29+
'DBDebug' => true,
30+
'charset' => 'utf8mb4',
31+
'DBCollat' => 'utf8mb4_general_ci',
32+
'swapPre' => '',
33+
'encrypt' => false,
34+
'compress' => false,
35+
'strictOn' => false,
36+
'failover' => [],
37+
'port' => 3306,
38+
],
39+
];
40+
41+
/**
42+
* Override database config
43+
*
44+
* @return array<string, array<string, bool|int|string>|bool|int|string>
45+
*/
46+
public static function Database(): array
47+
{
48+
$config = [];
49+
50+
// Under GitHub Actions, we can set an ENV var named 'DB'
51+
// so that we can test against multiple databases.
52+
if (($group = getenv('DB')) && isset(self::$dbConfig[$group])) {
53+
$config['tests'] = self::$dbConfig[$group];
54+
}
55+
56+
return $config;
57+
}
58+
}

0 commit comments

Comments
 (0)