| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?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 ApiRequestService $apiRequestService;
- public function setUp(): void {
- $client = $this->getMockBuilder(HttpClientInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $response->method('getContent')->willReturn('{"a": 1}');
- $client
- ->expects($this->once())
- ->method('request')
- ->with("GET", "my_url.org")
- ->willReturn($response);
- $this->apiRequestService = new ApiRequestService($client);
- }
- public function testGetJsonContent() {
- $this->assertEquals(
- ['a' => 1],
- $this->apiRequestService->getJsonContent('my_url.org')
- );
- }
- public function testGetContent() {
- $this->assertEquals(
- '{"a": 1}',
- $this->apiRequestService->getContent('my_url.org')
- );
- }
- }
|