fix(brand): filter out comment tuples and enforce positive integer validation for ArcadiaId

This commit is contained in:
Jérémy Munsch 2026-08-31 11:45:35 +02:00
parent 2d7d7d5077
commit 97a73a5e05
Signed by: forge-joniko
GPG key ID: D7EFE2F5CB6CC0E4
5 changed files with 47 additions and 5 deletions

View file

@ -8,7 +8,7 @@ use Shared\DDD\Model\EntityId;
final readonly class ArcadiaId extends EntityId
{
private const string PATTERN = '/^[1-9]\d{0,}$/';
private const string PATTERN = '/^[1-9]\d*$/';
public function __construct(
string $value

View file

@ -9,6 +9,7 @@ use Domain\Models\ValueObjects\Brand\ArcadiaBrand;
use Domain\Models\ValueObjects\Brand\ArcadiaId;
use Domain\Ports\Directories\ArcadiaBrandDirectory as ArcadiaBrandDirectoryPort;
use Illuminate\Database\Connection;
use Illuminate\Database\Query\Builder;
use Infra\Adapters\Mappers\ArcadiaBrandMapper;
final class ArcadiaMarqueBrandDirectory implements ArcadiaBrandDirectoryPort
@ -26,6 +27,14 @@ final class ArcadiaMarqueBrandDirectory implements ArcadiaBrandDirectoryPort
{
$rows = $this->connection
->table(MarqueTable::table($this->connection))
->where('COD_MARQ', '>', 0)
->where('LIB_MARQ', 'NOT LIKE', 'Z -%')
->where(static function (Builder $q): void {
$q->whereNull('A_EPURER')->orWhere('A_EPURER', '!=', 1);
})
->where(static function (Builder $q): void {
$q->whereNull('TYPE_MARQUE')->orWhere('TYPE_MARQUE', '!=', 99);
})
->get();
$items = [];
@ -49,6 +58,14 @@ final class ArcadiaMarqueBrandDirectory implements ArcadiaBrandDirectoryPort
$row = $this->connection
->table(MarqueTable::table($this->connection))
->where('COD_MARQ', $id->value)
->where('COD_MARQ', '>', 0)
->where('LIB_MARQ', 'NOT LIKE', 'Z -%')
->where(static function (Builder $q): void {
$q->whereNull('A_EPURER')->orWhere('A_EPURER', '!=', 1);
})
->where(static function (Builder $q): void {
$q->whereNull('TYPE_MARQUE')->orWhere('TYPE_MARQUE', '!=', 99);
})
->first();
if ($row === null) {

View file

@ -30,12 +30,20 @@ final class InMemoryArcadiaBrandDirectory implements ArcadiaBrandDirectory
#[\Override]
public function findAll(): array
{
return array_values($this->brands);
return array_values(array_filter(
$this->brands,
static fn (ArcadiaBrand $b): bool => ! str_starts_with($b->name->value, 'Z -')
));
}
#[\Override]
public function find(ArcadiaId $id): ?ArcadiaBrand
{
return $this->brands[$id->value] ?? null;
$brand = $this->brands[$id->value] ?? null;
if ($brand !== null && str_starts_with($brand->name->value, 'Z -')) {
return null;
}
return $brand;
}
}

View file

@ -15,7 +15,7 @@ describe('ArcadiaId Value Object Instantiation', function (): void {
// THEN
expect($arcadiaId->value)->toBe($data);
})->with(['1', '999', '123']);
})->with(['1', '999', '123', '1000', '1199']);
});
describe('ArcadiaId Value Object Domain Rules', function (): void {
@ -23,5 +23,5 @@ describe('ArcadiaId Value Object Domain Rules', function (): void {
// WHEN & THEN
expect(fn () => new ArcadiaId($invalid))
->toThrow(\DomainException::class);
})->with(['0', '1000', '-1', 'abc', '', '01']);
})->with(['0', '-1', 'abc', '', '01', '1.5', '-100']);
});

View file

@ -49,4 +49,21 @@ describe('InMemoryArcadiaBrandDirectory Unit Tests', function (): void {
// THEN
expect($directory->findAll())->toBeEmpty();
});
it('filters out comment and obsolete brands starting with Z -', function (): void {
// GIVEN
$directory = new InMemoryArcadiaBrandDirectory();
$valid = new ArcadiaBrand(new ArcadiaId('1'), new BrandName('Le Gaulois'));
$comment = new ArcadiaBrand(new ArcadiaId('2'), new BrandName('Z - PLUS DE CODE ART - VENTRABEN'));
$directory->add($valid, $comment);
// WHEN
$all = $directory->findAll();
$found = $directory->find(new ArcadiaId('2'));
// THEN
expect($all)->toHaveCount(1)
->and($all[0]->id->value)->toBe('1')
->and($found)->toBeNull();
});
});