ldc-cocotte/tests/Integration/WithApp/App/Casts/ShopperServiceCodeCastTest.php
Jérémy Munsch 5197e796c0
test(casts): add tests for various cast classes
- Implement tests for DiscountValueCast to validate percentage and amount handling.
- Add tests for EmailCast to ensure proper email handling.
- Create tests for EmployeeSitesCast to validate JSON and array handling.
- Implement tests for MatriculeCast to validate matricule handling.
- Add tests for MoneyCast to ensure proper money handling.
- Create tests for NutritionalValuesCast to validate nutritional values handling.
- Implement tests for OrderEmployeeCast to validate employee data handling.
- Add tests for OrderLineProductCast to validate order line product handling.
- Create tests for OrderReferenceCast to validate order reference handling.
- Implement tests for ShopperEstablishmentCodeCast to validate establishment code handling.
- Add tests for ShopperServiceCodeCast to validate service code handling.
- Create tests for ShopperSiteCodeCast to validate site code handling.
2026-11-15 18:56:19 +01:00

78 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
use App\Casts\ShopperServiceCodeCast;
use Domain\Models\ValueObjects\ShopperServiceCode;
use Illuminate\Database\Eloquent\Model;
it('gets a ShopperServiceCode', function () {
// GIVEN
$cast = new ShopperServiceCodeCast();
$model = \Mockery::mock(Model::class);
// WHEN
$code = $cast->get($model, 'service', '101', []);
// THEN
expect($code)->toBeInstanceOf(ShopperServiceCode::class)
->and($code->value)->toBe('101');
});
it('throws exception when getting invalid ShopperServiceCode type', function () {
// GIVEN
$cast = new ShopperServiceCodeCast();
$model = \Mockery::mock(Model::class);
// WHEN
$cast->get($model, 'service', 123, []);
// THEN
})->throws(\UnexpectedValueException::class, 'ShopperServiceCode must be a string.');
it('throws exception when getting null ShopperServiceCode', function () {
// GIVEN
$cast = new ShopperServiceCodeCast();
$model = \Mockery::mock(Model::class);
// WHEN
$cast->get($model, 'service', null, []);
// THEN
})->throws(\UnexpectedValueException::class, 'ShopperServiceCode must be a string.');
it('sets a ShopperServiceCode from instance', function () {
// GIVEN
$cast = new ShopperServiceCodeCast();
$model = \Mockery::mock(Model::class);
$vo = new ShopperServiceCode('101');
// WHEN
$value = $cast->set($model, 'service', $vo, []);
// THEN
expect($value)->toBe('101');
});
it('sets a ShopperServiceCode from valid string', function () {
// GIVEN
$cast = new ShopperServiceCodeCast();
$model = \Mockery::mock(Model::class);
// WHEN
$value = $cast->set($model, 'service', '101', []);
// THEN
expect($value)->toBe('101');
});
it('throws exception when setting invalid ShopperServiceCode type', function () {
// GIVEN
$cast = new ShopperServiceCodeCast();
$model = \Mockery::mock(Model::class);
// WHEN
$cast->set($model, 'service', 123, []);
// THEN
})->throws(\UnexpectedValueException::class, 'The given value is not an instance of ShopperServiceCode.');