CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.1 Red Velvet API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 3.1
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
      • Fixture
      • Stub
    • Utility
    • Validation
    • View

Class IntegrationTestCase

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.

Abstract
Namespace: Cake\TestSuite

Property Summary

  • $_configure protected
    array

    Configure values to restore at end of test.

  • $_controller protected
    Cake\Controller\Controller

    The controller used in the last request.

  • $_cookie protected
    array

    Cookie data to use in the next request.

  • $_cookieEncriptionKey protected
    null|string
  • $_csrfToken protected
    bool

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

  • $_exception protected
    Cake\Core\Exception\Exception

    The exception being thrown if the case.

  • $_layoutName protected
    string

    The last rendered layout

  • $_pathRestore protected
    array

    Path settings to restore at the end of the test.

  • $_request protected
    array

    The data used to build the next request.

  • $_requestSession protected
    Cake\Network\Session

    The session instance from the last request

  • $_response protected
    Cake\Network\Response

    The response for the most recent request.

  • $_securityToken protected
    bool

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

  • $_session protected
    array

    Session data to use in the next request.

  • $_validCiphers protected
    array

    Valid cipher names for encrypted cookies.

  • $_viewName protected
    string

    The last rendered view

  • $autoFixtures public
    array

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

  • $dropTables public
    bool

    Control table create/drops on each test method.

  • $fixtureManager public
    Cake\TestSuite\Fixture\FixtureManager

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

Method Summary

  • _addTokens() protected

    Add the CSRF and Security Component tokens if necessary.

  • _assertAttributes() protected

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

  • _assertStatus() protected

    Helper method for status assertions.

  • _buildFieldToken() protected

    Generate the token data for the provided inputs.

  • _buildRequest() protected

    Creates a request object with the configured options and parameters.

  • _checkCipher() protected

    Helper method for validating encryption cipher names.

  • _decode() protected

    Decodes and decrypts a single value.

  • _decrypt() protected

    Decrypts $value using public $type method in Security class

  • _encrypt() protected

    Encrypts $value using public $type method in Security class

  • _explode() protected

    Explode method to return array from string set in CookieComponent::_implode() Maintains reading backwards compatibility with 1.x CookieComponent::_implode().

  • _getCookieEncryptionKey() protected

    Returns the encryption key to be used.

  • _handleError() protected

    Attempts to render an error response for a given exception.

  • _implode() protected

    Implode method to keep keys are multidimensional arrays

  • _normalizePath() protected

    Normalize a path for comparison.

  • _sendRequest() protected

    Creates and send the request into a Dispatcher instance.

  • _url() protected

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

  • assertContentType() public

    Asserts content type

  • assertCookie() public

    Asserts cookie values

  • assertCookieEncrypted() public

    Asserts cookie values which are encrypted by the CookieComponent.

  • assertHeader() public

    Asserts response headers

  • assertHtml() public

    Asserts HTML tags.

  • assertLayout() public

    Asserts that the search string was in the layout name.

  • assertNoRedirect() public

    Asserts that the Location header is not set.

  • assertNotWithinRange() protected static

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

  • assertPathEquals() protected static

    Compatibility function to test paths.

  • assertRedirect() public

    Asserts that the Location header is correct.

  • assertRedirectContains() public

    Asserts that the Location header contains a substring

  • assertResponseCode() public

    Asserts a specific response status code.

  • assertResponseContains() public

    Asserts content exists in the response body.

  • assertResponseEmpty() public

    Assert response content is empty.

  • assertResponseEquals() public

    Asserts content exists in the response body.

  • assertResponseError() public

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

  • assertResponseFailure() public

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

  • assertResponseNotContains() public

    Asserts content does not exist in the response body.

  • assertResponseNotEmpty() public

    Assert response content is not empty.

  • assertResponseOk() public

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

  • assertResponseSuccess() public

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

  • assertSession() public

    Asserts session contents

  • assertTags() public deprecated

    Asserts HTML tags.

  • assertTemplate() public

    Asserts that the search string was in the template name.

  • assertTextContains() public

    Assert that a string contains another string, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.

  • assertTextEndsNotWith() public

    Asserts that a string ends not with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.

  • assertTextEndsWith() public

    Asserts that a string ends with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.

  • assertTextEquals() public

    Assert text equality, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.

  • assertTextNotContains() public

    Assert that a text doesn't contain another text, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.

  • assertTextNotEquals() public

    Assert text equality, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.

  • assertTextStartsNotWith() public

    Asserts that a string starts not with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.

  • assertTextStartsWith() public

    Asserts that a string starts with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.

  • assertWithinRange() protected static

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

  • configRequest() public

    Configures the data for the next request.

  • controllerSpy() public

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

  • cookie() public

    Sets a request cookie for future requests.

  • cookieEncrypted() public

    Sets a encrypted request cookie for future requests.

  • delete() public

    Performs a DELETE request using the current request data.

  • enableCsrfToken() public

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

  • enableSecurityToken() public

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

  • get() public

    Performs a GET request using the current request data.

  • getMockForModel() public

    Mock a model, maintain fixtures and table association

  • loadFixtures() public

    Chooses which fixtures to load for a given test

  • patch() public

    Performs a PATCH request using the current request data.

  • post() public

    Performs a POST request using the current request data.

  • put() public

    Performs a PUT request using the current request data.

  • session() public

    Sets session data.

  • setUp() public

    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.

  • skipIf() public

    Overrides SimpleTestCase::skipIf to provide a boolean return value

  • skipUnless() protected

    Compatibility function for skipping.

  • tearDown() public

    Clears the state used for requests.

  • viewVariable() public

    Fetches a view variable by name.

