From 921d59560ee267766a3995c56ae0e4459d197ff8 Mon Sep 17 00:00:00 2001 From: myrmidex Date: Sun, 27 Sep 2026 00:59:12 +0200 Subject: [PATCH] 169 - Run the test suite against MariaDB instead of SQLite --- .env.testing | 9 +++++++-- .forgejo/workflows/ci.yml | 15 ++++++++++++++- docker/dev/docker-compose.yml | 1 + docker/dev/initdb/01-create-test-database.sql | 7 +++++++ phpunit.xml | 4 ++-- .../KeyPlatformChannelPostsMigrationTest.php | 8 +++----- tests/Feature/MirrorDuplicateDetectionTest.php | 2 -- tests/Feature/ValidateArticleListenerTest.php | 5 +++-- 8 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 docker/dev/initdb/01-create-test-database.sql diff --git a/.env.testing b/.env.testing index 6b2cbec9..21577466 100644 --- a/.env.testing +++ b/.env.testing @@ -11,8 +11,13 @@ BCRYPT_ROUNDS=4 LOG_CHANNEL=stack LOG_STACK=single -DB_CONNECTION=sqlite -DB_DATABASE=:memory: +# Host and credentials must match docker/dev/docker-compose.yml; nothing enforces it. +DB_CONNECTION=mysql +DB_HOST=db +DB_PORT=3306 +DB_DATABASE=ffr_testing +DB_USERNAME=ffr +DB_PASSWORD=ffr SESSION_DRIVER=array diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index 80a1b1fd..82c494cd 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -10,7 +10,20 @@ jobs: ci: runs-on: docker container: - image: forge.lvl0.xyz/lvl0/fedi-feed-router-ci:php8.3-3 + image: forge.lvl0.xyz/lvl0/fedi-feed-router-ci:php8.3-4 + services: + db: + image: mariadb:11 + env: + MARIADB_DATABASE: ffr_testing + MARIADB_USER: ffr + MARIADB_PASSWORD: ffr + MARIADB_ROOT_PASSWORD: ffr_root_ci + options: >- + --health-cmd="healthcheck.sh --connect --innodb_initialized" + --health-interval=10s + --health-timeout=5s + --health-retries=10 steps: - uses: https://data.forgejo.org/actions/checkout@v4 diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml index fcb03bbf..fa03e12e 100644 --- a/docker/dev/docker-compose.yml +++ b/docker/dev/docker-compose.yml @@ -56,6 +56,7 @@ services: MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD:-ffr_root_dev}" volumes: - db_data:/var/lib/mysql + - ./initdb:/docker-entrypoint-initdb.d:ro healthcheck: test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"] interval: 10s diff --git a/docker/dev/initdb/01-create-test-database.sql b/docker/dev/initdb/01-create-test-database.sql new file mode 100644 index 00000000..e62b491f --- /dev/null +++ b/docker/dev/initdb/01-create-test-database.sql @@ -0,0 +1,7 @@ +-- Runs only on an empty data directory. Recreate the volume to apply changes. +CREATE DATABASE IF NOT EXISTS ffr_testing + CHARACTER SET utf8mb4 + COLLATE utf8mb4_unicode_ci; + +GRANT ALL PRIVILEGES ON ffr_testing.* TO 'ffr'@'%'; +FLUSH PRIVILEGES; diff --git a/phpunit.xml b/phpunit.xml index 17f11850..05ea7cc1 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -23,8 +23,8 @@ - - + + diff --git a/tests/Feature/KeyPlatformChannelPostsMigrationTest.php b/tests/Feature/KeyPlatformChannelPostsMigrationTest.php index 1febf897..3c306ca0 100644 --- a/tests/Feature/KeyPlatformChannelPostsMigrationTest.php +++ b/tests/Feature/KeyPlatformChannelPostsMigrationTest.php @@ -62,7 +62,7 @@ public function test_maps_rows_to_the_local_channel_by_name(): void { $this->restoreLegacyTable(); - $channel = PlatformChannel::factory()->create(['name' => 'newsbottest', 'channel_id' => 'newsbottest']); + $channel = PlatformChannel::factory()->create(['name' => 'newsbottest']); $this->seedLegacyRow('217', 'newsbottest', '1'); $this->seedLegacyRow('217', 'newsbottest', '2'); @@ -76,7 +76,7 @@ public function test_drops_rows_that_match_no_channel(): void { $this->restoreLegacyTable(); - PlatformChannel::factory()->create(['name' => 'newsbottest', 'channel_id' => 'newsbottest']); + PlatformChannel::factory()->create(['name' => 'newsbottest']); $this->seedLegacyRow('999', 'a-community-that-no-longer-exists', '1'); $this->runMigration(); @@ -94,12 +94,10 @@ public function test_drops_rows_whose_channel_name_is_ambiguous_across_instances PlatformChannel::factory()->create([ 'platform_instance_id' => $first->id, 'name' => 'news', - 'channel_id' => 'news', ]); PlatformChannel::factory()->create([ 'platform_instance_id' => $second->id, 'name' => 'news', - 'channel_id' => 'news-two', ]); $this->seedLegacyRow('8', 'news', '1'); @@ -113,7 +111,7 @@ public function test_leaves_a_schema_the_new_code_can_use(): void { $this->restoreLegacyTable(); - $channel = PlatformChannel::factory()->create(['name' => 'newsbottest', 'channel_id' => 'newsbottest']); + $channel = PlatformChannel::factory()->create(['name' => 'newsbottest']); $this->seedLegacyRow('217', 'newsbottest', '1'); $this->runMigration(); diff --git a/tests/Feature/MirrorDuplicateDetectionTest.php b/tests/Feature/MirrorDuplicateDetectionTest.php index 09bd6a5e..8243648c 100644 --- a/tests/Feature/MirrorDuplicateDetectionTest.php +++ b/tests/Feature/MirrorDuplicateDetectionTest.php @@ -41,7 +41,6 @@ protected function setUp(): void $instance = PlatformInstance::factory()->create(['url' => 'https://lemmy.test']); $channel = PlatformChannel::factory()->create([ 'platform_instance_id' => $instance->id, - 'channel_id' => 'news', 'name' => 'news', ]); $account = PlatformAccount::factory()->create(['instance_url' => 'https://lemmy.test']); @@ -180,7 +179,6 @@ public function test_a_second_instance_with_the_same_community_name_does_not_col $otherInstance = PlatformInstance::factory()->create(['url' => 'https://other.test']); $otherChannel = PlatformChannel::factory()->create([ 'platform_instance_id' => $otherInstance->id, - 'channel_id' => 'news', 'name' => 'news', ]); diff --git a/tests/Feature/ValidateArticleListenerTest.php b/tests/Feature/ValidateArticleListenerTest.php index dd491355..427ca903 100644 --- a/tests/Feature/ValidateArticleListenerTest.php +++ b/tests/Feature/ValidateArticleListenerTest.php @@ -89,7 +89,8 @@ public function test_listener_skips_already_validated_articles(): void public function test_listener_skips_articles_with_existing_publication(): void { $feed = Feed::factory()->create(); - Route::factory()->active()->create(['feed_id' => $feed->id]); + /** @var Route $route */ + $route = Route::factory()->active()->create(['feed_id' => $feed->id]); $article = Article::factory()->create([ 'feed_id' => $feed->id, @@ -98,7 +99,7 @@ public function test_listener_skips_articles_with_existing_publication(): void ArticlePublication::create([ 'article_id' => $article->id, 'post_id' => 'test-post-id', - 'platform_channel_id' => 1, + 'platform_channel_id' => $route->platform_channel_id, 'published_at' => now(), 'published_by' => 'test-user', ]);