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