\Cake\TestSuiteIntegrationTestCase

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.

Summary

Methods
Properties
Constants
setupServer()
cleanup()
useHttpServer()
configApplication()
enableSecurityToken()
enableCsrfToken()
enableRetainFlashMessages()
configRequest()
session()
cookie()
cookieEncrypted()
get()
post()
patch()
put()
delete()
head()
options()
controllerSpy()
viewVariable()
assertResponseOk()
assertResponseSuccess()
assertResponseError()
assertResponseFailure()
assertResponseCode()
assertRedirect()
assertRedirectContains()
assertRedirectNotContains()
assertNoRedirect()
assertHeader()
assertHeaderContains()
assertHeaderNotContains()
assertContentType()
assertResponseEquals()
assertResponseNotEquals()
assertResponseContains()
assertResponseNotContains()
assertResponseRegExp()
assertResponseNotRegExp()
assertResponseNotEmpty()
assertResponseEmpty()
assertTemplate()
assertLayout()
assertSession()
assertFlashMessage()
assertFlashMessageAt()
assertFlashElement()
assertFlashElementAt()
assertCookie()
assertCookieNotSet()
disableErrorHandlerMiddleware()
assertCookieEncrypted()
assertFileResponse()
skipIf()
withErrorReporting()
deprecated()
setUp()
tearDown()
loadFixtures()
loadPlugins()
removePlugins()
clearPlugins()
assertEventFired()
assertEventFiredWith()
assertTextNotEquals()
assertTextEquals()
assertTextStartsWith()
assertTextStartsNotWith()
assertTextEndsWith()
assertTextEndsNotWith()
assertTextContains()
assertTextNotContains()
assertTags()
assertHtml()
getMockForModel()
setAppNamespace()
tableLocator()
setTableLocator()
getTableLocator()
$fixtureManager
$autoFixtures
$dropTables
No constants found
_getCookieEncryptionKey()
_sendRequest()
_makeDispatcher()
_handleError()
_buildRequest()
_addTokens()
_castToString()
_url()
_getBodyAsString()
extractVerboseMessage()
extractExceptionMessage()
_assertAttributes()
_normalizePath()
assertWithinRange()
assertNotWithinRange()
assertPathEquals()
skipUnless()
_getTableClassName()
$_useHttpServer
$_appClass
$_appArgs
$_request
$_response
$_exception
$_session
$_cookie
$_controller
$_viewName
$_layoutName
$_requestSession
$_securityToken
$_csrfToken
$_retainFlashMessages
$_flashMessages
$_cookieEncryptionKey
$_configure
$_pathRestore
$_tableLocator
N/A
No private methods found
No private properties found
N/A

Properties

$fixtureManager

$fixtureManager : \Cake\TestSuite\Fixture\FixtureManager|null

The class responsible for managing the creation, loading and removing of fixtures

Type

\Cake\TestSuite\Fixture\FixtureManager|null

$autoFixtures

$autoFixtures : boolean

By default, all fixtures attached to this class will be truncated and reloaded after each test.

Set this to false to handle manually

Type

boolean

$dropTables

$dropTables : boolean

Control table create/drops on each test method.

If true, tables will still be dropped at the end of each test runner execution.

Type

boolean

$_useHttpServer

$_useHttpServer : boolean

Track whether or not tests are run against the PSR7 HTTP stack.

Type

boolean

$_appClass

$_appClass : string|null

The customized application class name.

Type

string|null

$_appArgs

$_appArgs : array|null

The customized application constructor arguments.

Type

array|null

$_request

$_request : array

The data used to build the next request.

Type

array

$_response

$_response : \Cake\Http\Response|null

The response for the most recent request.

Type

\Cake\Http\Response|null

$_exception

$_exception : \Exception|null

The exception being thrown if the case.

Type

\Exception|null

$_session

$_session : array

Session data to use in the next request.

Type

array

$_cookie

$_cookie : array

Cookie data to use in the next request.

Type

array

$_controller

$_controller : \Cake\Controller\Controller|null

The controller used in the last request.

Type

\Cake\Controller\Controller|null

$_viewName

$_viewName : string|null

The last rendered view

Type

string|null

$_layoutName

$_layoutName : string|null

The last rendered layout

Type

string|null

$_requestSession

