| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace App\Tests\Service;
- use App\Service\Rest\ApiRequestService;
- use PHPUnit\Framework\TestCase;
- use Symfony\Contracts\HttpClient\HttpClientInterface;
- use Symfony\Contracts\HttpClient\ResponseInterface;
- class ApiRequestServiceTest extends TestCase
- {
- private HttpClientInterface $client;
- private ApiRequestService $apiRequestService;
- public function setUp(): void {
- $this->client = $this->getMockBuilder(HttpClientInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $response->method('getContent')->willReturn('{"a": 1}');
- $this->client
- ->expects($this->once())
- ->method('request')
- ->with("GET", "my_url.org")
- ->willReturn($response);
- $this->apiRequestService = new ApiRequestService($this->client);
- }
- public function testGetJsonContent() {
- $this->assertEquals(
- $this->apiRequestService->getJsonContent('my_url.org'),
- ['a' => 1]
- );
- }
- public function testGetContent() {
- $this->assertEquals(
- $this->apiRequestService->getContent('my_url.org'),
- '{"a": 1}'
- );
- }
- }
|