fedi-feed-router/backend/tests/Feature/Http/Console/Commands/FetchNewArticlesCommandTest.php

63 lines
1.7 KiB
PHP

<?php
namespace Tests\Feature\Http\Console\Commands;
use App\Jobs\ArticleDiscoveryJob;
use App\Models\Feed;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Queue;
use Illuminate\Testing\PendingCommand;
use Tests\TestCase;
class FetchNewArticlesCommandTest extends TestCase
{
use RefreshDatabase;
public function test_command_runs_successfully_when_feeds_exist(): void
{
Queue::fake();
Feed::factory()->create(['is_active' => true]);
/** @var PendingCommand $exitCode */
$exitCode = $this->artisan('article:refresh');
$exitCode->assertSuccessful();
$exitCode->assertExitCode(0);
}
public function test_command_does_not_dispatch_jobs_when_no_active_feeds_exist(): void
{
Queue::fake();
/** @var PendingCommand $exitCode */
$exitCode = $this->artisan('article:refresh');
$exitCode->assertSuccessful();
Queue::assertNotPushed(ArticleDiscoveryJob::class);
}
public function test_command_does_not_dispatch_jobs_when_only_inactive_feeds_exist(): void
{
Queue::fake();
Feed::factory()->create(['is_active' => false]);
/** @var PendingCommand $exitCode */
$exitCode = $this->artisan('article:refresh');
$exitCode->assertSuccessful();
Queue::assertNotPushed(ArticleDiscoveryJob::class);
}
public function test_command_logs_when_no_feeds_available(): void
{
Queue::fake();
/** @var PendingCommand $exitCode */
$exitCode = $this->artisan('article:refresh');
$exitCode->assertSuccessful();
$exitCode->expectsOutput('No active feeds found. Article discovery skipped.');
}
}