yamcsha

MixerServiceTest.php

Nov 7th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Tests\App\Service;
  4.  
  5. use PHPUnit\Framework\TestCase;
  6. use Symfony\Contracts\HttpClient\ResponseInterface;
  7. use Symfony\Contracts\HttpClient\HttpClientInterface;
  8.  
  9. /**
  10.  * Class MixerServiceTest
  11.  * @package Tests\App\Service
  12.  */
  13. class MixerServiceTest extends TestCase
  14. {
  15.     /**
  16.      * Test GetData return array from calling the API
  17.      */
  18.     public function testGetData()
  19.     {
  20.         $httpClientMock = $this->getMockForAbstractClass(HttpClientInterface::class);
  21.  
  22.         $httpResponseMock = $this->getMockForAbstractClass(ResponseInterface::class);
  23.         $httpResponseMock->method('toArray')->willReturn(['foo' => 'bar']);
  24.  
  25.         $httpClientMock->method('request')->willReturn($httpResponseMock);
  26.  
  27.         $mixerService = new \App\Service\MixerService($httpClientMock);
  28.         $data = $mixerService->getData();
  29.  
  30.         $this->assertEquals($data, ['foo' => 'bar']);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment