2026-09-29 14:51:46 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-11-16 14:21:17 +01:00
|
|
|
namespace Tests\Integration\WithApp\App\Cqs\Actions\Common;
|
|
|
|
|
|
2026-09-29 14:51:46 +02:00
|
|
|
use App\Contracts\ActionInput;
|
2026-11-10 14:28:00 +01:00
|
|
|
use App\Cqs\Actions\Common\ToggleModelStar;
|
|
|
|
|
use App\Cqs\Actions\Common\ToggleModelStarInput;
|
2026-09-29 14:51:46 +02:00
|
|
|
use App\Models\Product;
|
|
|
|
|
use App\Models\Range;
|
|
|
|
|
use Domain\Enums\ProductBrand;
|
|
|
|
|
use Domain\Enums\SellUnit;
|
|
|
|
|
use Domain\Enums\TaxRate;
|
|
|
|
|
use Domain\Enums\Units\InvoicingUnit;
|
|
|
|
|
use Domain\Enums\Units\OrderUnit;
|
|
|
|
|
use Money\Money;
|
|
|
|
|
|
|
|
|
|
describe('ToggleModelStar action', function (): void {
|
|
|
|
|
it('toggles model star in database', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$range = new Range();
|
|
|
|
|
$range->name = 'Test Range ' . uniqid();
|
|
|
|
|
$range->status = true;
|
|
|
|
|
$range->order = random_int(1, 9999);
|
|
|
|
|
$range->picture_alt = 'alt';
|
|
|
|
|
$range->picture_title = 'title';
|
|
|
|
|
$range->save();
|
|
|
|
|
|
|
|
|
|
$product = new Product([
|
|
|
|
|
'range_id' => $range->id,
|
|
|
|
|
'name' => 'Test Product ' . uniqid(),
|
|
|
|
|
'brand' => ProductBrand::loue,
|
|
|
|
|
'invoicing_unit' => InvoicingUnit::PCE,
|
|
|
|
|
'sell_unit' => SellUnit::PCE,
|
|
|
|
|
'order_unit' => OrderUnit::PCE,
|
|
|
|
|
'tax_rate' => TaxRate::TVA_20,
|
|
|
|
|
'description' => 'Test description',
|
|
|
|
|
'status' => true,
|
|
|
|
|
]);
|
|
|
|
|
$product->price = Money::EUR(1000);
|
|
|
|
|
$product->short_description = 'Short test description';
|
|
|
|
|
$product->picture_alt = 'test alt';
|
|
|
|
|
$product->picture_title = 'test title';
|
|
|
|
|
$product->picture_large_alt = 'test alt';
|
|
|
|
|
$product->picture_large_title = 'test title';
|
|
|
|
|
$product->star = false;
|
|
|
|
|
$product->save();
|
|
|
|
|
|
|
|
|
|
$action = new ToggleModelStar();
|
|
|
|
|
$input = new ToggleModelStarInput($product);
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$result = $action($input);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($result->getAttribute('star'))->toBeTrue();
|
|
|
|
|
|
|
|
|
|
$fresh = Product::query()->find($product->id);
|
|
|
|
|
assert($fresh instanceof Product);
|
|
|
|
|
expect($fresh->getAttribute('star'))->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('throws when an invalid input is passed', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$action = new ToggleModelStar();
|
|
|
|
|
$invalidInput = new class () implements ActionInput
|
|
|
|
|
{
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
expect(
|
|
|
|
|
/** @phpstan-ignore argument.type */
|
|
|
|
|
fn () => $action($invalidInput)
|
|
|
|
|
)
|
|
|
|
|
// THEN
|
|
|
|
|
->toThrow(\InvalidArgumentException::class);
|
|
|
|
|
});
|
|
|
|
|
});
|