47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Integration\WithApp\App\Cqs\Actions\Common;
|
|
|
|
use App\Contracts\ActionInput;
|
|
use App\Cqs\Actions\Common\ToggleModelStatus;
|
|
use App\Cqs\Actions\Common\ToggleModelStatusInput;
|
|
use App\Models\Tag;
|
|
|
|
describe('ToggleModelStatus action', function (): void {
|
|
it('toggles model status in database', function (): void {
|
|
// GIVEN
|
|
$tag = Tag::factory()->create([
|
|
'status' => true,
|
|
]);
|
|
|
|
$action = new ToggleModelStatus();
|
|
$input = new ToggleModelStatusInput($tag);
|
|
|
|
// WHEN
|
|
$result = $action($input);
|
|
|
|
// THEN
|
|
expect($result->getAttribute('status'))->toBeFalse();
|
|
|
|
$fresh = Tag::query()->find($tag->id);
|
|
expect($fresh?->getAttribute('status'))->toBeFalse();
|
|
});
|
|
|
|
it('throws when an invalid input is passed', function (): void {
|
|
// GIVEN
|
|
$action = new ToggleModelStatus();
|
|
$invalidInput = new class () implements ActionInput
|
|
{
|
|
};
|
|
|
|
// WHEN
|
|
expect(
|
|
/** @phpstan-ignore argument.type */
|
|
fn () => $action($invalidInput)
|
|
)
|
|
// THEN
|
|
->toThrow(\InvalidArgumentException::class);
|
|
});
|
|
});
|