Scalr\Tests\Functional\Api\ApiTestCase::assertErrorMessageContains PHP Méthode

assertErrorMessageContains() public méthode

Asserts api error response
public assertErrorMessageContains ( Scalr\Tests\Functional\Api\ApiTestResponse $response, integer $expectedStatus, string $expectedError = null, string $expectedMessage = null )
$response Scalr\Tests\Functional\Api\ApiTestResponse Api response
$expectedStatus integer Expected Status
$expectedError string optional Expected error
$expectedMessage string optional Expected message
    public function assertErrorMessageContains(ApiTestResponse $response, $expectedStatus, $expectedError = null, $expectedMessage = null)
    {
        $body = $response->getBody();
        $this->assertNotEmpty($body);
        $printError = $this->printResponseError($response);
        $this->assertEquals($expectedStatus, $response->response->getStatus(), $printError);
        $this->assertObjectHasAttribute('errors', $body);
        $this->assertNotEmpty($body->errors);
        $error = reset($body->errors);
        if ($expectedError !== null) {
            $this->assertObjectHasAttribute('code', $error);
            $this->assertEquals($expectedError, $error->code, $printError);
        }
        if ($expectedMessage !== null) {
            $this->assertObjectHasAttribute('message', $error);
            $this->assertContains($expectedMessage, $error->message, $printError);
        }
    }