| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php /** @noinspection PhpUnhandledExceptionInspection */
- namespace App\Tests\Service\Utils;
- use App\Service\Utils\Siret;
- use PHPUnit\Framework\TestCase;
- use Symfony\Contracts\HttpClient\HttpClientInterface;
- use Symfony\Contracts\HttpClient\ResponseInterface;
- class SiretTest extends TestCase
- {
- private HttpClientInterface $client;
- public function setUp(): void
- {
- $this->client = $this->getMockBuilder(HttpClientInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- }
- /**
- * @see Siret::isSiretCorrect()
- */
- public function testIsSiretCorrect():void
- {
- $siret = $this->getMockBuilder(Siret::class)
- ->setConstructorArgs([$this->client])
- ->setMethodsExcept(['isSiretCorrect'])
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)->getMock();
- $response->method('getStatusCode')->willReturn(200);
- $this->client->expects(self::once())->method('request')->willReturn($response);
- $this->assertTrue(
- $siret->isSiretCorrect('50465312200052')
- );
- }
- /**
- * @see Siret::isSiretCorrect()
- */
- public function testIsNotSiretCorrect():void
- {
- $siret = $this->getMockBuilder(Siret::class)
- ->setConstructorArgs([$this->client])
- ->setMethodsExcept(['isSiretCorrect'])
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)->getMock();
- $response->method('getStatusCode')->willReturn(404);
- $this->client->expects(self::once())->method('request')->willReturn($response);
- $this->assertFalse($siret->isSiretCorrect('50465312200052'));
- }
- }
|