Method Detail

_addTokens() ¶ protected

_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

_assertAttributes() ¶ protected

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

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

Parameters
array $assertions

Assertions to run.

string $string

The HTML string to check.

bool $fullDebug optional

Whether or not more verbose output should be used.

array $regex optional

Full regexp from assertHtml

Returns
string

_assertStatus() ¶ protected

_assertStatus(int $min, int $max, string $message): void

Helper method for status assertions.

Parameters
int $min

Min status code.

int $max

Max status code.

string $message

The error message.

Returns
void

_buildFieldToken() ¶ protected

_buildFieldToken(string $url, array $fields, array $unlockedFields = []): array

Generate the token data for the provided inputs.

Parameters
string $url

The URL the form is being submitted to.

array $fields

If set specifies the list of fields to use when generating the hash.

array $unlockedFields optional

The list of fields that are excluded from field validation.

Returns
array

_buildRequest() ¶ protected

_buildRequest(string|array $url, string $method, array|null $data): Cake\Network\Request

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
Cake\Network\Request

_checkCipher() ¶ protected

_checkCipher(string $encrypt): void

Helper method for validating encryption cipher names.

Parameters
string $encrypt

The cipher name.

Returns
void
Throws
RuntimeException
When an invalid cipher is provided.

_decode() ¶ protected

_decode(string $value, string|false $encrypt): string

Decodes and decrypts a single value.

Parameters
string $value

The value to decode & decrypt.

string|false $encrypt

The encryption cipher to use.

Returns
string

_decrypt() ¶ protected

_decrypt(array $values, string|bool $mode): string

Decrypts $value using public $type method in Security class

Parameters
array $values

Values to decrypt

string|bool $mode

Encryption mode

Returns
string

_encrypt() ¶ protected

_encrypt(string $value, string|bool $encrypt, string|null $key = null): string

Encrypts $value using public $type method in Security class

Parameters
string $value

Value to encrypt

string|bool $encrypt

Encryption mode to use. False disabled encryption.

string|null $key optional

Used as the security salt only in this time for tests if specified.

Returns
string

_explode() ¶ protected

_explode(string $string): array

Explode method to return array from string set in CookieComponent::_implode() Maintains reading backwards compatibility with 1.x CookieComponent::_implode().

Parameters
string $string

A string containing JSON encoded data, or a bare string.

Returns
array

_getCookieEncryptionKey() ¶ protected

_getCookieEncryptionKey(): string

Returns the encryption key to be used.

Returns
string

_handleError() ¶ protected

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

Returns
void
Throws
Exception

_implode() ¶ protected

_implode(array $array): string

Implode method to keep keys are multidimensional arrays

Parameters
array $array

