$_useHttpServer
$_useHttpServer : boolean
Track whether or not tests are run against the PSR7 HTTP stack.
A trait intended to make integration tests of your controllers easier.
This test class provides a number of helper methods and features that make dispatching requests and checking their responses simpler. It favours full integration tests over mock objects as you can test more of your code easily and avoid some of the maintenance pitfalls that mock objects create.
$_response : \Cake\Http\Response|null
The response for the most recent request.
$_controller : \Cake\Controller\Controller|null
The controller used in the last request.
$_requestSession : \Cake\Http\Session|null
The session instance from the last request
configApplication(string $class, array|null $constructorArgs) : void
Configure the application class to use in integration tests.
Combined with useHttpServer()
to customize the class name and constructor arguments
of your application class.
string | $class | The application class name. |
array|null | $constructorArgs | The constructor arguments for your application class. |
session(array $data) : void
Sets session data.
This method lets you configure the session data you want to be used for requests that follow. The session state is reset in each tearDown().
You can call this method multiple times to append into the current state.
array | $data | The session data to use. |
cookie(string $name, mixed $value) : void
Sets a request cookie for future requests.
This method lets you configure the session data you want to be used for requests that follow. The session state is reset in each tearDown().
You can call this method multiple times to append into the current state.
string | $name | The cookie name to use. |
mixed | $value | The value of the cookie. |
cookieEncrypted(string $name, mixed $value, string|boolean $encrypt = 'aes', string|null $key = null) : void
Sets a encrypted request cookie for future requests.
The difference from cookie() is this encrypts the cookie value like the CookieComponent.
string | $name | The cookie name to use. |
mixed | $value | The value of the cookie. |
string|boolean | $encrypt | Encryption mode to use. |
string|null | $key | Encryption key used. Defaults to Security.salt. |
post(string|array $url, array $data = array()) : void
Performs a POST request using the current request data.
The response of the dispatched request will be stored as a property. You can use various assert methods to check the response.
string|array | $url | The URL to request. |
array | $data | The data for the request. |
patch(string|array $url, array $data = array()) : void
Performs a PATCH request using the current request data.
The response of the dispatched request will be stored as a property. You can use various assert methods to check the response.
string|array | $url | The URL to request. |
array | $data | The data for the request. |
put(string|array $url, array $data = array()) : void
Performs a PUT request using the current request data.
The response of the dispatched request will be stored as a property. You can use various assert methods to check the response.
string|array | $url | The URL to request. |
array | $data | The data for the request. |
delete(string|array $url) : void
Performs a DELETE request using the current request data.
The response of the dispatched request will be stored as a property. You can use various assert methods to check the response.
string|array | $url | The URL to request. |
options(string|array $url) : void
Performs an OPTIONS request using the current request data.
The response of the dispatched request will be stored as a property. You can use various assert methods to check the response.
string|array | $url | The URL to request. |
controllerSpy(\Cake\Event\Event $event, \Cake\Controller\Controller|null $controller = null) : void
Adds additional event spies to the controller/view event manager.
\Cake\Event\Event | $event | A dispatcher event. |
\Cake\Controller\Controller|null | $controller | Controller instance. |
assertRedirect(string|array|null $url = null, string $message = '') : void
Asserts that the Location header is correct.
string|array|null | $url | The URL you expected the client to go to. This can either be a string URL or an array compatible with Router::url(). Use null to simply check for the existence of this header. |
string | $message | The failure message that will be appended to the generated message. |
assertRedirectNotContains(string $url, string $message = '') : void
Asserts that the Location header does not contain a substring
string | $url | The URL you expected the client to go to. |
string | $message | The failure message that will be appended to the generated message. |
assertHeaderContains(string $header, string $content, string $message = '') : void
Asserts response header contains a string
string | $header | The header to check |
string | $content | The content to check for. |
string | $message | The failure message that will be appended to the generated message. |
assertHeaderNotContains(string $header, string $content, string $message = '') : void
Asserts response header does not contain a string
string | $header | The header to check |
string | $content | The content to check for. |
string | $message | The failure message that will be appended to the generated message. |
assertResponseContains(string $content, string $message = '', boolean $ignoreCase = false) : void
Asserts content exists in the response body.
string | $content | The content to check for. |
string | $message | The failure message that will be appended to the generated message. |
boolean | $ignoreCase | A flag to check whether we should ignore case or not. |
assertResponseNotContains(string $content, string $message = '', boolean $ignoreCase = false) : void
Asserts content does not exist in the response body.
string | $content | The content to check for. |
string | $message | The failure message that will be appended to the generated message. |
boolean | $ignoreCase | A flag to check whether we should ignore case or not. |
assertResponseNotRegExp(string $pattern, string $message = '') : void
Asserts that the response body does not match a given regular expression.
string | $pattern | The pattern to compare against. |
string | $message | The failure message that will be appended to the generated message. |
assertSession(string $expected, string $path, string $message = '') : void
Asserts session contents
string | $expected | The expected contents. |
string | $path | The session data path. Uses Hash::get() compatible notation |
string | $message | The failure message that will be appended to the generated message. |
assertFlashMessageAt(integer $at, string $expected, string $key = 'flash', string $message = '') : void
Asserts a flash message was set at a certain index
integer | $at | Flash index |
string | $expected | Expected message |
string | $key | Flash key |
string | $message | Assertion failure message |
assertFlashElementAt(integer $at, string $expected, string $key = 'flash', string $message = '') : void
Asserts a flash element was set at a certain index
integer | $at | Flash index |
string | $expected | Expected element name |
string | $key | Flash key |
string | $message | Assertion failure message |
disableErrorHandlerMiddleware() : void
Disable the error handler middleware.
By using this function, exceptions are no longer caught by the ErrorHandlerMiddleware and are instead re-thrown by the TestExceptionRenderer. This can be helpful when trying to diagnose/debug unexpected failures in test cases.
assertCookieEncrypted(string $expected, string $name, string|boolean $encrypt = 'aes', string|null $key = null, string $message = '') : void
Asserts cookie values which are encrypted by the CookieComponent.
The difference from assertCookie() is this decrypts the cookie value like the CookieComponent for this assertion.
string | $expected | The expected contents. |
string | $name | The cookie name. |
string|boolean | $encrypt | Encryption mode to use. |
string|null | $key | Encryption key used. Defaults to Security.salt. |
string | $message | The failure message that will be appended to the generated message. |
assertFileResponse(string $expected, string $message = '') : void
Asserts that a file with the given name was sent in the response
string | $expected | The file name that should be sent in the response |
string | $message | The failure message that will be appended to the generated message. |
_sendRequest(string|array $url, string $method, array|null $data = array()) : void
Creates and send the request into a Dispatcher instance.
Receives and stores the response for future inspection.
string|array | $url | The URL |
string | $method | The HTTP method |
array|null | $data | The request data. |
_makeDispatcher() : \Cake\TestSuite\MiddlewareDispatcher|\Cake\TestSuite\LegacyRequestDispatcher
Get the correct dispatcher instance.
A dispatcher instance
_handleError(\Exception $exception) : void
Attempts to render an error response for a given exception.
This method will attempt to use the configured exception renderer. If that class does not exist, the built-in renderer will be used.
\Exception | $exception | Exception to handle. |