|
| 1 | +<?php namespace Gitlab\Tests\Api; |
| 2 | + |
| 3 | +use Gitlab\Api\AbstractApi; |
| 4 | +use Gitlab\Client; |
| 5 | +use Gitlab\HttpClient\Message\Response; |
| 6 | + |
| 7 | +class AbstractApiTest extends TestCase |
| 8 | +{ |
| 9 | + /** |
| 10 | + * @test |
| 11 | + */ |
| 12 | + public function shouldPassGETRequestToClient() |
| 13 | + { |
| 14 | + $response = $this->getResponse('value'); |
| 15 | + |
| 16 | + $httpClient = $this->getHttpMock(); |
| 17 | + $httpClient |
| 18 | + ->expects($this->any()) |
| 19 | + ->method('get') |
| 20 | + ->with('/path', array('param1' => 'param1value'), array('header1' => 'header1value')) |
| 21 | + ->will($this->returnValue($response)); |
| 22 | + |
| 23 | + $client = $this->getClientMock(); |
| 24 | + $client->setHttpClient($httpClient); |
| 25 | + |
| 26 | + $api = $this->getAbstractApiObject($client); |
| 27 | + $this->assertEquals('value', $api->get('/path', array('param1' => 'param1value'), array('header1' => 'header1value'))); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * @test |
| 32 | + */ |
| 33 | + public function shouldPassPOSTRequestToClient() |
| 34 | + { |
| 35 | + $response = $this->getResponse('value'); |
| 36 | + |
| 37 | + $httpClient = $this->getHttpMock(); |
| 38 | + $httpClient |
| 39 | + ->expects($this->any()) |
| 40 | + ->method('post') |
| 41 | + ->with('/path', array('param1' => 'param1value'), array('header1' => 'header1value')) |
| 42 | + ->will($this->returnValue($response)); |
| 43 | + |
| 44 | + $client = $this->getClientMock(); |
| 45 | + $client->setHttpClient($httpClient); |
| 46 | + |
| 47 | + $api = $this->getAbstractApiObject($client); |
| 48 | + $this->assertEquals('value', $api->post('/path', array('param1' => 'param1value'), array('header1' => 'header1value'))); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @test |
| 53 | + */ |
| 54 | + public function shouldPassPUTRequestToClient() |
| 55 | + { |
| 56 | + $response = $this->getResponse('value'); |
| 57 | + |
| 58 | + $httpClient = $this->getHttpMock(); |
| 59 | + $httpClient |
| 60 | + ->expects($this->any()) |
| 61 | + ->method('put') |
| 62 | + ->with('/path', array('param1' => 'param1value'), array('header1' => 'header1value')) |
| 63 | + ->will($this->returnValue($response)); |
| 64 | + |
| 65 | + $client = $this->getClientMock(); |
| 66 | + $client->setHttpClient($httpClient); |
| 67 | + |
| 68 | + $api = $this->getAbstractApiObject($client); |
| 69 | + $this->assertEquals('value', $api->put('/path', array('param1' => 'param1value'), array('header1' => 'header1value'))); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * @test |
| 74 | + */ |
| 75 | + public function shouldPassDELETERequestToClient() |
| 76 | + { |
| 77 | + $response = $this->getResponse('value'); |
| 78 | + |
| 79 | + $httpClient = $this->getHttpMock(); |
| 80 | + $httpClient |
| 81 | + ->expects($this->any()) |
| 82 | + ->method('delete') |
| 83 | + ->with('/path', array('param1' => 'param1value'), array('header1' => 'header1value')) |
| 84 | + ->will($this->returnValue($response)); |
| 85 | + |
| 86 | + $client = $this->getClientMock(); |
| 87 | + $client->setHttpClient($httpClient); |
| 88 | + |
| 89 | + $api = $this->getAbstractApiObject($client); |
| 90 | + $this->assertEquals('value', $api->delete('/path', array('param1' => 'param1value'), array('header1' => 'header1value'))); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * @test |
| 95 | + */ |
| 96 | + public function shouldPassPATCHRequestToClient() |
| 97 | + { |
| 98 | + $response = $this->getResponse('value'); |
| 99 | + |
| 100 | + $httpClient = $this->getHttpMock(); |
| 101 | + $httpClient |
| 102 | + ->expects($this->any()) |
| 103 | + ->method('patch') |
| 104 | + ->with('/path', array('param1' => 'param1value'), array('header1' => 'header1value')) |
| 105 | + ->will($this->returnValue($response)); |
| 106 | + |
| 107 | + $client = $this->getClientMock(); |
| 108 | + $client->setHttpClient($httpClient); |
| 109 | + |
| 110 | + $api = $this->getAbstractApiObject($client); |
| 111 | + $this->assertEquals('value', $api->patch('/path', array('param1' => 'param1value'), array('header1' => 'header1value'))); |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * @param mixed $value |
| 116 | + * @return Response |
| 117 | + */ |
| 118 | + protected function getResponse($value) |
| 119 | + { |
| 120 | + $response = new Response(); |
| 121 | + $response->setContent($value); |
| 122 | + |
| 123 | + return $response; |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * @param Client $client |
| 128 | + * @return AbstractApiTestInstance |
| 129 | + */ |
| 130 | + protected function getAbstractApiObject(Client $client) |
| 131 | + { |
| 132 | + return new AbstractApiTestInstance($client); |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +class AbstractApiTestInstance extends AbstractApi |
| 137 | +{ |
| 138 | + /** |
| 139 | + * {@inheritDoc} |
| 140 | + */ |
| 141 | + public function get($path, array $parameters = array(), $requestHeaders = array()) |
| 142 | + { |
| 143 | + return parent::get($path, $parameters, $requestHeaders); |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | + * {@inheritDoc} |
| 148 | + */ |
| 149 | + public function post($path, array $parameters = array(), $requestHeaders = array()) |
| 150 | + { |
| 151 | + return parent::post($path, $parameters, $requestHeaders); |
| 152 | + } |
| 153 | + |
| 154 | + /** |
| 155 | + * {@inheritDoc} |
| 156 | + */ |
| 157 | + public function patch($path, array $parameters = array(), $requestHeaders = array()) |
| 158 | + { |
| 159 | + return parent::patch($path, $parameters, $requestHeaders); |
| 160 | + } |
| 161 | + |
| 162 | + /** |
| 163 | + * {@inheritDoc} |
| 164 | + */ |
| 165 | + public function put($path, array $parameters = array(), $requestHeaders = array()) |
| 166 | + { |
| 167 | + return parent::put($path, $parameters, $requestHeaders); |
| 168 | + } |
| 169 | + |
| 170 | + /** |
| 171 | + * {@inheritDoc} |
| 172 | + */ |
| 173 | + public function delete($path, array $parameters = array(), $requestHeaders = array()) |
| 174 | + { |
| 175 | + return parent::delete($path, $parameters, $requestHeaders); |
| 176 | + } |
| 177 | +} |
0 commit comments