Files
Starseed/tests/Module/Logistique/Infrastructure/Weighbridge/WeighbridgeReaderStubTest.php
T
Matthieu e455204bbd feat(logistique) : pesée pont bascule stub + allocateur DSD + endpoint (ERP-184)
- WeighbridgeReaderInterface (contrat) + RandomWeighbridgeReader (stub,
  poids aléatoire ∈ [10000,50000] kg, RG-5.06) + WeighbridgeUnavailableException
- DsdAllocator : compteur DSD par site (weighbridge_dsd_counter) incrémenté
  sous verrou ligne SELECT ... FOR UPDATE (RG-5.04, § 2.7)
- endpoint POST /api/weighbridge_readings : ressource virtuelle
  WeighbridgeReadingResource + WeighbridgeReadingProcessor (pas de controller)
  - AUTO -> {weight, dsd, mode} ; MANUAL -> {weight, dsd, manualNumber, mode}
  - WeighbridgeUnavailableException -> HTTP 503 explicite (RG-5.06)
  - site courant via CurrentSiteProviderInterface (contrat Sites)
  - is_granted('logistique.weighing_tickets.manage')
- dsd renvoyé prévisionnel : attribution autoritaire refaite à la création
  du ticket (ERP-185)
- tests : WeighbridgeReaderStubTest, DsdAllocatorTest, processor (503/400),
  WeighbridgeReadingApiTest (RBAC + AUTO/MANUAL + 422)
2026-06-17 18:09:54 +02:00

57 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Module\Logistique\Infrastructure\Weighbridge;
use App\Module\Logistique\Application\Service\DsdAllocatorInterface;
use App\Module\Logistique\Infrastructure\Weighbridge\RandomWeighbridgeReader;
use App\Shared\Domain\Contract\SiteInterface;
use PHPUnit\Framework\TestCase;
/**
* Stub du pont bascule (RG-5.06 / § 2.6).
*
* Verifie le contrat du stub livre au M5 : poids aleatoire borne a
* [10000, 50000] kg et DSD delegue a l'allocateur (le chemin d'erreur 503
* est couvert cote Processor — WeighbridgeReadingProcessorTest).
*
* @internal
*/
final class WeighbridgeReaderStubTest extends TestCase
{
/**
* RG-5.06 : sur un grand nombre de lectures, le poids reste toujours dans
* l'intervalle borne [10000, 50000] (random_int inclusif aux deux bornes).
*/
public function testReadReturnsWeightWithinBounds(): void
{
$allocator = $this->createStub(DsdAllocatorInterface::class);
$allocator->method('next')->willReturn(1);
$reader = new RandomWeighbridgeReader($allocator);
$site = $this->createStub(SiteInterface::class);
for ($i = 0; $i < 500; ++$i) {
$reading = $reader->read($site);
self::assertGreaterThanOrEqual(10000, $reading->weight);
self::assertLessThanOrEqual(50000, $reading->weight);
}
}
/**
* RG-5.04 : le DSD renvoye par la lecture est celui fourni par l'allocateur
* de site (le reader ne calcule pas le DSD lui-meme).
*/
public function testReadDelegatesDsdToAllocator(): void
{
$allocator = $this->createStub(DsdAllocatorInterface::class);
$allocator->method('next')->willReturn(42);
$reader = new RandomWeighbridgeReader($allocator);
$reading = $reader->read($this->createStub(SiteInterface::class));
self::assertSame(42, $reading->dsd);
}
}