Map of key and values

Returns
string

_normalizePath() ¶ protected

_normalizePath(string $path): string

Normalize a path for comparison.

Parameters
string $path

Path separated by "/" slash.

Returns
string

_sendRequest() ¶ protected

_sendRequest(string|array $url, string $method, array|null $data = []): 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 optional

The request data.

Returns
void
Throws
Exception

_url() ¶ protected

_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

assertContentType() ¶ public

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

Asserts content type

Parameters
string $type

The content-type to check for.

string $message optional

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

Returns
void

assertCookie() ¶ public

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

Asserts cookie values

Parameters
string $expected

The expected contents.

string $name

The cookie name.

string $message optional

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

Returns
void

assertCookieEncrypted() ¶ public

assertCookieEncrypted(string $expected, string $name, string|bool $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|bool $encrypt optional

Encryption mode to use.

string|null $key optional

Encryption key used. Defaults to Security.salt.

string $message optional

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

Returns
void
See Also
CookieCryptTrait::_encrypt

assertHeader() ¶ public

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 optional

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

Returns
void

assertHtml() ¶ public

assertHtml(array $expected, string $string, bool $fullDebug = false): bool

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

bool $fullDebug optional

Whether or not more verbose output should be used.

Returns
bool

assertLayout() ¶ public

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 optional

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

Returns
void

assertNoRedirect() ¶ public

assertNoRedirect(string $message = ''): void

Asserts that the Location header is not set.

Parameters
string $message optional

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

Returns
void

assertNotWithinRange() ¶ protected static

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 optional

the text to display if the assertion is not correct

Returns
void

assertPathEquals() ¶ protected static

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

Compatibility function to test paths.

Parameters
string $expected
string $result
string $message optional

the text to display if the assertion is not correct

Returns
void

assertRedirect() ¶ public

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

Asserts that the Location header is correct.

Parameters
string|array|null $url optional

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 optional

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

Returns
void

assertRedirectContains() ¶ public

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 optional

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

Returns
void

assertResponseCode() ¶ public

assertResponseCode(int $code): void

Asserts a specific response status code.

Parameters
int $code

Status code to assert.

Returns
void

assertResponseContains() ¶ public

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

Asserts content exists in the response body.

Parameters
string $content

The content to check for.

string $message optional

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

Returns
void

assertResponseEmpty() ¶ public

assertResponseEmpty(string $message = ''): void

Assert response content is empty.

Parameters
string $message optional

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

Returns
void

assertResponseEquals() ¶ public

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

Asserts content exists in the response body.

Parameters
mixed $content

The content to check for.

string $message optional

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

Returns
void

assertResponseError() ¶ public

assertResponseError(): void

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

Returns
void

assertResponseFailure() ¶ public

assertResponseFailure(): void

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

Returns
void

assertResponseNotContains() ¶ public

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

Asserts content does not exist in the response body.

Parameters
string $content

The content to check for.

string $message optional

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

Returns
void

assertResponseNotEmpty() ¶ public

assertResponseNotEmpty(string $message = ''): void

Assert response content is not empty.

Parameters
string $message optional

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

Returns
void

assertResponseOk() ¶ public

assertResponseOk(): void

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

Returns
void

assertResponseSuccess() ¶ public

assertResponseSuccess(): void

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

Returns
void

assertSession() ¶ public

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 optional

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

Returns
void

assertTags() ¶ public

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

Asserts HTML tags.

Parameters
string $string

An HTML/XHTML/XML string

array $expected

An array, see above

bool $fullDebug optional

Whether or not more verbose output should be used.

Returns
void

assertTemplate() ¶ public

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 optional

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

Returns
void

assertTextContains() ¶ public

assertTextContains(string $needle, string $haystack, string $message = '', bool $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 optional

The message to display on failure.

bool $ignoreCase optional

Whether or not the search should be case-sensitive.

Returns
void

assertTextEndsNotWith() ¶ public

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 optional

The message to use for failure.

Returns
void

assertTextEndsWith() ¶ public

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 optional

The message to use for failure.

Returns
void

assertTextEquals() ¶ public

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 optional

The message to use for failure.

Returns
void

assertTextNotContains() ¶ public

assertTextNotContains(string $needle, string $haystack, string $message = '', bool $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 optional

The message to display on failure.

bool $ignoreCase optional

Whether or not the search should be case-sensitive.

Returns
void

assertTextNotEquals() ¶ public

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 optional

The message to use for failure.

Returns
void

assertTextStartsNotWith() ¶ public

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 optional

The message to use for failure.

Returns
void

assertTextStartsWith() ¶ public

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 optional

The message to use for failure.

Returns
void

assertWithinRange() ¶ protected static

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 optional

the text to display if the assertion is not correct

Returns
void

configRequest() ¶ public

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.

Returns
void

controllerSpy() ¶ public

controllerSpy(Cake\Event\Event $event): void

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

Parameters
Cake\Event\Event $event

A dispatcher event.

Returns
void

cookie() ¶ public

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.

Returns
void

cookieEncrypted() ¶ public

cookieEncrypted(string $name, mixed $value, string|bool $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|bool $encrypt optional

Encryption mode to use.

string|null $key optional

Encryption key used. Defaults to Security.salt.

Returns
void
See Also
CookieCryptTrait::_encrypt

delete() ¶ public

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.

Returns
void

enableCsrfToken() ¶ public

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.

Returns
void

enableSecurityToken() ¶ public

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.

Returns
void

get() ¶ public

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.

Returns
void

getMockForModel() ¶ public

getMockForModel(string $alias, mixed $methods = [], array $options = []): 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.

mixed $methods optional

The list of methods to mock

array $options optional

The config data for the mock's constructor.

Returns
Cake\ORM\Table|PHPUnit_Framework_MockObject_MockObject
Throws
Cake\ORM\Exception\MissingTableClassException

loadFixtures() ¶ public

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.

Returns
void
Throws
Exception
when no fixture manager is available.
See Also
\Cake\TestSuite\TestCase::$autoFixtures

patch() ¶ public

patch(string|array $url, array $data = []): 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 optional

The data for the request.

Returns
void

post() ¶ public

post(string|array $url, array $data = []): 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 optional

The data for the request.

Returns
void

put() ¶ public

put(string|array $url, array $data = []): 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 optional

The data for the request.

Returns
void

session() ¶ public

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.

Returns
void

setUp() ¶ public

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.

Returns
void

skipIf() ¶ public

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

Overrides SimpleTestCase::skipIf to provide a boolean return value

Parameters
bool $shouldSkip

Whether or not the test should be skipped.

string $message optional

The message to display.

Returns
bool

skipUnless() ¶ protected

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

Compatibility function for skipping.

Parameters
bool $condition

Condition to trigger skipping

string $message optional

Message for skip

Returns
bool

tearDown() ¶ public

tearDown(): void

Clears the state used for requests.

Returns
void

viewVariable() ¶ public

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

Property Detail

$_configure ¶ protected

Configure values to restore at end of test.

Type
array

$_controller ¶ protected

The controller used in the last request.

Type
Cake\Controller\Controller

$_cookie ¶ protected

Cookie data to use in the next request.

Type
array

$_cookieEncriptionKey ¶ protected

Type
null|string

$_csrfToken ¶ protected

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

Type
bool

$_exception ¶ protected

The exception being thrown if the case.

Type
Cake\Core\Exception\Exception

$_layoutName ¶ protected

The last rendered layout

Type
string

$_pathRestore ¶ protected

Path settings to restore at the end of the test.

Type
array

$_request ¶ protected

The data used to build the next request.

Type
array

$_requestSession ¶ protected

The session instance from the last request

Type
Cake\Network\Session

$_response ¶ protected

The response for the most recent request.

Type
Cake\Network\Response

$_securityToken ¶ protected

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

Type
bool

$_session ¶ protected

Session data to use in the next request.

Type
array

$_validCiphers ¶ protected

Valid cipher names for encrypted cookies.

Type
array

$_viewName ¶ protected

The last rendered view

Type
string

$autoFixtures ¶ public

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

Type
array

$dropTables ¶ public

Control table create/drops on each test method.

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

Type
bool

$fixtureManager ¶ public

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

Type
Cake\TestSuite\Fixture\FixtureManager
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs