Skip to content

Commit da1e67d

Browse files
committed
Split tests into multiple test suites
MySQL testing is here!
1 parent f5207b1 commit da1e67d

91 files changed

Lines changed: 1066 additions & 319 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/continuous-integration.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,37 @@ jobs:
4444
matrix:
4545
php: ['8.1', '8.2', '8.3', '8.4']
4646
dependencies: ['lowest', 'highest']
47+
testsuite: ['unit', 'mysql', 'sqlite']
4748

4849
name: Tests
4950

51+
services:
52+
mysql:
53+
# only setup service in mysql testsuite
54+
image: ${{ matrix.testsuite == 'mysql' && 'mysql:8.0.31' || '' }}
55+
ports:
56+
- '3306:3306'
57+
env:
58+
MYSQL_ROOT_PASSWORD: mysql
59+
MYSQL_DATABASE: access_test_db
60+
MYSQL_ROOT_HOST: '%'
61+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
62+
5063
steps:
64+
- name: Setup MySQL `sql_mode`
65+
if: ${{ matrix.testsuite == 'mysql' }}
66+
# default sql mode minus ONLY_FULL_GROUP_BY
67+
run: mysql -h 127.0.0.1 --port 3306 -u root -pmysql -e "SET GLOBAL sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'"
68+
69+
- name: Setup MySQL credentials
70+
if: ${{ matrix.testsuite == 'mysql' }}
71+
run: |
72+
echo "MYSQL_DATABASE_HOST=127.0.0.1" >> $GITHUB_ENV
73+
echo "MYSQL_DATABASE_PORT=3306" >> $GITHUB_ENV
74+
echo "MYSQL_DATABASE_USER=root" >> $GITHUB_ENV
75+
echo "MYSQL_DATABASE_PASSWORD=mysql" >> $GITHUB_ENV
76+
echo "MYSQL_DATABASE_NAME=access_test_db" >> $GITHUB_ENV
77+
5178
- uses: actions/checkout@v4
5279

5380
- name: Install PHP
@@ -64,7 +91,7 @@ jobs:
6491
dependency-versions: ${{ matrix.dependencies }}
6592

6693
- name: Run test suite
67-
run: composer run-script test -- --display-deprecations --display-notices --display-warnings
94+
run: composer run-script test -- --display-deprecations --display-notices --display-warnings --testsuite ${{ matrix.testsuite }}
6895

6996
- name: Upload code coverage
7097
env:

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
"autoload-dev": {
2626
"psr-4": {
2727
"Benchmarks\\": "benchmarks",
28-
"Tests\\": "tests"
28+
"Tests\\Base\\": "tests/base",
29+
"Tests\\Fixtures\\": "tests/fixtures",
30+
"Tests\\Mysql\\": "tests/mysql",
31+
"Tests\\Sqlite\\": "tests/sqlite",
32+
"Tests\\Unit\\": "tests/unit"
2933
}
3034
},
3135
"scripts": {

data/.keep

Whitespace-only changes.

docker-compose.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
services:
2+
db:
3+
image: mysql:8.0.31
4+
volumes:
5+
- ./data/db:/var/lib/mysql:cached
6+
ports:
7+
- '3306:3306'
8+
# default sql mode minus ONLY_FULL_GROUP_BY
9+
command: --sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
10+
environment:
11+
MYSQL_ROOT_PASSWORD: mysql

phpunit.xml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,28 @@
1313
</coverage>
1414

1515
<testsuites>
16-
<testsuite name="Access">
17-
<directory>tests/</directory>
16+
<testsuite name="mysql">
17+
<directory>tests/mysql</directory>
18+
</testsuite>
19+
20+
<testsuite name="sqlite">
21+
<directory>tests/sqlite</directory>
22+
</testsuite>
23+
24+
<testsuite name="unit">
25+
<directory>tests/unit</directory>
1826
</testsuite>
1927
</testsuites>
2028

29+
<php>
30+
<!-- database credentials for mysql test -->
31+
<env name="MYSQL_DATABASE_HOST" value="127.0.0.1"/>
32+
<env name="MYSQL_DATABASE_PORT" value="3306"/>
33+
<env name="MYSQL_DATABASE_USER" value="root"/>
34+
<env name="MYSQL_DATABASE_PASSWORD" value="mysql"/>
35+
<env name="MYSQL_DATABASE_NAME" value="access_test_db"/>
36+
</php>
37+
2138
<logging/>
2239

2340
<source
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111

1212
declare(strict_types=1);
1313

14-
namespace Tests;
14+
namespace Tests\Base;
1515

1616
use DateTimeImmutable;
17-
use Tests\AbstractBaseTestCase;
17+
use PHPUnit\Framework\TestCase;
1818
use Tests\Fixtures\Entity\LogMessage;
1919
use Tests\Fixtures\Entity\User;
2020
use Tests\Fixtures\MockClock;
2121

22-
class ClockTest extends AbstractBaseTestCase
22+
abstract class BaseClockTest extends TestCase implements DatabaseBuilderInterface
2323
{
2424
public function testCreatable(): void
2525
{
2626
$now = new DateTimeImmutable('2023-05-23 00:00:00');
2727
$clock = new MockClock($now);
28-
$db = self::createDatabaseWithMockClock($clock);
28+
$db = static::createDatabaseWithMockClock($clock);
2929

3030
$logMessage = new LogMessage();
3131
$logMessage->setMessage('Something happened!');
@@ -39,7 +39,7 @@ public function testClockRoundtrip(): void
3939
{
4040
$now = new DateTimeImmutable('2023-05-23 00:00:00');
4141
$clock = new MockClock($now);
42-
$db = self::createDatabaseWithMockClock($clock);
42+
$db = static::createDatabaseWithMockClock($clock);
4343

4444
$user = new User();
4545
$user->setName('Dave');
@@ -53,7 +53,7 @@ public function testClockUpdate(): void
5353
{
5454
$now = new DateTimeImmutable('2023-05-23 00:00:00');
5555
$clock = new MockClock($now);
56-
$db = self::createDatabaseWithMockClock($clock);
56+
$db = static::createDatabaseWithMockClock($clock);
5757

5858
$user = new User();
5959
$user->setName('Dave');
@@ -78,7 +78,7 @@ public function testClockSoftDelete(): void
7878
{
7979
$now = new DateTimeImmutable('2023-05-23 00:00:00');
8080
$clock = new MockClock($now);
81-
$db = self::createDatabaseWithMockClock($clock);
81+
$db = static::createDatabaseWithMockClock($clock);
8282

8383
$user = new User();
8484
$user->setName('Dave');

0 commit comments

Comments
 (0)