$_requestSession : \Cake\Http\Session|null

The session instance from the last request

Type

\Cake\Http\Session|null

$_securityToken

$_securityToken : boolean

Boolean flag for whether or not the request should have a SecurityComponent token added.

Type

boolean

$_csrfToken

$_csrfToken : boolean

Boolean flag for whether or not the request should have a CSRF token added.

Type

boolean

$_retainFlashMessages

$_retainFlashMessages : boolean

Boolean flag for whether or not the request should re-store flash messages

Type

boolean

$_flashMessages

$_flashMessages : null|array

Stored flash messages before render

Type

null|array

$_cookieEncryptionKey

$_cookieEncryptionKey : null|string

Type

null|string

$_configure

$_configure : array

Configure values to restore at end of test.

Type

array

$_pathRestore

$_pathRestore : array

Path settings to restore at the end of the test.

Type

array

Methods

setupServer()

setupServer() : void

Auto-detect if the HTTP middleware stack should be used.

cleanup()

cleanup() : void

Clears the state used for requests.

useHttpServer()

useHttpServer(boolean  $enable) : void

Toggle whether or not you want to use the HTTP Server stack.

Parameters

boolean $enable

Enable/disable the usage of the HTTP Stack.

configApplication()

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.

Parameters

string $class

The application class name.

array|null $constructorArgs

The constructor arguments for your application class.

enableSecurityToken()

enableSecurityToken() : void

Calling this method will enable a SecurityComponent compatible token to be added to request data. This lets you easily test actions protected by SecurityComponent.

enableCsrfToken()

enableCsrfToken() : void

Calling this method will add a CSRF token to the request.

Both the POST data and cookie will be populated when this option is enabled. The default parameter names will be used.

enableRetainFlashMessages()

enableRetainFlashMessages() : void

Calling this method will re-store flash messages into the test session after being removed by the FlashHelper

configRequest()

configRequest(array  $data) : void

Configures the data for the *next* request.

This data is cleared in the tearDown() method.

You can call this method multiple times to append into the current state.

Parameters

array $data

The request data to use.

session()

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.

Parameters

array $data

The session data to use.

cookie()

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.

Parameters

string $name

The cookie name to use.

mixed $value

The value of the cookie.

cookieEncrypted()

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.

Parameters

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.

get()

get(string|array  $url) : void

Performs a GET 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.

Parameters

string|array $url

The URL to request.

Throws

\PHPUnit\Exception

post()

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.

Parameters

string|array $url

The URL to request.

array $data

The data for the request.

Throws

\PHPUnit\Exception

patch()

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.

Parameters

string|array $url

The URL to request.

array $data

The data for the request.

Throws

\PHPUnit\Exception

put()

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.

Parameters

string|array $url

The URL to request.

array $data

The data for the request.

Throws

\PHPUnit\Exception

delete()

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.

Parameters

string|array $url

The URL to request.

Throws

\PHPUnit\Exception

head()

head(string|array  $url) : void

Performs a HEAD 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.

Parameters

string|array $url

The URL to request.

Throws

\PHPUnit\Exception

options()

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.

Parameters

string|array $url

The URL to request.

Throws

\PHPUnit\Exception

controllerSpy()

controllerSpy(\Cake\Event\Event  $event, \Cake\Controller\Controller|null  $controller = null) : void

Adds additional event spies to the controller/view event manager.

Parameters

\Cake\Event\Event $event

A dispatcher event.

\Cake\Controller\Controller|null $controller

Controller instance.

viewVariable()

viewVariable(string  $name) : mixed

Fetches a view variable by name.

If the view variable does not exist, null will be returned.

Parameters

string $name

The view variable to get.

Returns

mixed —

The view variable if set.

assertResponseOk()

assertResponseOk(string  $message = null) : void

Asserts that the response status code is in the 2xx range.

Parameters

string $message

Custom message for failure.

assertResponseSuccess()

assertResponseSuccess(string  $message = null) : void

Asserts that the response status code is in the 2xx/3xx range.

Parameters

string $message

Custom message for failure.

assertResponseError()

assertResponseError(string  $message = null) : void

Asserts that the response status code is in the 4xx range.

Parameters

string $message

Custom message for failure.

assertResponseFailure()

assertResponseFailure(string  $message = null) : void

Asserts that the response status code is in the 5xx range.

