SiretTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. namespace App\Tests\Service\Utils;
  3. use App\Service\Utils\Siret;
  4. use PHPUnit\Framework\TestCase;
  5. use Symfony\Component\HttpClient\MockHttpClient;
  6. use Symfony\Component\HttpClient\Response\MockResponse;
  7. use Symfony\Contracts\HttpClient\HttpClientInterface;
  8. use Symfony\Contracts\HttpClient\ResponseInterface;
  9. class SiretTest extends TestCase
  10. {
  11. private HttpClientInterface $client;
  12. public function setUp(): void
  13. {
  14. $this->client = $this->getMockBuilder(HttpClientInterface::class)
  15. ->disableOriginalConstructor()
  16. ->getMock();
  17. }
  18. /**
  19. * @see Siret::isSiretCorrect()
  20. */
  21. public function testIsSiretCorrect():void
  22. {
  23. $siret = $this->getMockBuilder(Siret::class)
  24. ->setConstructorArgs([$this->client])
  25. ->setMethodsExcept(['isSiretCorrect'])
  26. ->getMock();
  27. $response = $this->getMockBuilder(ResponseInterface::class)->getMock();
  28. $response->method('getStatusCode')->willReturn(200);
  29. $this->client->expects(self::once())->method('request')->willReturn($response);
  30. $this->assertTrue(
  31. $siret->isSiretCorrect('50465312200052')
  32. );
  33. }
  34. /**
  35. * @see Siret::isSiretCorrect()
  36. */
  37. public function testIsNotSiretCorrect():void
  38. {
  39. $siret = $this->getMockBuilder(Siret::class)
  40. ->setConstructorArgs([$this->client])
  41. ->setMethodsExcept(['isSiretCorrect'])
  42. ->getMock();
  43. $response = $this->getMockBuilder(ResponseInterface::class)->getMock();
  44. $response->method('getStatusCode')->willReturn(404);
  45. $this->client->expects(self::once())->method('request')->willReturn($response);
  46. $this->assertFalse($siret->isSiretCorrect('50465312200052'));
  47. }
  48. }