|
@@ -39,19 +39,19 @@ class OpentalentApiServiceTest extends UnitTestCase
|
|
|
$this->fixture = new ApiResponseFixtures();
|
|
$this->fixture = new ApiResponseFixtures();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected function injectClientFor($uri, $http_method='GET') {
|
|
|
|
|
|
|
+ protected function injectClientFor($uri, $http_method='GET', $params = []) {
|
|
|
// mock the Guzzle client
|
|
// mock the Guzzle client
|
|
|
$client = $this->prophesize(Client::class);
|
|
$client = $this->prophesize(Client::class);
|
|
|
try {
|
|
try {
|
|
|
$willReturn = $this->fixture->get($uri);
|
|
$willReturn = $this->fixture->get($uri);
|
|
|
- $client->request($http_method, $uri)
|
|
|
|
|
|
|
+ $client->request($http_method, $uri, Argument::any())
|
|
|
->shouldBeCalled()
|
|
->shouldBeCalled()
|
|
|
->willReturn($willReturn);
|
|
->willReturn($willReturn);
|
|
|
|
|
|
|
|
} catch (\RuntimeException $e) {
|
|
} catch (\RuntimeException $e) {
|
|
|
- $client->request($http_method, Argument::type('string'))
|
|
|
|
|
|
|
+ $client->request($http_method, Argument::type('string'), [])
|
|
|
->shouldBeCalled()
|
|
->shouldBeCalled()
|
|
|
- ->willThrow(new \GuzzleHttp\Exception\TransferException('error'));
|
|
|
|
|
|
|
+ ->willThrow(new \GuzzleHttp\Exception\TransferException('bad prophecy request'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$reflectionObject = new \ReflectionObject($this->service);
|
|
$reflectionObject = new \ReflectionObject($this->service);
|
|
@@ -70,12 +70,12 @@ class OpentalentApiServiceTest extends UnitTestCase
|
|
|
public function get() {
|
|
public function get() {
|
|
|
|
|
|
|
|
$base_uri = "api/public/organizations";
|
|
$base_uri = "api/public/organizations";
|
|
|
- $params = ['itemsPerPage' => 10, 'foo' => 1];
|
|
|
|
|
|
|
+ $params = ['_format' => 'json', 'itemsPerPage' => 10, 'foo' => 1];
|
|
|
|
|
|
|
|
// uri as it is supposed to be processed by the repo
|
|
// uri as it is supposed to be processed by the repo
|
|
|
$processed_uri = $base_uri . "?_format=json&itemsPerPage=10&foo=1";
|
|
$processed_uri = $base_uri . "?_format=json&itemsPerPage=10&foo=1";
|
|
|
|
|
|
|
|
- $this->injectClientFor($processed_uri);
|
|
|
|
|
|
|
+ $this->injectClientFor($processed_uri, 'GET', $params);
|
|
|
$actual = $this->service->request('GET', $base_uri, $params);
|
|
$actual = $this->service->request('GET', $base_uri, $params);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $actual->getStatusCode());
|
|
$this->assertEquals(200, $actual->getStatusCode());
|
|
@@ -92,10 +92,7 @@ class OpentalentApiServiceTest extends UnitTestCase
|
|
|
$base_uri = "api/public/organizations";
|
|
$base_uri = "api/public/organizations";
|
|
|
$params = [];
|
|
$params = [];
|
|
|
|
|
|
|
|
- // uri as it is supposed to be processed by the repo
|
|
|
|
|
- $processed_uri = $base_uri . "?_format=json";
|
|
|
|
|
-
|
|
|
|
|
- $this->injectClientFor($processed_uri);
|
|
|
|
|
|
|
+ $this->injectClientFor($base_uri, 'GET', $params);
|
|
|
$actual = $this->service->request('GET', $base_uri, $params);
|
|
$actual = $this->service->request('GET', $base_uri, $params);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $actual->getStatusCode());
|
|
$this->assertEquals(200, $actual->getStatusCode());
|
|
@@ -112,13 +109,13 @@ class OpentalentApiServiceTest extends UnitTestCase
|
|
|
$base_uri = "a very bad uri";
|
|
$base_uri = "a very bad uri";
|
|
|
$params = [];
|
|
$params = [];
|
|
|
|
|
|
|
|
- $this->injectClientFor($base_uri);
|
|
|
|
|
|
|
+ $this->injectClientFor($base_uri, 'GET', $params);
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
$res = $this->service->request('GET', $base_uri, $params);
|
|
$res = $this->service->request('GET', $base_uri, $params);
|
|
|
throw new \AssertionError("An ApiRequestException should have been thrown");
|
|
throw new \AssertionError("An ApiRequestException should have been thrown");
|
|
|
} catch (ApiRequestException $e) {
|
|
} catch (ApiRequestException $e) {
|
|
|
- $this->assertEquals('error', $e->getMessage());
|
|
|
|
|
|
|
+ $this->assertEquals('bad prophecy request', $e->getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -130,12 +127,12 @@ class OpentalentApiServiceTest extends UnitTestCase
|
|
|
public function getBody() {
|
|
public function getBody() {
|
|
|
|
|
|
|
|
$base_uri = "api/public/organizations";
|
|
$base_uri = "api/public/organizations";
|
|
|
- $params = ['itemsPerPage' => 10, 'foo' => 1];
|
|
|
|
|
|
|
+ $params = ['_format' => 'json', 'itemsPerPage' => 10, 'foo' => 1];
|
|
|
|
|
|
|
|
// uri as it is supposed to be processed by the repo
|
|
// uri as it is supposed to be processed by the repo
|
|
|
$processed_uri = $base_uri . "?_format=json&itemsPerPage=10&foo=1";
|
|
$processed_uri = $base_uri . "?_format=json&itemsPerPage=10&foo=1";
|
|
|
|
|
|
|
|
- $this->injectClientFor($processed_uri);
|
|
|
|
|
|
|
+ $this->injectClientFor($processed_uri, 'GET', $params);
|
|
|
$actual = $this->service->getBody($base_uri, $params);
|
|
$actual = $this->service->getBody($base_uri, $params);
|
|
|
|
|
|
|
|
$this->assertEquals('{"@context": "/api/contexts/PortailOrganization"}', $actual);
|
|
$this->assertEquals('{"@context": "/api/contexts/PortailOrganization"}', $actual);
|
|
@@ -149,12 +146,12 @@ class OpentalentApiServiceTest extends UnitTestCase
|
|
|
public function getJsonDecoded() {
|
|
public function getJsonDecoded() {
|
|
|
|
|
|
|
|
$base_uri = "api/public/organizations";
|
|
$base_uri = "api/public/organizations";
|
|
|
- $params = ['itemsPerPage' => 10, 'foo' => 1];
|
|
|
|
|
|
|
+ $params = ['_format' => 'json', 'itemsPerPage' => 10, 'foo' => 1];
|
|
|
|
|
|
|
|
// uri as it is supposed to be processed by the repo
|
|
// uri as it is supposed to be processed by the repo
|
|
|
$processed_uri = $base_uri . "?_format=json&itemsPerPage=10&foo=1";
|
|
$processed_uri = $base_uri . "?_format=json&itemsPerPage=10&foo=1";
|
|
|
|
|
|
|
|
- $this->injectClientFor($processed_uri);
|
|
|
|
|
|
|
+ $this->injectClientFor($processed_uri, 'GET', $params);
|
|
|
$actual = $this->service->getJsonDecoded($base_uri, $params);
|
|
$actual = $this->service->getJsonDecoded($base_uri, $params);
|
|
|
|
|
|
|
|
$this->assertEquals(["@context" => "/api/contexts/PortailOrganization"], $actual);
|
|
$this->assertEquals(["@context" => "/api/contexts/PortailOrganization"], $actual);
|