From 0123e20b1d93658a53e6d417afb5c436715dc32c Mon Sep 17 00:00:00 2001 From: myrmidex Date: Sun, 8 Mar 2026 02:54:10 +0100 Subject: [PATCH] Fix 28 pre-existing test failures across test suite --- .env.testing | 28 +++++++++++++++++++ app/Models/Article.php | 1 - phpunit.xml | 24 ++++++++-------- tests/Feature/JobsAndEventsTest.php | 10 +++++-- tests/Unit/Models/ArticleTest.php | 18 ++++++++++-- .../ArticlePublishingServiceTest.php | 19 +++++++++---- 6 files changed, 77 insertions(+), 23 deletions(-) create mode 100644 .env.testing diff --git a/.env.testing b/.env.testing new file mode 100644 index 0000000..6b2cbec --- /dev/null +++ b/.env.testing @@ -0,0 +1,28 @@ +APP_NAME=Laravel +APP_ENV=testing +APP_KEY=base64:5VABFQKtzx6flRFn7rQUQYI/G8xLnkUSYPVaYz2s/4M= +APP_DEBUG=true +APP_URL=http://localhost + +APP_MAINTENANCE_DRIVER=file + +BCRYPT_ROUNDS=4 + +LOG_CHANNEL=stack +LOG_STACK=single + +DB_CONNECTION=sqlite +DB_DATABASE=:memory: + +SESSION_DRIVER=array + +BROADCAST_CONNECTION=log +FILESYSTEM_DISK=local +QUEUE_CONNECTION=sync + +CACHE_STORE=array + +MAIL_MAILER=array + +PULSE_ENABLED=false +TELESCOPE_ENABLED=false diff --git a/app/Models/Article.php b/app/Models/Article.php index f5cd55b..d508e79 100644 --- a/app/Models/Article.php +++ b/app/Models/Article.php @@ -61,7 +61,6 @@ public function casts(): array public function isValid(): bool { - // Article is valid if it passed validation and wasn't rejected return $this->validated_at !== null && ! $this->isRejected(); } diff --git a/phpunit.xml b/phpunit.xml index dda51b4..17f1185 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -18,17 +18,17 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/tests/Feature/JobsAndEventsTest.php b/tests/Feature/JobsAndEventsTest.php index 58a732c..c73ce60 100644 --- a/tests/Feature/JobsAndEventsTest.php +++ b/tests/Feature/JobsAndEventsTest.php @@ -18,6 +18,7 @@ use App\Models\Article; use App\Models\Feed; use App\Models\Log; +use App\Models\Setting; use App\Models\PlatformChannel; use App\Services\Log\LogSaver; use App\Services\Article\ArticleFetcher; @@ -175,7 +176,10 @@ public function test_exception_logged_event_is_dispatched(): void public function test_validate_article_listener_processes_new_article(): void { - Event::fake([ArticleReadyToPublish::class]); + Event::fake([ArticleApproved::class]); + + // Disable approvals so listener auto-approves valid articles + Setting::setBool('enable_publishing_approvals', false); $feed = Feed::factory()->create(); $article = Article::factory()->create([ @@ -200,8 +204,8 @@ public function test_validate_article_listener_processes_new_article(): void $listener->handle($event); $article->refresh(); - $this->assertNotEquals('pending', $article->approval_status); - $this->assertContains($article->approval_status, ['approved', 'rejected']); + $this->assertEquals('approved', $article->approval_status); + Event::assertDispatched(ArticleApproved::class); } // Test removed - PublishApprovedArticle and ArticleReadyToPublish classes no longer exist diff --git a/tests/Unit/Models/ArticleTest.php b/tests/Unit/Models/ArticleTest.php index e8ba894..93d5617 100644 --- a/tests/Unit/Models/ArticleTest.php +++ b/tests/Unit/Models/ArticleTest.php @@ -46,15 +46,26 @@ public function test_is_valid_returns_false_when_approval_status_is_rejected(): $this->assertFalse($article->isValid()); } - public function test_is_valid_returns_true_when_approval_status_is_approved(): void + public function test_is_valid_returns_true_when_validated_and_not_rejected(): void { $article = Article::factory()->make([ 'approval_status' => 'approved', + 'validated_at' => now(), ]); $this->assertTrue($article->isValid()); } + public function test_is_valid_returns_false_when_not_validated(): void + { + $article = Article::factory()->make([ + 'approval_status' => 'approved', + 'validated_at' => null, + ]); + + $this->assertFalse($article->isValid()); + } + public function test_is_approved_returns_true_for_approved_status(): void { $article = Article::factory()->make(['approval_status' => 'approved']); @@ -149,10 +160,12 @@ public function test_can_be_published_requires_approval_when_approvals_enabled() $pendingArticle = Article::factory()->make([ 'approval_status' => 'pending', + 'validated_at' => now(), ]); $approvedArticle = Article::factory()->make([ 'approval_status' => 'approved', + 'validated_at' => now(), ]); $this->assertFalse($pendingArticle->canBePublished()); @@ -165,7 +178,8 @@ public function test_can_be_published_returns_true_when_approvals_disabled(): vo Setting::where('key', 'enable_publishing_approvals')->delete(); $article = Article::factory()->make([ - 'approval_status' => 'approved', // Only approved articles can be published + 'approval_status' => 'approved', + 'validated_at' => now(), ]); $this->assertTrue($article->canBePublished()); diff --git a/tests/Unit/Services/Publishing/ArticlePublishingServiceTest.php b/tests/Unit/Services/Publishing/ArticlePublishingServiceTest.php index 53da385..6880c9f 100644 --- a/tests/Unit/Services/Publishing/ArticlePublishingServiceTest.php +++ b/tests/Unit/Services/Publishing/ArticlePublishingServiceTest.php @@ -62,7 +62,8 @@ public function test_publish_to_routed_channels_returns_empty_collection_when_no $feed = Feed::factory()->create(); $article = Article::factory()->create([ 'feed_id' => $feed->id, - 'approval_status' => 'approved' + 'approval_status' => 'approved', + 'validated_at' => now() ]); $extractedData = ['title' => 'Test Title']; @@ -79,6 +80,7 @@ public function test_publish_to_routed_channels_skips_routes_without_active_acco $article = Article::factory()->create([ 'feed_id' => $feed->id, 'approval_status' => 'approved', + 'validated_at' => now(), ]); // Create a route with a channel but no active accounts @@ -105,7 +107,8 @@ public function test_publish_to_routed_channels_successfully_publishes_to_channe { // Arrange $feed = Feed::factory()->create(); - $article = Article::factory()->create(['feed_id' => $feed->id, 'approval_status' => 'approved']); + $article = Article::factory()->create(['feed_id' => $feed->id, 'approval_status' => 'approved', + 'validated_at' => now()]); $platformInstance = PlatformInstance::factory()->create(); $channel = PlatformChannel::factory()->create(['platform_instance_id' => $platformInstance->id]); @@ -151,7 +154,8 @@ public function test_publish_to_routed_channels_handles_publishing_failure_grace { // Arrange $feed = Feed::factory()->create(); - $article = Article::factory()->create(['feed_id' => $feed->id, 'approval_status' => 'approved']); + $article = Article::factory()->create(['feed_id' => $feed->id, 'approval_status' => 'approved', + 'validated_at' => now()]); $platformInstance = PlatformInstance::factory()->create(); $channel = PlatformChannel::factory()->create(['platform_instance_id' => $platformInstance->id]); @@ -192,7 +196,8 @@ public function test_publish_to_routed_channels_publishes_to_multiple_routes(): { // Arrange $feed = Feed::factory()->create(); - $article = Article::factory()->create(['feed_id' => $feed->id, 'approval_status' => 'approved']); + $article = Article::factory()->create(['feed_id' => $feed->id, 'approval_status' => 'approved', + 'validated_at' => now()]); $platformInstance = PlatformInstance::factory()->create(); $channel1 = PlatformChannel::factory()->create(['platform_instance_id' => $platformInstance->id]); @@ -247,7 +252,8 @@ public function test_publish_to_routed_channels_filters_out_failed_publications( { // Arrange $feed = Feed::factory()->create(); - $article = Article::factory()->create(['feed_id' => $feed->id, 'approval_status' => 'approved']); + $article = Article::factory()->create(['feed_id' => $feed->id, 'approval_status' => 'approved', + 'validated_at' => now()]); $platformInstance = PlatformInstance::factory()->create(); $channel1 = PlatformChannel::factory()->create(['platform_instance_id' => $platformInstance->id]); @@ -305,6 +311,7 @@ public function test_publish_skips_duplicate_when_url_already_posted_to_channel( $article = Article::factory()->create([ 'feed_id' => $feed->id, 'approval_status' => 'approved', + 'validated_at' => now(), 'url' => 'https://example.com/article-1', ]); @@ -356,6 +363,7 @@ public function test_publish_skips_duplicate_when_title_already_posted_to_channe $article = Article::factory()->create([ 'feed_id' => $feed->id, 'approval_status' => 'approved', + 'validated_at' => now(), 'url' => 'https://example.com/article-new-url', 'title' => 'Breaking News: Something Happened', ]); @@ -408,6 +416,7 @@ public function test_publish_proceeds_when_no_duplicate_exists(): void $article = Article::factory()->create([ 'feed_id' => $feed->id, 'approval_status' => 'approved', + 'validated_at' => now(), 'url' => 'https://example.com/unique-article', ]);