\ApiTestCase

ApiTestCase is the base class for testing all RESTful API controller methods.

Usage:

$response = $this->post(
     'api/login',
     array(
         'username'=>'userName',
         'password'=>'password'
     ),
     array(
         CURLOPT_CRLF=>true,
         'cookies'=>array(
             'giud'=>'value',
             ...
         )
     )
);

Summary

Methods
Properties
Constants
getAuthCookies()
createReport()
get()
post()
put()
delete()
$authCookies
$loginUrl
$loginData
No constants found
No protected methods found
No protected properties found
N/A
request()
_encode()
http_parse_headers()
No private properties found
N/A

Properties

$authCookies

$authCookies : array

Type

array — authenticated cookies

$loginUrl

$loginUrl : string

Type

string — authentication url

$loginData

$loginData : array

Type

array — data which will be sended for authentication.

Methods

getAuthCookies()

getAuthCookies(boolean $reload)

Function authenticates in application and set $authCookies from response;

Parameters

boolean $reload

need to reload cookies and not return from the cache.

createReport()

createReport(mixed $data) : void

Function creates report and save it in report folder

Parameters

mixed $data

data to report

get()

get(string $url, array $params, array $options) : array

Function executes curl request with GET method.

Parameters

string $url

URL

array $params

request GET params

array $options

additional request options

Returns

array —

response

post()

post(string $url, array $params, array $options) : array

Function executes curl request with POST method.

Parameters

string $url

URL

array $params

request parameters

array $options

additional request options

Returns

array —

response

put()

put(string $url, array $params, array $options) : array

Function executes curl request with PUT method.

Parameters

string $url

URL

array $params

request parameters

array $options

additional request options

Returns

array —

response

delete()

delete(string $url, array $params, array $options) : array

Function executes curl request with DELETE method.

Parameters

string $url

URL

array $params

request parameters

array $options

additional request options

Returns

array —

response

request()

request(string $url, array $params, array $options) : array

Function executes curl request

Parameters

string $url

URL

array $params

request parameters

array $options

additional request options

Returns

array —

response

array{
  'body' => "response content",
  'code' => 200,
  'location' => 'http://www.example.org/index.php',
  'cookies' => array(...)
  'headers' => array(...)
}

_encode()

_encode(array $params) : string

Function generate URL-encoded query string from array

Parameters

array $params

query parameters

Returns

string

http_parse_headers()

http_parse_headers(string $header) : array

Function convert HTTP headers to array

Parameters

string $header

Returns

array —

HTTP headers
Example:

array(
  'Date' =>" Tue, 18 Mar 2014 11:50:12 GMT",
  'Server' => "Apache/2.4.7 (Win32) OpenSSL/1.0.1e PHP/5.5.9",
  'X-Powered-By' =>"PHP/5.5.9",
  'Set-Cookie' => array(
        'PHPSESSID' =>array(
          'value' => "ou85gd41ad8rlgme12dps41ki4",
          'path' => "/"
        )
        'guid' => array(
          'value' => "53283b69df9cc8.91971156",
          'expires' => 1397737577,
          'Max-Age' => "2592000",
          'path' => "/",
        )
      ),
  'Expires' => "Thu, 19 Nov 1981 08:52:00 GMT",
  'Cache-Control' =>"no-store, no-cache, must-revalidate, post-check=0, pre-check=0",
  'Pragma' =>"no-cache",
  'Content-Length' =>"204",
  'Content-Type' =>"application/json",
)