51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
use App\Actions\Common\ChangeModelOrderPositionInput;
|
||
|
|
use App\Interfaces\ModelWithOrder;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
|
||
|
|
describe('ChangeModelOrderPositionInput', function (): void {
|
||
|
|
it('can be instantiated with a model implementing ModelWithOrder and a valid target order', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$mock = new class () extends Model implements ModelWithOrder
|
||
|
|
{
|
||
|
|
public function getOrder(): int
|
||
|
|
{
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function setOrder(int $order): void
|
||
|
|
{
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$input = new ChangeModelOrderPositionInput(model: $mock, targetOrder: 5);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($input->model)->toBe($mock)
|
||
|
|
->and($input->targetOrder)->toBe(5);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('throws when target order is less than 1', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$mock = new class () extends Model implements ModelWithOrder
|
||
|
|
{
|
||
|
|
public function getOrder(): int
|
||
|
|
{
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function setOrder(int $order): void
|
||
|
|
{
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
// WHEN & THEN
|
||
|
|
expect(fn () => new ChangeModelOrderPositionInput(model: $mock, targetOrder: 0))
|
||
|
|
->toThrow(\InvalidArgumentException::class);
|
||
|
|
});
|
||
|
|
});
|