/** * @param $id * @return array */ private function getMessageById($id) { $response = $this->getClient()->get(sprintf("/messages/%s.json", $id)); $responseString = (string) $response->getBody()->getContents(); Assertions::assertJson($responseString); return json_decode($responseString, true); }
/** * @When I login using password grant with :username :password */ public function iLoginUsingPasswordGrantWith($username, $password) { // We need to reset the headers to be able to login correctly $this->IamUnauthorized(); $this->getClient()->postWithFormData('/oauth/token', ['grant_type' => 'password', 'username' => $username, 'password' => $password]); $responseBody = $this->getClient()->lastResponseBody; Assertions::assertJson($responseBody); $response = json_decode($responseBody, true); Assertions::assertArrayHasKey('access_token', $response); $this->setAuthorizationBearerHeader($response['access_token']); }
/** * @Then /^it should match the following properties:$/ */ public function itShouldMatchTheFollowingProperties(TableNode $table) { $jsonString = $this->getClient()->lastResponseBody; Assertions::assertJson($jsonString); $json = json_decode($jsonString, true); foreach ($table->getRows() as list($key, $value)) { // So we can detect checks for null values $value = $value === 'null' ? null : $value; Assertions::assertArrayHasKey($key, $json); if (is_bool($json[$key])) { Assertions::assertEquals((bool) $value, $json[$key]); } else { Assertions::assertEquals($value, $json[$key]); } } }