Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,37 @@ jobs:
matrix:
php: ['8.1', '8.2', '8.3', '8.4']
dependencies: ['lowest', 'highest']
testsuite: ['unit', 'mysql', 'sqlite']

name: Tests

services:
mysql:
# only setup service in mysql testsuite
image: ${{ matrix.testsuite == 'mysql' && 'mysql:8.0.31' || '' }}
ports:
- '3306:3306'
env:
MYSQL_ROOT_PASSWORD: mysql
MYSQL_DATABASE: access_test_db
MYSQL_ROOT_HOST: '%'
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: Setup MySQL `sql_mode`
if: ${{ matrix.testsuite == 'mysql' }}
# default sql mode minus ONLY_FULL_GROUP_BY
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'"

- name: Setup MySQL credentials
if: ${{ matrix.testsuite == 'mysql' }}
run: |
echo "MYSQL_DATABASE_HOST=127.0.0.1" >> $GITHUB_ENV
echo "MYSQL_DATABASE_PORT=3306" >> $GITHUB_ENV
echo "MYSQL_DATABASE_USER=root" >> $GITHUB_ENV
echo "MYSQL_DATABASE_PASSWORD=mysql" >> $GITHUB_ENV
echo "MYSQL_DATABASE_NAME=access_test_db" >> $GITHUB_ENV

- uses: actions/checkout@v4

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

- name: Run test suite
run: composer run-script test -- --display-deprecations --display-notices --display-warnings
run: composer run-script test -- --display-deprecations --display-notices --display-warnings --testsuite ${{ matrix.testsuite }}

- name: Upload code coverage
env:
Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
"autoload-dev": {
"psr-4": {
"Benchmarks\\": "benchmarks",
"Tests\\": "tests"
"Tests\\Base\\": "tests/base",
"Tests\\Fixtures\\": "tests/fixtures",
"Tests\\Mysql\\": "tests/mysql",
"Tests\\Sqlite\\": "tests/sqlite",
"Tests\\Unit\\": "tests/unit"
}
},
"scripts": {
Expand Down
Empty file added data/.keep
Empty file.
11 changes: 11 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
db:
image: mysql:8.0.31
volumes:
- ./data/db:/var/lib/mysql:cached
ports:
- '3306:3306'
# default sql mode minus ONLY_FULL_GROUP_BY
command: --sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
environment:
MYSQL_ROOT_PASSWORD: mysql
21 changes: 19 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,28 @@
</coverage>

<testsuites>
<testsuite name="Access">
<directory>tests/</directory>
<testsuite name="mysql">
<directory>tests/mysql</directory>
</testsuite>

<testsuite name="sqlite">
<directory>tests/sqlite</directory>
</testsuite>

<testsuite name="unit">
<directory>tests/unit</directory>
</testsuite>
</testsuites>

<php>
<!-- database credentials for mysql test -->
<env name="MYSQL_DATABASE_HOST" value="127.0.0.1"/>
<env name="MYSQL_DATABASE_PORT" value="3306"/>
<env name="MYSQL_DATABASE_USER" value="root"/>
<env name="MYSQL_DATABASE_PASSWORD" value="mysql"/>
<env name="MYSQL_DATABASE_NAME" value="access_test_db"/>
</php>

<logging/>

<source
Expand Down
14 changes: 7 additions & 7 deletions tests/ClockTest.php → tests/base/BaseClockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@

declare(strict_types=1);

namespace Tests;
namespace Tests\Base;

use DateTimeImmutable;
use Tests\AbstractBaseTestCase;
use PHPUnit\Framework\TestCase;
use Tests\Fixtures\Entity\LogMessage;
use Tests\Fixtures\Entity\User;
use Tests\Fixtures\MockClock;

class ClockTest extends AbstractBaseTestCase
abstract class BaseClockTest extends TestCase implements DatabaseBuilderInterface
{
public function testCreatable(): void
{
$now = new DateTimeImmutable('2023-05-23 00:00:00');
$clock = new MockClock($now);
$db = self::createDatabaseWithMockClock($clock);
$db = static::createDatabaseWithMockClock($clock);

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

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

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

$user = new User();
$user->setName('Dave');
Expand Down
Loading
Loading