- 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.
61 lines
1.3 KiB
PHP
61 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Casts\CodeCast;
|
|
use Domain\Models\ValueObjects\Code;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
it('gets a code', function () {
|
|
// GIVEN
|
|
$cast = new CodeCast();
|
|
$model = \Mockery::mock(Model::class);
|
|
|
|
// WHEN
|
|
$code = $cast->get($model, 'code', 'ABCDEFGH', []);
|
|
|
|
// THEN
|
|
expect($code)->toBeInstanceOf(Code::class)
|
|
->and($code->value)->toBe('ABCDEFGH');
|
|
});
|
|
|
|
it('throws exception when getting null code', function () {
|
|
// GIVEN
|
|
$cast = new CodeCast();
|
|
$model = \Mockery::mock(Model::class);
|
|
|
|
// WHEN
|
|
$cast->get($model, 'code', null, []);
|
|
|
|
// THEN
|
|
})->throws(
|
|
\UnexpectedValueException::class,
|
|
'Code must be a string.'
|
|
);
|
|
|
|
it('sets a code', function () {
|
|
// GIVEN
|
|
$cast = new CodeCast();
|
|
$model = \Mockery::mock(Model::class);
|
|
$code = new Code('ABCDEFGH');
|
|
|
|
// WHEN
|
|
$value = $cast->set($model, 'code', $code, []);
|
|
|
|
// THEN
|
|
expect($value)->toBe('ABCDEFGH');
|
|
});
|
|
|
|
it('throws exception when setting invalid code', function () {
|
|
// GIVEN
|
|
$cast = new CodeCast();
|
|
$model = \Mockery::mock(Model::class);
|
|
|
|
// WHEN
|
|
$cast->set($model, 'code', 'ABCDEFGH', []);
|
|
|
|
// THEN
|
|
})->throws(
|
|
\UnexpectedValueException::class,
|
|
'The given value is not an instance of Code.'
|
|
);
|