| Total Complexity | 4 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | abstract class AbstractTestCase extends TestCase |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var \Http\Client\HttpClient |
||
| 16 | */ |
||
| 17 | protected $httpClient; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var \IBM\Watson\Common\RequestBuilderInterface |
||
| 21 | */ |
||
| 22 | protected $requestBuilder; |
||
| 23 | |||
| 24 | public function setUp() |
||
| 25 | { |
||
| 26 | $this->httpClient = m::mock(HttpClient::class); |
||
| 27 | $this->requestBuilder = m::mock(RequestBuilder::class); |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Get mock response from file. |
||
| 32 | * |
||
| 33 | * @param string $path Location of the response file. |
||
| 34 | * @param int $code HTTP status code. |
||
| 35 | * |
||
| 36 | * @return \GuzzleHttp\Psr7\Response |
||
| 37 | */ |
||
| 38 | public function getMockResponse($path, $code = 200): Response |
||
| 39 | { |
||
| 40 | $ref = new ReflectionObject($this); |
||
| 41 | $dir = \dirname($ref->getFileName()); |
||
| 42 | |||
| 43 | if (!file_exists($dir.'/mock/'.$path) && file_exists($dir.'/../mock/'.$path)) { |
||
| 44 | return new Response( |
||
| 45 | $code, |
||
| 46 | [ |
||
| 47 | 'Content-Type' => 'application/json', |
||
| 48 | ], |
||
| 49 | file_get_contents($dir.'/../mock/'.$path) |
||
| 50 | ); |
||
| 51 | } |
||
| 52 | |||
| 53 | return new Response($code, [], file_get_contents($dir.'/mock/'.$path)); |
||
| 54 | } |
||
| 56 |