ldc-cocotte/tests/Feature/App/Console/Commands/UpsertPublicHolydaysOnShopsPickupExceptionsTest.php

54 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\App\Console\Commands;
use App\Jobs\UpsertShopsPickupExceptionsUsingApiForYear;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Date;
afterEach(function (): void {
Date::setTestNow();
});
it('dispatches the job for next year when year argument is omitted', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
Date::setTestNow('2026-06-15 10:00:00');
Bus::fake();
// WHEN
$this->artisan('uwil:upsert-shops-hollydays')
// THEN
->assertSuccessful();
Bus::assertDispatched(UpsertShopsPickupExceptionsUsingApiForYear::class);
});
it('dispatches the job for the specified numeric year', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
Bus::fake();
// WHEN
$this->artisan('uwil:upsert-shops-hollydays', ['year' => '2027'])
// THEN
->assertSuccessful();
Bus::assertDispatched(UpsertShopsPickupExceptionsUsingApiForYear::class);
});
it('fails when year argument is not numeric', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
Bus::fake();
// WHEN
$this->artisan('uwil:upsert-shops-hollydays', ['year' => 'abc'])
// THEN
->expectsOutput('The year must be a number')
->assertFailed();
Bus::assertNotDispatched(UpsertShopsPickupExceptionsUsingApiForYear::class);
});