SiretTest.php 1.7 KB

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