$fixtureManager
$fixtureManager : \Cake\TestSuite\Fixture\FixtureManager|null
The class responsible for managing the creation, loading and removing of fixtures
A test case class 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.
$fixtureManager : \Cake\TestSuite\Fixture\FixtureManager|null
The class responsible for managing the creation, loading and removing of fixtures
$_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
$_tableLocator : \Cake\ORM\Locator\LocatorInterface
Table locator instance
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. |
loadFixtures() : void
Chooses which fixtures to load for a given test
Each parameter is a model name that corresponds to a fixture, i.e. 'Posts', 'Authors', etc. Passing no parameters will cause all fixtures on the test case to load.
when no fixture manager is available.
loadPlugins(array $plugins = array()) : \Cake\Http\BaseApplication
Load plugins into a simulated application.
Useful to test how plugins being loaded/not loaded interact with other elements in CakePHP or applications.
array | $plugins | list of Plugins to load |
assertEventFired(string $name, \Cake\Event\EventManager|null $eventManager = null, string $message = '') : void
Asserts that a global event was fired. You must track events in your event manager for this assertion to work
string | $name | Event name |
\Cake\Event\EventManager|null | $eventManager | Event manager to check, defaults to global event manager |
string | $message | Assertion failure message |
assertEventFiredWith(string $name, string $dataKey, string $dataValue, \Cake\Event\EventManager|null $eventManager = null, string $message = '') : void
Asserts an event was fired with data
If a third argument is passed, that value is used to compare with the value in $dataKey
string | $name | Event name |
string | $dataKey | Data key |
string | $dataValue | Data value |
\Cake\Event\EventManager|null | $eventManager | Event manager to check, defaults to global event manager |
string | $message | Assertion failure message |
assertTextNotEquals(string $expected, string $result, string $message = '') : void
Assert text equality, ignoring differences in newlines.
Helpful for doing cross platform tests of blocks of text.
string | $expected | The expected value. |
string | $result | The actual value. |
string | $message | The message to use for failure. |
assertTextEquals(string $expected, string $result, string $message = '') : void
Assert text equality, ignoring differences in newlines.
Helpful for doing cross platform tests of blocks of text.
string | $expected | The expected value. |
string | $result | The actual value. |
string | $message | The message to use for failure. |
assertTextStartsWith(string $prefix, string $string, string $message = '') : void
Asserts that a string starts with a given prefix, ignoring differences in newlines.
Helpful for doing cross platform tests of blocks of text.
string | $prefix | The prefix to check for. |
string | $string | The string to search in. |
string | $message | The message to use for failure. |
assertTextStartsNotWith(string $prefix, string $string, string $message = '') : void
Asserts that a string starts not with a given prefix, ignoring differences in newlines.
Helpful for doing cross platform tests of blocks of text.
string | $prefix | The prefix to not find. |
string | $string | The string to search. |
string | $message | The message to use for failure. |
assertTextEndsWith(string $suffix, string $string, string $message = '') : void
Asserts that a string ends with a given prefix, ignoring differences in newlines.
Helpful for doing cross platform tests of blocks of text.
string | $suffix | The suffix to find. |
string | $string | The string to search. |
string | $message | The message to use for failure. |
assertTextEndsNotWith(string $suffix, string $string, string $message = '') : void
Asserts that a string ends not with a given prefix, ignoring differences in newlines.
Helpful for doing cross platform tests of blocks of text.
string | $suffix | The suffix to not find. |
string | $string | The string to search. |
string | $message | The message to use for failure. |
assertTextContains(string $needle, string $haystack, string $message = '', boolean $ignoreCase = false) : void
Assert that a string contains another string, ignoring differences in newlines.
Helpful for doing cross platform tests of blocks of text.
string | $needle | The string to search for. |
string | $haystack | The string to search through. |
string | $message | The message to display on failure. |
boolean | $ignoreCase | Whether or not the search should be case-sensitive. |
assertTextNotContains(string $needle, string $haystack, string $message = '', boolean $ignoreCase = false) : void
Assert that a text doesn't contain another text, ignoring differences in newlines.
Helpful for doing cross platform tests of blocks of text.
string | $needle | The string to search for. |
string | $haystack | The string to search through. |
string | $message | The message to display on failure. |
boolean | $ignoreCase | Whether or not the search should be case-sensitive. |
assertHtml(array $expected, string $string, boolean $fullDebug = false) : boolean
Asserts HTML tags.
Takes an array $expected and generates a regex from it to match the provided $string. Samples for $expected:
Checks for an input tag with a name attribute (contains any non-empty value) and an id attribute that contains 'my-input':
['input' => ['name', 'id' => 'my-input']]
Checks for two p elements with some text in them:
[
['p' => true],
'textA',
'/p',
['p' => true],
'textB',
'/p'
]
You can also specify a pattern expression as part of the attribute values, or the tag being defined, if you prepend the value with preg: and enclose it with slashes, like so:
[
['input' => ['name', 'id' => 'preg:/FieldName\d+/']],
'preg:/My\s+field/'
]
Important: This function is very forgiving about whitespace and also accepts any permutation of attribute order. It will also allow whitespace between specified tags.
array | $expected | An array, see above |
string | $string | An HTML/XHTML/XML string |
boolean | $fullDebug | Whether or not more verbose output should be used. |
None found |
getMockForModel(string $alias, array|null $methods = array(), array $options = array()) : \Cake\ORM\Table|\PHPUnit_Framework_MockObject_MockObject
Mock a model, maintain fixtures and table association
string | $alias | The model to get a mock for. |
array|null | $methods | The list of methods to mock |
array | $options | The config data for the mock's constructor. |
None found |
setAppNamespace(string $appNamespace = 'TestApp') : void
Set the app namespace
string | $appNamespace | The app namespace, defaults to "TestApp". |
None found |
tableLocator(\Cake\ORM\Locator\LocatorInterface|null $tableLocator = null) : \Cake\ORM\Locator\LocatorInterface
Sets the table locator.
If no parameters are passed, it will return the currently used locator.
\Cake\ORM\Locator\LocatorInterface|null | $tableLocator | LocatorInterface instance. |
None found |
setTableLocator(\Cake\ORM\Locator\LocatorInterface $tableLocator) : $this
Sets the table locator.
\Cake\ORM\Locator\LocatorInterface | $tableLocator | LocatorInterface instance. |
None found |
getTableLocator() : \Cake\ORM\Locator\LocatorInterface
Gets the table locator.
None found |
_getCookieEncryptionKey() : string
Returns the encryption key to be used.
None found |
_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. |
None found |
_makeDispatcher() : \Cake\TestSuite\MiddlewareDispatcher|\Cake\TestSuite\LegacyRequestDispatcher
Get the correct dispatcher instance.
A dispatcher instance
None found |
_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. |
None found |
_buildRequest(string|array $url, string $method, array|null $data) : array
Creates a request object with the configured options and parameters.
string|array | $url | The URL |
string | $method | The HTTP method |
array|null | $data | The request data. |
The request context
None found |
_addTokens(string $url, array $data) : array
Add the CSRF and Security Component tokens if necessary.
string | $url | The URL the form is being submitted on. |
array | $data | The request body data. |
The request body with tokens added.
None found |
_castToString(array $data) : array
Recursively casts all data to string as that is how data would be POSTed in the real world
array | $data | POST data |
None found |
_url(string|array $url) : array
Creates a valid request url and parameter array more like Request::_url()
string|array | $url | The URL |
Qualified URL and the query parameters
None found |
_getBodyAsString() : string
Get the response body as string
The response body.
None found |
extractVerboseMessage(string $message = null) : null|string
Inspect controller to extract possible causes of the failed assertion
string | $message | Original message to use as a base |
None found |
extractExceptionMessage(\Exception $exception) : string
Extract verbose message for existing exception
\Exception | $exception | Exception to extract |
None found |
_assertAttributes(array $assertions, string $string, boolean $fullDebug = false, array|string $regex = '') : string|boolean
Check the attributes as part of an assertTags() check.
array | $assertions | Assertions to run. |
string | $string | The HTML string to check. |
boolean | $fullDebug | Whether or not more verbose output should be used. |
array|string | $regex | Full regexp from |
None found |
_normalizePath(string $path) : string
Normalize a path for comparison.
string | $path | Path separated by "/" slash. |
Normalized path separated by DIRECTORY_SEPARATOR.
None found |
assertWithinRange(float $expected, float $result, float $margin, string $message = '') : void
Compatibility function to test if a value is between an acceptable range.
float | $expected | |
float | $result | |
float | $margin | the rage of acceptation |
string | $message | the text to display if the assertion is not correct |
None found |
assertNotWithinRange(float $expected, float $result, float $margin, string $message = '') : void
Compatibility function to test if a value is not between an acceptable range.
float | $expected | |
float | $result | |
float | $margin | the rage of acceptation |
string | $message | the text to display if the assertion is not correct |
None found |
assertPathEquals(string $expected, string $result, string $message = '') : void
Compatibility function to test paths.
string | $expected | |
string | $result | |
string | $message | the text to display if the assertion is not correct |
None found |
skipUnless(boolean $condition, string $message = '') : boolean
Compatibility function for skipping.
boolean | $condition | Condition to trigger skipping |
string | $message | Message for skip |
None found |
_getTableClassName(string $alias, array $options) : string
Gets the class name for the table.
string | $alias | The model to get a mock for. |
array | $options | The config data for the mock's constructor. |
None found |