コード例 #1
0
 /**
  * Obtiene un cliente de HTTP.
  * @param string $url
  * @param string $username
  * @param string $password
  * @return Client
  */
 public static function buildHttpClient($url = NULL, $username = NULL, $password = NULL, $contentType = self::CONTENT_JSON_API, $language = self::HEADER_LOCALE)
 {
     $client = new Client($url);
     $client->setHead(['Accept: ' . $contentType, 'Accept-Language: ' . $language, 'Content-Type: application/vnd.api+json']);
     if (is_scalar($username) && is_scalar($password)) {
         $client->setOptions([CURLOPT_HTTPAUTH, CURLAUTH_ANY]);
         $client->setOption(CURLOPT_USERPWD, $username . ':' . $password);
     }
     return $client;
 }
コード例 #2
0
 /**
  * Verifica el código de estado de una respuesta HTTP.
  * @param int $expectedCode
  * @param Client $client
  */
 public static function assertResponseStatus($expectedCode, Client $client, $message = '')
 {
     $actualCode = $client->getInfo(CURLINFO_HTTP_CODE);
     $condition = $expectedCode === $actualCode;
     $message .= sprintf(static::FAIL_RESPONSE_STATUS_PATTERN, $actualCode, array_flip(static::$statusCodes)[$actualCode], $expectedCode, array_flip(static::$statusCodes)[$expectedCode]);
     return static::assertThat($condition, static::isTrue(), $message);
 }