Parameters

string $message

Custom message for failure.

assertResponseCode()

assertResponseCode(integer  $code, string  $message = null) : void

Asserts a specific response status code.

Parameters

integer $code

Status code to assert.

string $message

Custom message for failure.

assertRedirect()

assertRedirect(string|array|null  $url = null, string  $message = '') : void

Asserts that the Location header is correct.

Parameters

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.

assertRedirectContains()

assertRedirectContains(string  $url, string  $message = '') : void

Asserts that the Location header contains a substring

Parameters

string $url

The URL you expected the client to go to.

string $message

The failure message that will be appended to the generated message.

assertRedirectNotContains()

assertRedirectNotContains(string  $url, string  $message = '') : void

Asserts that the Location header does not contain a substring

Parameters

string $url

The URL you expected the client to go to.

string $message

The failure message that will be appended to the generated message.

assertNoRedirect()

assertNoRedirect(string  $message = '') : void

Asserts that the Location header is not set.

Parameters

string $message

The failure message that will be appended to the generated message.

assertHeader()

assertHeader(string  $header, string  $content, string  $message = '') : void

Asserts response headers

Parameters

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.

assertHeaderContains()

assertHeaderContains(string  $header, string  $content, string  $message = '') : void

Asserts response header contains a string

Parameters

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()

assertHeaderNotContains(string  $header, string  $content, string  $message = '') : void

Asserts response header does not contain a string

Parameters

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.

assertContentType()

assertContentType(string  $type, string  $message = '') : void

Asserts content type

Parameters

string $type

The content-type to check for.

string $message

The failure message that will be appended to the generated message.

assertResponseEquals()

assertResponseEquals(mixed  $content, string  $message = '') : void

Asserts content in the response body equals.

Parameters

mixed $content

The content to check for.

string $message

The failure message that will be appended to the generated message.

assertResponseNotEquals()

assertResponseNotEquals(mixed  $content, string  $message = '') : void

Asserts content in the response body not equals.

Parameters

mixed $content

The content to check for.

string $message

The failure message that will be appended to the generated message.

assertResponseContains()

assertResponseContains(string  $content, string  $message = '', boolean  $ignoreCase = false) : void

Asserts content exists in the response body.

Parameters

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()

assertResponseNotContains(string  $content, string  $message = '', boolean  $ignoreCase = false) : void

Asserts content does not exist in the response body.

Parameters

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.

assertResponseRegExp()

assertResponseRegExp(string  $pattern, string  $message = '') : void

Asserts that the response body matches a given regular expression.

Parameters

string $pattern

The pattern to compare against.

string $message

The failure message that will be appended to the generated message.

assertResponseNotRegExp()

assertResponseNotRegExp(string  $pattern, string  $message = '') : void

Asserts that the response body does not match a given regular expression.

Parameters

string $pattern

The pattern to compare against.

string $message

The failure message that will be appended to the generated message.

assertResponseNotEmpty()

assertResponseNotEmpty(string  $message = '') : void

Assert response content is not empty.

Parameters

string $message

The failure message that will be appended to the generated message.

assertResponseEmpty()

assertResponseEmpty(string  $message = '') : void

Assert response content is empty.

Parameters

string $message

The failure message that will be appended to the generated message.

assertTemplate()

assertTemplate(string  $content, string  $message = '') : void

Asserts that the search string was in the template name.

Parameters

string $content

The content to check for.

string $message

The failure message that will be appended to the generated message.

assertLayout()

assertLayout(string  $content, string  $message = '') : void

Asserts that the search string was in the layout name.

Parameters

string $content

The content to check for.

string $message

The failure message that will be appended to the generated message.

assertSession()

assertSession(string  $expected, string  $path, string  $message = '') : void

Asserts session contents

Parameters

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.

assertFlashMessage()

assertFlashMessage(string  $expected, string  $key = 'flash', string  $message = '') : void

Asserts a flash message was set

Parameters

string $expected

Expected message

string $key

Flash key

string $message

Assertion failure message

assertFlashMessageAt()

assertFlashMessageAt(integer  $at, string  $expected, string  $key = 'flash', string  $message = '') : void

Asserts a flash message was set at a certain index

Parameters

integer $at

Flash index

string $expected

Expected message

string $key

Flash key

