123456, 'original_id' => Uuid::uuid7()->toString(), 'name' => 'Poulet Fermier', 'weight' => 1500, 'weight_variable' => true, 'brand' => ProductBrand::loue->value, 'order_unit' => OrderUnit::PCE->value, 'price' => 1050, 'discounted_price' => 950, 'price_kg_ttc' => 700, 'tax_rate' => TaxRate::TVA_5_5->percent(), 'picture' => 'poulet.jpg', ]); // WHEN $vo = $cast->get($model, 'product', $json, []); // THEN expect($vo)->toBeInstanceOf(OrderLineProduct::class) ->and($vo->incoId->value)->toBe(123456) ->and($vo->name)->toBe('Poulet Fermier') ->and($vo->weight->value)->toBe(1500) ->and($vo->weight->isVariable)->toBeTrue() ->and($vo->brand)->toBe(ProductBrand::loue) ->and($vo->orderUnit)->toBe(OrderUnit::PCE) ->and($vo->taxRate)->toBe(TaxRate::TVA_5_5) ->and($vo->picture)->toBe('poulet.jpg'); }); it('can set OrderLineProduct to JSON correctly', function () { // GIVEN $cast = new OrderLineProductCast(); $model = new class () extends Model { }; $vo = new OrderLineProduct( incoId: new IncoId(123456), originalId: new ProductId(Uuid::uuid7()), name: 'Poulet Fermier', weight: new ProductWeight(1500, true), brand: ProductBrand::loue, orderUnit: OrderUnit::PCE, price: new Money(1050, new Currency('EUR')), discountedPrice: new Money(950, new Currency('EUR')), priceKgTtc: new Money(700, new Currency('EUR')), taxRate: TaxRate::TVA_5_5, picture: 'poulet.jpg' ); // WHEN $json = $cast->set($model, 'product', $vo, []); $data = json_decode($json, true); // THEN expect($data) ->toBeArray() ->toHaveKey('weight', 1500) ->toHaveKey('weight_variable', true) ->not->toHaveKey('weight_unit'); }); it('throws exception if value is null on get', function () { // GIVEN $cast = new OrderLineProductCast(); $model = new class () extends Model { }; // WHEN / THEN $cast->get($model, 'product', null, []); })->throws(\InvalidArgumentException::class); it('throws exception if value is not string on get', function () { // GIVEN $cast = new OrderLineProductCast(); $model = new class () extends Model { }; // WHEN / THEN $cast->get($model, 'product', ['array' => 'invalid'], []); })->throws(\InvalidArgumentException::class); it('throws exception if value is not an OrderLineProduct on set', function () { // GIVEN $cast = new OrderLineProductCast(); $model = new class () extends Model { }; // WHEN / THEN $cast->set($model, 'product', 'not a VO', []); })->throws(\InvalidArgumentException::class); });