| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace App\Tests\Service\Mobyt;
- use App\Service\Mobyt\MobytService;
- use PHPUnit\Framework\TestCase;
- use Symfony\Contracts\HttpClient\HttpClientInterface;
- use Symfony\Contracts\HttpClient\ResponseInterface;
- class MobytServiceTest extends TestCase
- {
- private HttpClientInterface $client;
- private MobytService $mobytService;
- public function setUp():void
- {
- $this->client = $this->getMockBuilder(HttpClientInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->mobytService = new MobytService($this->client);
- }
- private function getContentFromFixture(string $filename): string {
- $filepath = dirname(__FILE__) . '/fixtures/' . $filename;
- return file_get_contents($filepath);
- }
- /**
- * @see MobytService::getUserStatus()
- */
- public function testGetUserStatus(): void {
- // Mock the response that will be returned by the connection request
- $connectResponse = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $connectResponse->method('getContent')->willReturn('userId;sessionKey');
- // Mock the response that will be returned by the user_status request
- $responseContent = $this->getContentFromFixture('user_status.json');
- $response = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $response->method('getContent')->willReturn($responseContent);
- $this->client
- ->method('request')
- ->withConsecutive(
- ["GET", "login?username=user&password=pwd"],
- ["GET", "status?getMoney=true&typeAliases=true", ['headers' => [ 'user_key' => 'userId', 'Session_key' => 'sessionKey' ]]]
- )
- ->willReturnOnConsecutiveCalls(
- $connectResponse,
- $response
- );
- $data = $this->mobytService->getUserStatus(1, 'user', 'pwd');
- $this->assertEquals(
- $data['money'],
- 33.0
- );
- }
- }
|