4a77449a41
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | #203 | Réceptions — Parcours de pesée multi-étapes | ## Description de la PR [#203] Réceptions — Parcours de pesée multi-étapes ## Modification du .env ## Check list - [x] Pas de régression - [x] TU/TI/TF rédigée - [x] TU/TI/TF OK - [x] CHANGELOG modifié Reviewed-on: https://gitea.malio.fr/MALIO-DEV/Ferme/pulls/3 Reviewed-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr> Co-authored-by: AUTIN Tristan <tristan@yuno.malio.fr> Co-committed-by: AUTIN Tristan <tristan@yuno.malio.fr>
63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\State;
|
|
|
|
use ApiPlatform\Metadata\Get;
|
|
use App\Dto\PontBasculeReading;
|
|
use App\Service\PontBasculePayloadDecoder;
|
|
use App\Service\PontBasculeService;
|
|
use App\State\ReceptionWeighingProvider;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
final class ReceptionWeighingProviderTest extends TestCase
|
|
{
|
|
public function testProvideReturnsReading(): void
|
|
{
|
|
$decoder = new PontBasculePayloadDecoder();
|
|
|
|
$httpClient = $this->createMock(HttpClientInterface::class);
|
|
$httpClient->expects(self::never())->method('request');
|
|
|
|
$service = new PontBasculeService($httpClient, $decoder, 'http://example.test', true);
|
|
|
|
$provider = new ReceptionWeighingProvider($service);
|
|
|
|
$result = $provider->provide(new Get());
|
|
|
|
self::assertInstanceOf(PontBasculeReading::class, $result);
|
|
self::assertSame(121, $result->getDsd());
|
|
self::assertSame(1420.0, $result->getWeight());
|
|
}
|
|
|
|
public function testProvideThrowsHttpException(): void
|
|
{
|
|
$exception = $this->createStub(TransportExceptionInterface::class);
|
|
|
|
$httpClient = $this->createMock(HttpClientInterface::class);
|
|
$httpClient
|
|
->expects(self::once())
|
|
->method('request')
|
|
->willThrowException($exception)
|
|
;
|
|
|
|
$decoder = new PontBasculePayloadDecoder();
|
|
|
|
$service = new PontBasculeService($httpClient, $decoder, 'http://example.test', false);
|
|
|
|
$provider = new ReceptionWeighingProvider($service);
|
|
|
|
$this->expectException(HttpException::class);
|
|
$this->expectExceptionMessage('Erreur lors de la communication avec le pont bascule:');
|
|
|
|
$provider->provide(new Get());
|
|
}
|
|
}
|