Пример #1
0
 /**
  * @param Response $response
  * @param integer  $statusCode
  * @param string   $entityName
  * @param string   $requestType
  */
 protected function assertApiResponseStatusCodeEquals(Response $response, $statusCode, $entityName, $requestType)
 {
     try {
         $this->assertResponseStatusCodeEquals($response, $statusCode);
     } catch (\PHPUnit_Framework_ExpectationFailedException $e) {
         $e = new \PHPUnit_Framework_ExpectationFailedException(sprintf('Wrong %s response for "%s" request for entity: "%s". Error message: %s', $statusCode, $requestType, $entityName, $e->getMessage()), $e->getComparisonFailure());
         throw $e;
     }
 }
Пример #2
0
 /**
  * Assert response status code equals
  *
  * @param Response $response
  * @param int      $statusCode
  */
 public static function assertResponseStatusCodeEquals(Response $response, $statusCode)
 {
     try {
         \PHPUnit_Framework_TestCase::assertEquals($statusCode, $response->getStatusCode());
     } catch (\PHPUnit_Framework_ExpectationFailedException $e) {
         if ($statusCode < 400 && $response->getStatusCode() >= 400 && $response->headers->contains('Content-Type', 'application/json')) {
             $content = self::jsonToArray($response->getContent());
             if (!empty($content['message'])) {
                 $errors = null;
                 if (!empty($content['errors'])) {
                     $errors = is_array($content['errors']) ? json_encode($content['errors']) : $content['errors'];
                 }
                 $e = new \PHPUnit_Framework_ExpectationFailedException($e->getMessage() . ' Error message: ' . $content['message'] . ($errors ? '. Errors: ' . $errors : ''), $e->getComparisonFailure());
             }
         }
         throw $e;
     }
 }
Пример #3
0
 /**
  * @param \PHPUnit_Framework_ExpectationFailedException $e
  * @param $state
  *
  * @throws \Exception
  */
 private function throwException(\PHPUnit_Framework_ExpectationFailedException $e, $state)
 {
     throw new \PHPUnit_Framework_ExpectationFailedException(sprintf("Invalid state on %s:\r\n\r\n%s", $state, $e->getMessage()), $e->getComparisonFailure(), $e->getPrevious());
 }