nstack-io /
php-sdk
| 1 | <?php |
||
| 2 | |||
| 3 | namespace NStack\Tests; |
||
| 4 | |||
| 5 | use GuzzleHttp\Client; |
||
| 6 | use GuzzleHttp\Psr7\Response; |
||
| 7 | use NStack\Config; |
||
| 8 | |||
| 9 | class TestCase extends \PHPUnit\Framework\TestCase |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * getMockAsArray |
||
| 13 | * |
||
| 14 | * @param string $fileName |
||
| 15 | * @return array |
||
| 16 | * @author Casper Rasmussen <[email protected]> |
||
| 17 | */ |
||
| 18 | protected function getMockAsArray(string $fileName): array |
||
| 19 | { |
||
| 20 | $content = file_get_contents(getcwd() . '/tests/mocks/' . $fileName); |
||
| 21 | |||
| 22 | return json_decode($content, true); |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * getClientWithMockedGet |
||
| 27 | * |
||
| 28 | * @param string $filename |
||
| 29 | * @return \GuzzleHttp\Client |
||
| 30 | * @author Casper Rasmussen <[email protected]> |
||
| 31 | */ |
||
| 32 | protected function getClientWithMockedGet(string $filename): Client |
||
| 33 | { |
||
| 34 | $response = new Response(200, ['Content-Type' => 'application/json'], |
||
| 35 | $this->getMockAsString($filename)); |
||
| 36 | |||
| 37 | $guzzle = \Mockery::mock(\GuzzleHttp\Client::class); |
||
| 38 | $guzzle->shouldReceive('get')->once()->andReturn($response); |
||
| 39 | |||
| 40 | return $guzzle; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * getClientWithMockedPost |
||
| 45 | * |
||
| 46 | * @param string $filename |
||
| 47 | * @return Client |
||
| 48 | * @author Tiago Araujo <[email protected]> |
||
| 49 | */ |
||
| 50 | protected function getClientWithMockedPost(string $filename): Client |
||
| 51 | { |
||
| 52 | $response = new Response(200, ['Content-Type' => 'application/json'], |
||
| 53 | $this->getMockAsString($filename)); |
||
| 54 | |||
| 55 | $guzzle = \Mockery::mock(Client::class); |
||
| 56 | $guzzle->shouldReceive('post')->once()->andReturn($response); |
||
| 57 | |||
| 58 | return $guzzle; |
||
|
0 ignored issues
–
show
|
|||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * getClientWithMockedDelete |
||
| 63 | * |
||
| 64 | * @param string $filename |
||
| 65 | * @return Client |
||
| 66 | * @author Tiago Araujo <[email protected]> |
||
| 67 | */ |
||
| 68 | protected function getClientWithMockedDelete(string $filename): Client |
||
| 69 | { |
||
| 70 | $response = new Response(200, ['Content-Type' => 'application/json'], |
||
| 71 | $this->getMockAsString($filename)); |
||
| 72 | |||
| 73 | $guzzle = \Mockery::mock(Client::class); |
||
| 74 | $guzzle->shouldReceive('delete')->once()->andReturn($response); |
||
| 75 | |||
| 76 | return $guzzle; |
||
|
0 ignored issues
–
show
|
|||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * getMockAsString |
||
| 81 | * |
||
| 82 | * @param string $fileName |
||
| 83 | * @return string |
||
| 84 | * @author Casper Rasmussen <[email protected]> |
||
| 85 | */ |
||
| 86 | protected function getMockAsString(string $fileName): string |
||
| 87 | { |
||
| 88 | return file_get_contents(getcwd() . '/tests/mocks/' . $fileName); |
||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * getConfig |
||
| 93 | * |
||
| 94 | * @return \NStack\Config |
||
| 95 | * @author Casper Rasmussen <[email protected]> |
||
| 96 | */ |
||
| 97 | public function getConfig(): Config |
||
| 98 | { |
||
| 99 | return new Config('', ''); |
||
| 100 | } |
||
| 101 | |||
| 102 | } |
||
| 103 |