string $message

Assertion failure message

assertFlashElement()

assertFlashElement(string  $expected, string  $key = 'flash', string  $message = '') : void

Asserts a flash element was set

Parameters

string $expected

Expected element name

string $key

Flash key

string $message

Assertion failure message

assertFlashElementAt()

assertFlashElementAt(integer  $at, string  $expected, string  $key = 'flash', string  $message = '') : void

Asserts a flash element was set at a certain index

Parameters

integer $at

Flash index

string $expected

Expected element name

string $key

Flash key

string $message

Assertion failure message

assertCookie()

assertCookie(string  $expected, string  $name, string  $message = '') : void

Asserts cookie values

Parameters

string $expected

The expected contents.

string $name

The cookie name.

string $message

The failure message that will be appended to the generated message.

assertCookieNotSet()

assertCookieNotSet(string  $cookie, string  $message = '') : void

Asserts a cookie has not been set in the response

Parameters

string $cookie

The cookie name to check

string $message

The failure message that will be appended to the generated message.

disableErrorHandlerMiddleware()

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()

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.

Parameters

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()

assertFileResponse(string  $expected, string  $message = '') : void

Asserts that a file with the given name was sent in the response

Parameters

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.

skipIf()

skipIf(boolean  $shouldSkip, string  $message = '') : boolean

Overrides SimpleTestCase::skipIf to provide a boolean return value

Parameters

boolean $shouldSkip

Whether or not the test should be skipped.

string $message

The message to display.

Returns

boolean

withErrorReporting()

withErrorReporting(integer  $errorLevel, callable  $callable) : void

Helper method for tests that needs to use error_reporting()

Parameters

integer $errorLevel

value of error_reporting() that needs to use

callable $callable

callable function that will receive asserts

deprecated()

deprecated(callable  $callable) : void

Helper method for check deprecation methods

Parameters

callable $callable

callable function that will receive asserts

setUp()

setUp() : void

Setup the test case, backup the static object values so they can be restored.

Specifically backs up the contents of Configure and paths in App if they have not already been backed up.

tearDown()

tearDown() : void

teardown any static object changes and restore them.

loadFixtures()

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.

Throws

\Exception

when no fixture manager is available.

loadPlugins()

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.

Parameters

array $plugins

list of Plugins to load

Returns

\Cake\Http\BaseApplication

removePlugins()

removePlugins(array  $plugins = array()) : void

Remove plugins from the global plugin collection.

Useful in test case teardown methods.

Parameters

array $plugins

A list of plugins you want to remove.

clearPlugins()

clearPlugins() : void

Clear all plugins from the global plugin collection.

Useful in test case teardown methods.

assertEventFired()

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

Parameters

string $name

Event name

\Cake\Event\EventManager|null $eventManager

Event manager to check, defaults to global event manager

string $message

Assertion failure message

assertEventFiredWith()

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

Parameters

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()

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.

Parameters

string $expected

The expected value.

string $result

The actual value.

string $message

The message to use for failure.

assertTextEquals()

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.

Parameters

string $expected

The expected value.

string $result

The actual value.

string $message

The message to use for failure.

assertTextStartsWith()

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.

Parameters

string $prefix

The prefix to check for.

string $string

The string to search in.

string $message

The message to use for failure.

assertTextStartsNotWith()

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.

Parameters

string $prefix

The prefix to not find.

string $string

The string to search.

string $message

The message to use for failure.

assertTextEndsWith()

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.

Parameters

string $suffix

The suffix to find.

string $string

The string to search.

string $message

The message to use for failure.

assertTextEndsNotWith()

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.

Parameters

string $suffix

The suffix to not find.

string $string

The string to search.

string $message

The message to use for failure.

assertTextContains()

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.

Parameters

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()

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.

Parameters

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.

assertTags()

assertTags(string  $string, array  $expected, boolean  $fullDebug = false) : void

Asserts HTML tags.

Parameters

string $string

An HTML/XHTML/XML string

array $expected

An array, see above

boolean $fullDebug

Whether or not more verbose output should be used.

assertHtml()

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.

Parameters

array $expected

An array, see above

string $string

An HTML/XHTML/XML string

boolean $fullDebug

Whether or not more verbose output should be used.

Returns

boolean

getMockForModel()

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

Parameters

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.

