SiretTest.php 1.7 KB

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