- Refactored tests to utilize Webmozart Assert for type assertions. - Improved clarity and consistency in test expectations across multiple test files. - Ensured that all relevant tests now check for expected types and values.
64 lines
1.7 KiB
PHP
64 lines
1.7 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;
|
|
use Illuminate\Testing\PendingCommand;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
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
|
|
$command = $this->artisan('uwil:upsert-shops-hollydays');
|
|
Assert::isInstanceOf($command, PendingCommand::class);
|
|
|
|
// THEN
|
|
$command->assertSuccessful()->execute();
|
|
|
|
Bus::assertDispatched(UpsertShopsPickupExceptionsUsingApiForYear::class);
|
|
});
|
|
|
|
it('dispatches the job for the specified numeric year', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $this */
|
|
Bus::fake();
|
|
|
|
// WHEN
|
|
$command = $this->artisan('uwil:upsert-shops-hollydays', ['year' => '2027']);
|
|
Assert::isInstanceOf($command, PendingCommand::class);
|
|
|
|
// THEN
|
|
$command->assertSuccessful()->execute();
|
|
|
|
Bus::assertDispatched(UpsertShopsPickupExceptionsUsingApiForYear::class);
|
|
});
|
|
|
|
it('fails when year argument is not numeric', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $this */
|
|
Bus::fake();
|
|
|
|
// WHEN
|
|
$command = $this->artisan('uwil:upsert-shops-hollydays', ['year' => 'abc']);
|
|
Assert::isInstanceOf($command, PendingCommand::class);
|
|
|
|
// THEN
|
|
$command
|
|
->expectsOutput('The year must be a number')
|
|
->assertFailed()
|
|
->execute();
|
|
|
|
Bus::assertNotDispatched(UpsertShopsPickupExceptionsUsingApiForYear::class);
|
|
});
|