Throws

\Cake\ORM\Exception\MissingTableClassException

Returns

\Cake\ORM\Table|\PHPUnit_Framework_MockObject_MockObject

setAppNamespace()

setAppNamespace(string  $appNamespace = 'TestApp') : void

Set the app namespace

Parameters

string $appNamespace

The app namespace, defaults to "TestApp".

tableLocator()

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.

Parameters

\Cake\ORM\Locator\LocatorInterface|null $tableLocator

LocatorInterface instance.

Returns

\Cake\ORM\Locator\LocatorInterface

setTableLocator()

setTableLocator(\Cake\ORM\Locator\LocatorInterface  $tableLocator) : $this

Sets the table locator.

Parameters

\Cake\ORM\Locator\LocatorInterface $tableLocator

LocatorInterface instance.

Returns

$this

_getCookieEncryptionKey()

_getCookieEncryptionKey() : string

Returns the encryption key to be used.

Returns

string

_sendRequest()

_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.

Parameters

string|array $url

The URL

string $method

The HTTP method

array|null $data

The request data.

Throws

\PHPUnit\Exception

_handleError()

_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.

Parameters

\Exception $exception

Exception to handle.

Throws

\Exception

_buildRequest()

_buildRequest(string|array  $url, string  $method, array|null  $data) : array

Creates a request object with the configured options and parameters.

Parameters

string|array $url

The URL

string $method

The HTTP method

array|null $data

The request data.

Returns

array —

The request context

_addTokens()

_addTokens(string  $url, array  $data) : array

Add the CSRF and Security Component tokens if necessary.

Parameters

string $url

The URL the form is being submitted on.

array $data

The request body data.

Returns

array —

The request body with tokens added.

_castToString()

_castToString(array  $data) : array

Recursively casts all data to string as that is how data would be POSTed in the real world

Parameters

array $data

POST data

Returns

array

_url()

_url(string|array  $url) : array

Creates a valid request url and parameter array more like Request::_url()

Parameters

string|array $url

The URL

Returns

array —

Qualified URL and the query parameters

_getBodyAsString()

_getBodyAsString() : string

Get the response body as string

Returns

string —

The response body.

extractVerboseMessage()

extractVerboseMessage(string  $message = null) : null|string

Inspect controller to extract possible causes of the failed assertion

Parameters

string $message

Original message to use as a base

Returns

null|string

extractExceptionMessage()

extractExceptionMessage(\Exception  $exception) : string

Extract verbose message for existing exception

Parameters

\Exception $exception

Exception to extract

Returns

string

_assertAttributes()

_assertAttributes(array  $assertions, string  $string, boolean  $fullDebug = false, array|string  $regex = '') : string|boolean

Check the attributes as part of an assertTags() check.

Parameters

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 assertHtml

Returns

string|boolean

_normalizePath()

_normalizePath(string  $path) : string

Normalize a path for comparison.

Parameters

string $path

Path separated by "/" slash.

Returns

string —

Normalized path separated by DIRECTORY_SEPARATOR.

assertWithinRange()

assertWithinRange(float  $expected, float  $result, float  $margin, string  $message = '') : void

Compatibility function to test if a value is between an acceptable range.

Parameters

float $expected
float $result
float $margin

the rage of acceptation

string $message

the text to display if the assertion is not correct

assertNotWithinRange()

assertNotWithinRange(float  $expected, float  $result, float  $margin, string  $message = '') : void

Compatibility function to test if a value is not between an acceptable range.

Parameters

float $expected
float $result
float $margin

the rage of acceptation

string $message

the text to display if the assertion is not correct

assertPathEquals()

assertPathEquals(string  $expected, string  $result, string  $message = '') : void

Compatibility function to test paths.

Parameters

string $expected
string $result
string $message

the text to display if the assertion is not correct

skipUnless()

skipUnless(boolean  $condition, string  $message = '') : boolean

Compatibility function for skipping.

Parameters

boolean $condition

Condition to trigger skipping

string $message

Message for skip

Returns

boolean

_getTableClassName()

_getTableClassName(string  $alias, array  $options) : string

Gets the class name for the table.

Parameters

string $alias

The model to get a mock for.

array $options

The config data for the mock's constructor.

Throws

\Cake\ORM\Exception\MissingTableClassException

Returns

string