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.
array|null
The customized application constructor arguments.
string|null
The customized application class name.
array
Configure values to restore at end of test.
Cake\Controller\Controller|null
The controller used in the last request.
array
Cookie data to use in the next request.
string|null
string
The name that will be used when retrieving the csrf token.
bool
Boolean flag for whether the request should have a CSRF token added.
Throwable|null
The exception being thrown if the case.
array
Stored flash messages before render
string
The last rendered layout
array
The data used to build the next request.
Cake\Http\Session
The session instance from the last request
Psr\Http\Message\ResponseInterface|null
The response for the most recent request.
bool
Boolean flag for whether the request should re-store flash messages
bool
Boolean flag for whether the request should have a SecurityComponent token added.
array
Session data to use in the next request.
Cake\ORM\Locator\LocatorInterface|null
Table locator instance
array<string>
List of fields that are excluded from field validation.
array<string>
Valid cipher names for encrypted cookies.
string
The last rendered view
bool
By default, all fixtures attached to this class will be truncated and reloaded after each test. Set this to false to handle manually
?bool
string[]
string[]
bool
array<string, array<int, string>>
array<string, array<int, string>>
string|null
This object's default table alias.
bool
Control table create/drops on each test method.
Cake\TestSuite\Fixture\FixtureManager|null
The class responsible for managing the creation, loading and removing of fixtures
Cake\TestSuite\Fixture\FixtureStrategyInterface|null
array<string>
Fixtures used by this test case.
bool
list<ExecutionOrderDependency>
bool
Add the CSRF and Security Component tokens if necessary.
Check the attributes as part of an assertTags() check.
Creates a request object with the configured options and parameters.
Recursively casts all data to string as that is how data would be POSTed in the real world
Helper method for validating encryption cipher names.
Decodes and decrypts a single value.
Decrypts $value using public $type method in Security class
Encrypts $value using public $type method in Security class
Explode method to return array from string set in CookieComponent::_implode() Maintains reading backwards compatibility with 1.x CookieComponent::_implode().
Get the response body as string
Returns the encryption key to be used.
Gets the class name for the table.
Attempts to render an error response for a given exception.
Implode method to keep keys are multidimensional arrays
Get the correct dispatcher instance.
Normalize a path for comparison.
Creates and send the request into a Dispatcher instance.
Creates a valid request url and parameter array more like Request::_url()
Adds a fixture to this test case.
Returns a matcher that matches when the method is executed zero or more times.
Asserts that an array has a specified key.
Asserts that an array does not have a specified key.
Asserts that a class has a specified attribute.
Asserts that a class has a specified static attribute.
Asserts that a class does not have a specified attribute.
Asserts that a class does not have a specified static attribute.
Asserts that a haystack contains a needle.
Asserts that a haystack contains only values of a given type.
Asserts that a haystack contains only instances of a given class name.
Asserts content type
Asserts cookie values
Asserts cookie values which are encrypted by the CookieComponent.
Asserts a cookie has not been set in the response
Asserts the number of elements of an array, Countable or Traversable.
Asserts that a directory does not exist.
Asserts that a directory exists.
Asserts that a directory exists and is not readable.
Asserts that a directory exists and is not writable.
Asserts that a directory exists and is readable.
Asserts that a directory exists and is writable.
Asserts that a directory does not exist.
Asserts that a directory exists and is not readable.
Asserts that a directory exists and is not writable.
Asserts that a string does not match a given regular expression.
Asserts that a variable is empty.
Asserts that a hierarchy of DOMElements matches.
Asserts that two variables are equal.
Asserts that two variables are equal (canonicalizing).
Asserts that two variables are equal (ignoring case).
Assert that a string matches SQL with db-specific characters like quotes removed.
Asserts that two variables are equal (with delta).
Asserts that a global event was fired. You must track events in your event manager for this assertion to work
Asserts an event was fired with data
Asserts that a condition is false.
Asserts that a file does not exist.
Asserts that the contents of one file is equal to the contents of another file.
Asserts that the contents of one file is equal to the contents of another file (canonicalizing).
Asserts that the contents of one file is equal to the contents of another file (ignoring case).
Asserts that a file exists.
Asserts that a file exists and is not readable.
Asserts that a file exists and is not writable.
Asserts that a file exists and is readable.
Asserts that a file exists and is writable.
Asserts that the contents of one file is not equal to the contents of another file.
Asserts that the contents of one file is not equal to the contents of another file (canonicalizing).
Asserts that the contents of one file is not equal to the contents of another file (ignoring case).
Asserts that a file does not exist.
Asserts that a file exists and is not readable.
Asserts that a file exists and is not writable.
Asserts that a file with the given name was sent in the response
Asserts that a variable is finite.
Asserts a flash element was set
Asserts a flash element was set at a certain index
Asserts a flash message was set
Asserts a flash message was set at a certain index
Asserts that a value is greater than another value.
Asserts that a value is greater than or equal to another value.
Asserts response headers
Asserts response header contains a string
Asserts response header does not contain a string
Asserts HTML tags.
Asserts that a variable is infinite.
Asserts that a variable is of a given type.
Asserts that a variable is of type array.
Asserts that a variable is of type bool.
Asserts that a variable is of type callable.
Asserts that a variable is of type resource and is closed.
Asserts that a variable is of type float.
Asserts that a variable is of type int.
Asserts that a variable is of type iterable.
Asserts that a variable is not of type array.
Asserts that a variable is not of type bool.
Asserts that a variable is not of type callable.
Asserts that a variable is not of type resource.
Asserts that a variable is not of type float.
Asserts that a variable is not of type int.
Asserts that a variable is not of type iterable.
Asserts that a variable is not of type numeric.
Asserts that a variable is not of type object.
Asserts that a file/dir exists and is not readable.
Asserts that a variable is not of type resource.
Asserts that a variable is not of type scalar.
Asserts that a variable is not of type string.
Asserts that a file/dir exists and is not writable.
Asserts that a variable is of type numeric.
Asserts that a variable is of type object.
Asserts that a file/dir is readable.
Asserts that a variable is of type resource.
Asserts that a variable is of type scalar.
Asserts that a variable is of type string.
Asserts that a file/dir exists and is writable.
Asserts that a string is a valid JSON string.
Asserts that two JSON files are equal.
Asserts that two JSON files are not equal.
Asserts that the generated JSON encoded object and the content of the given file are equal.
Asserts that two given JSON encoded objects or arrays are equal.
Asserts that the generated JSON encoded object and the content of the given file are not equal.
Asserts that two given JSON encoded objects or arrays are not equal.
Asserts that the search string was in the layout name.
Asserts that a value is smaller than another value.
Asserts that a value is smaller than or equal to another value.
Asserts that a string matches a given regular expression.
Asserts that a variable is nan.
Asserts that the Location header is not set.
Asserts that a haystack does not contain a needle.
Asserts that a haystack does not contain only values of a given type.
Asserts the number of elements of an array, Countable or Traversable.
Asserts that a variable is not empty.
Asserts that two variables are not equal.
Asserts that two variables are not equal (canonicalizing).
Asserts that two variables are not equal (ignoring case).
Asserts that two variables are not equal (with delta).
Asserts that a condition is not false.
Asserts that a variable is not of a given type.
Asserts that a file/dir exists and is not readable.
Asserts that a file/dir exists and is not writable.
Asserts that a variable is not null.
Asserts that a string does not match a given regular expression.
Asserts that two variables do not have the same type and value. Used on objects, it asserts that two variables do not reference the same object.
Assert that the size of two arrays (or Countable
or Traversable
objects) is not the same.
Asserts that a condition is not true.
Compatibility function to test if a value is not between an acceptable range.
Asserts that a variable is null.
Asserts that an object has a specified attribute.
Asserts that an object does not have a specified attribute.
Compatibility function to test paths.
Performs assertions shared by all tests of a test case.
Performs assertions shared by all tests of a test case.
Asserts that the Location header is correct. Comparison is made against a full URL.
Asserts that the Location header contains a substring
Asserts that the Location header is correct. Comparison is made against exactly the URL provided.
Asserts that the Location header does not contain a substring
Asserts that a string matches a given regular expression.
Assertion for comparing a regex pattern against a query having its identifiers quoted. It accepts queries quoted with the characters <
and >
. If the third parameter is set to true, it will alter the pattern to both accept quoted and unquoted queries
Asserts a specific response status code.
Asserts content exists in the response body.
Assert response content is empty.
Asserts content in the response body equals.
Asserts that the response status code is in the 4xx range.
Asserts that the response status code is in the 5xx range.
Asserts content does not exist in the response body.
Assert response content is not empty.
Asserts content in the response body not equals.
Asserts that the response body does not match a given regular expression.
Asserts that the response status code is in the 2xx range.
Asserts that the response body matches a given regular expression.
Asserts that the response status code is in the 2xx/3xx range.
Asserts that two variables have the same type and value. Used on objects, it asserts that two variables reference the same object.
Assert that the size of two arrays (or Countable
or Traversable
objects) is the same.
Asserts session contents
Asserts session key exists.
Asserts a session key does not exist.
Asserts that a string ends not with a given suffix.
Asserts that a string ends with a given suffix.
Asserts that the contents of a string is equal to the contents of a file.
Asserts that the contents of a string is equal to the contents of a file (canonicalizing).
Asserts that the contents of a string is equal to the contents of a file (ignoring case).
Asserts that a string matches a given format string.
Asserts that a string matches a given format file.
Asserts that the contents of a string is not equal to the contents of a file.
Asserts that the contents of a string is not equal to the contents of a file (canonicalizing).
Asserts that the contents of a string is not equal to the contents of a file (ignoring case).
Asserts that a string does not match a given format string.
Asserts that a string does not match a given format string.
Asserts that a string starts not with a given prefix.
Asserts that a string starts with a given prefix.
Asserts that the search string was in the template name.
Assert that a string contains another string, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Asserts that a string ends not with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Asserts that a string ends with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Assert text equality, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Assert that a text doesn't contain another text, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Assert text equality, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Asserts that a string starts not with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Asserts that a string starts with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Evaluates a PHPUnit\Framework\Constraint matcher object.
Asserts that a condition is true.
Compatibility function to test if a value is between an acceptable range.
Asserts that two XML files are equal.
Asserts that two XML files are not equal.
Asserts that two XML documents are equal.
Asserts that two XML documents are equal.
Asserts that two XML documents are not equal.
Asserts that two XML documents are not equal.
Returns a matcher that matches when the method is executed at the given index.
Returns a matcher that matches when the method is executed at least N times.
Returns a matcher that matches when the method is executed at least once.
Returns a matcher that matches when the method is executed at most N times.
Clears the state used for requests.
Clears any mocks that were defined and cleans up application class configuration.
Clear all plugins from the global plugin collection.
Configure the application class to use in integration tests.
Configures the data for the next request.
Adds additional event spies to the controller/view event manager.
Sets a request cookie for future requests.
Sets a encrypted request cookie for future requests.
Create an application instance.
Returns a configured mock object for the specified class.
Returns a mock object for the specified class.
Returns a partial mock object for the specified class.
Creates a default TestResult object.
Makes configurable stub for the specified class.
Returns a test proxy for the specified class.
Performs a DELETE request using the current request data.
Helper method for check deprecation methods
Disable the error handler middleware.
Calling this method will add a CSRF token to the request.
Calling this method will re-store flash messages into the test session after being removed by the FlashHelper
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 a matcher that matches when the method is executed exactly $count times.
Sets up an expectation for an exception to be raised by the code under test. Information for expected exception class, expected exception message, and expected exception code are retrieved from a given Exception object.
Extract verbose message for existing exception
Inspect controller to extract possible causes of the failed assertion
Fails a test with the given message.
Convenience method to get a table instance.
Performs a GET request using the current request data.
Return the current assertion count.
Returns fixture strategy used by these tests.
Get the fixtures this test should use.
Returns a builder object to create mock objects using a fluent interface.
Mocks the specified class and returns the name of the mocked class.
Returns a mock object for the specified abstract class with all abstract methods of the class mocked. Concrete methods are not mocked by default. To mock concrete methods, use the 7th parameter ($mockedMethods).
Mock a model, maintain fixtures and table association
Returns a mock object for the specified trait with all abstract methods of the trait mocked. Concrete methods to mock can be specified with the $mockedMethods
parameter.
Returns a mock object based on the given WSDL file.
Returns the number of assertions performed by this test.
Returns an object for the specified trait.
Gets the data set of a TestCase.
Returns the size of the test.
Gets the table locator.
Performs a HEAD request using the current request data.
This method is a wrapper for the ini_set() function that automatically resets the modified php.ini setting to its original value after the test is run.
Chooses which fixtures to load for a given test
Load plugins into a simulated application.
Load routes for the application.
Mark the test as incomplete.
Mark the test as skipped.
Add a mocked service to the container.
Wrap the application's container with one containing mocks.
Returns a matcher that matches when the method is never executed.
This method is called when a test method did not execute successfully.
Returns a matcher that matches when the method is executed exactly once.
Performs an OPTIONS request using the current request data.
Performs a PATCH request using the current request data.
Performs a POST request using the current request data.
Returns the normalized test name as class::method.
Performs a PUT request using the current request data.
Remove a mocked service to the container.
Remove plugins from the global plugin collection.
Returns a list of normalized dependency names, class::method.
Reset the assertion counter.
Returns the current object.
Runs the test case and collects the results in a TestResult object. If no TestResult object is passed a new one will be created.
Override to run the test and assert its state.
Sets session data.
Set the app namespace
This method is a wrapper for the setlocale() function that automatically resets the locale to its original value after the test is run.
Sets the table locator.
Set list of fields that are excluded from field validation.
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.
This method is called before the first test of this test class is run.
Initialized and loads any use fixtures.
Overrides SimpleTestCase::skipIf to provide a boolean return value
Compatibility function for skipping.
teardown any static object changes and restore them.
This method is called after the last test of this test class is run.
Unloads any use fixtures.
Returns a string representation of the test case.
No-op method.
Fetches a view variable by name.
Helper method for tests that needs to use error_reporting()
__construct(?string $name = null, array $data = [], int|string $dataName = '')
?string
$name optional array
$data optional int|string
$dataName optional _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.
array
_assertAttributes(array<string, mixed> $assertions, string $string, bool $fullDebug = false, array|string $regex = ''): string|false
Check the attributes as part of an assertTags() check.
array<string, mixed>
$assertions Assertions to run.
string
$string The HTML string to check.
bool
$fullDebug optional Whether more verbose output should be used.
array|string
$regex optional Full regexp from assertHtml
string|false
_buildRequest(string $url, string $method, array|string $data = []): array
Creates a request object with the configured options and parameters.
string
$url The URL
string
$method The HTTP method
array|string
$data optional The request data.
array
_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
array
_checkCipher(string $encrypt): void
Helper method for validating encryption cipher names.
string
$encrypt The cipher name.
void
RuntimeException
_decode(string $value, string|false $encrypt, string|null $key): array|string
Decodes and decrypts a single value.
string
$value The value to decode & decrypt.
string|false
$encrypt The encryption cipher to use.
string|null
$key Used as the security salt if specified.
array|string
_decrypt(array<string>|string $values, string|false $mode, string|null $key = null): array|string
Decrypts $value using public $type method in Security class
array<string>|string
$values Values to decrypt
string|false
$mode Encryption mode
string|null
$key optional Used as the security salt if specified.
array|string
_encrypt(array|string $value, string|false $encrypt, string|null $key = null): string
Encrypts $value using public $type method in Security class
array|string
$value Value to encrypt
string|false
$encrypt Encryption mode to use. False disabled encryption.
string|null
$key optional Used as the security salt if specified.
string
_explode(string $string): array|string
Explode method to return array from string set in CookieComponent::_implode() Maintains reading backwards compatibility with 1.x CookieComponent::_implode().
string
$string A string containing JSON encoded data, or a bare string.
array|string
_getBodyAsString(): string
Get the response body as string
string
_getCookieEncryptionKey(): string
Returns the encryption key to be used.
string
_getTableClassName(string $alias, array<string, mixed> $options): string
Gets the class name for the table.
string
$alias The model to get a mock for.
array<string, mixed>
$options The config data for the mock's constructor.
string
Cake\ORM\Exception\MissingTableClassException
_handleError(Throwable $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.
Throwable
$exception Exception to handle.
void
_implode(array $array): string
Implode method to keep keys are multidimensional arrays
array
$array Map of key and values
string
_makeDispatcher(): Cake\TestSuite\MiddlewareDispatcher
Get the correct dispatcher instance.
Cake\TestSuite\MiddlewareDispatcher
_normalizePath(string $path): string
Normalize a path for comparison.
string
$path Path separated by "/" slash.
string
_sendRequest(array|string $url, string $method, array|string $data = []): void
Creates and send the request into a Dispatcher instance.
Receives and stores the response for future inspection.
array|string
$url The URL
string
$method The HTTP method
array|string
$data optional The request data.
void
PHPUnit\ExceptionThrowable
_url(string $url): array
Creates a valid request url and parameter array more like Request::_url()
string
$url The URL
array
addFixture(string $fixture): $this
Adds a fixture to this test case.
Examples:
Use this method inside your test cases' {@link getFixtures()} method to build up the fixture list.
string
$fixture Fixture
$this
addToAssertionCount(int $count): void
int
$count void
addWarning(string $warning): void
string
$warning void
any(): AnyInvokedCountMatcher
Returns a matcher that matches when the method is executed zero or more times.
AnyInvokedCountMatcher
anything(): IsAnything
IsAnything
arrayHasKey(int|string $key): ArrayHasKey
int|string
$key ArrayHasKey
assertArrayHasKey(int|string $key, array|ArrayAccess $array, string $message = ''): void
Asserts that an array has a specified key.
int|string
$key array|ArrayAccess
$array string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertArrayNotHasKey(int|string $key, array|ArrayAccess $array, string $message = ''): void
Asserts that an array does not have a specified key.
int|string
$key array|ArrayAccess
$array string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertClassHasAttribute(string $attributeName, string $className, string $message = ''): void
Asserts that a class has a specified attribute.
string
$attributeName string
$className string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertClassHasStaticAttribute(string $attributeName, string $className, string $message = ''): void
Asserts that a class has a specified static attribute.
string
$attributeName string
$className string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertClassNotHasAttribute(string $attributeName, string $className, string $message = ''): void
Asserts that a class does not have a specified attribute.
string
$attributeName string
$className string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertClassNotHasStaticAttribute(string $attributeName, string $className, string $message = ''): void
Asserts that a class does not have a specified static attribute.
string
$attributeName string
$className string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertContains(mixed $needle, iterable $haystack, string $message = ''): void
Asserts that a haystack contains a needle.
iterable
$haystack string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertContainsEquals(mixed $needle, iterable $haystack, string $message = ''): void
iterable
$haystack string
$message optional void
assertContainsOnly(string $type, iterable $haystack, ?bool $isNativeType = null, string $message = ''): void
Asserts that a haystack contains only values of a given type.
string
$type iterable
$haystack ?bool
$isNativeType optional string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertContainsOnlyInstancesOf(string $className, iterable $haystack, string $message = ''): void
Asserts that a haystack contains only instances of a given class name.
string
$className iterable
$haystack string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertContentType(string $type, string $message = ''): void
Asserts content type
string
$type The content-type to check for.
string
$message optional The failure message that will be appended to the generated message.
void
assertCookie(mixed $expected, string $name, string $message = ''): void
Asserts cookie values
mixed
$expected The expected contents.
string
$name The cookie name.
string
$message optional The failure message that will be appended to the generated message.
void
assertCookieEncrypted(mixed $expected, string $name, string $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.
mixed
$expected The expected contents.
string
$name The cookie name.
string
$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.
void
assertCookieNotSet(string $cookie, string $message = ''): void
Asserts a cookie has not been set in the response
string
$cookie The cookie name to check
string
$message optional The failure message that will be appended to the generated message.
void
assertCount(int $expectedCount, Countable|iterable $haystack, string $message = ''): void
Asserts the number of elements of an array, Countable or Traversable.
int
$expectedCount Countable|iterable
$haystack string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertDirectoryDoesNotExist(string $directory, string $message = ''): void
Asserts that a directory does not exist.
string
$directory Directory
string
$message optional Message
void
SebastianBergmann\RecursionContext\InvalidArgumentException
assertDirectoryExists(string $directory, string $message = ''): void
Asserts that a directory exists.
string
$directory string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertDirectoryIsNotReadable(string $directory, string $message = ''): void
Asserts that a directory exists and is not readable.
string
$directory string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertDirectoryIsNotWritable(string $directory, string $message = ''): void
Asserts that a directory exists and is not writable.
string
$directory string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertDirectoryIsReadable(string $directory, string $message = ''): void
Asserts that a directory exists and is readable.
string
$directory string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertDirectoryIsWritable(string $directory, string $message = ''): void
Asserts that a directory exists and is writable.
string
$directory string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertDirectoryNotExists(string $directory, string $message = ''): void
Asserts that a directory does not exist.
string
$directory string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertDirectoryNotIsReadable(string $directory, string $message = ''): void
Asserts that a directory exists and is not readable.
string
$directory string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertDirectoryNotIsWritable(string $directory, string $message = ''): void
Asserts that a directory exists and is not writable.
string
$directory string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertDoesNotMatchRegularExpression(string $pattern, string $string, string $message = ''): void
Asserts that a string does not match a given regular expression.
string
$pattern Regex pattern
string
$string String to test
string
$message optional Message
void
SebastianBergmann\RecursionContext\InvalidArgumentException
assertEmpty(mixed $actual, string $message = ''): void
Asserts that a variable is empty.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertEqualXMLStructure(DOMElement $expectedElement, DOMElement $actualElement, bool $checkAttributes = false, string $message = ''): void
Asserts that a hierarchy of DOMElements matches.
DOMElement
$expectedElement DOMElement
$actualElement bool
$checkAttributes optional string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
AssertionFailedError
ExpectationFailedException
assertEquals(mixed $expected, mixed $actual, string $message = ''): void
Asserts that two variables are equal.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertEqualsCanonicalizing(mixed $expected, mixed $actual, string $message = ''): void
Asserts that two variables are equal (canonicalizing).
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertEqualsIgnoringCase(mixed $expected, mixed $actual, string $message = ''): void
Asserts that two variables are equal (ignoring case).
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertEqualsSql(string $expected, string $actual, string $message = ''): void
Assert that a string matches SQL with db-specific characters like quotes removed.
string
$expected The expected sql
string
$actual The sql to compare
string
$message optional The message to display on failure
void
assertEqualsWithDelta(mixed $expected, mixed $actual, float $delta, string $message = ''): void
Asserts that two variables are equal (with delta).
float
$delta string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
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 optional Event manager to check, defaults to global event manager
string
$message optional Assertion failure message
void
assertEventFiredWith(string $name, string $dataKey, mixed $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
mixed
$dataValue Data value
Cake\Event\EventManager|null
$eventManager optional Event manager to check, defaults to global event manager
string
$message optional Assertion failure message
void
assertFalse(mixed $condition, string $message = ''): void
Asserts that a condition is false.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileDoesNotExist(string $filename, string $message = ''): void
Asserts that a file does not exist.
string
$filename Filename
string
$message optional Message
void
SebastianBergmann\RecursionContext\InvalidArgumentException
assertFileEquals(string $expected, string $actual, string $message = ''): void
Asserts that the contents of one file is equal to the contents of another file.
string
$expected string
$actual string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileEqualsCanonicalizing(string $expected, string $actual, string $message = ''): void
Asserts that the contents of one file is equal to the contents of another file (canonicalizing).
string
$expected string
$actual string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileEqualsIgnoringCase(string $expected, string $actual, string $message = ''): void
Asserts that the contents of one file is equal to the contents of another file (ignoring case).
string
$expected string
$actual string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileExists(string $filename, string $message = ''): void
Asserts that a file exists.
string
$filename string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileIsNotReadable(string $file, string $message = ''): void
Asserts that a file exists and is not readable.
string
$file string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileIsNotWritable(string $file, string $message = ''): void
Asserts that a file exists and is not writable.
string
$file string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileIsReadable(string $file, string $message = ''): void
Asserts that a file exists and is readable.
string
$file string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileIsWritable(string $file, string $message = ''): void
Asserts that a file exists and is writable.
string
$file string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileNotEquals(string $expected, string $actual, string $message = ''): void
Asserts that the contents of one file is not equal to the contents of another file.
string
$expected string
$actual string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileNotEqualsCanonicalizing(string $expected, string $actual, string $message = ''): void
Asserts that the contents of one file is not equal to the contents of another file (canonicalizing).
string
$expected string
$actual string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileNotEqualsIgnoringCase(string $expected, string $actual, string $message = ''): void
Asserts that the contents of one file is not equal to the contents of another file (ignoring case).
string
$expected string
$actual string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileNotExists(string $filename, string $message = ''): void
Asserts that a file does not exist.
string
$filename string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileNotIsReadable(string $file, string $message = ''): void
Asserts that a file exists and is not readable.
string
$file string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileNotIsWritable(string $file, string $message = ''): void
Asserts that a file exists and is not writable.
string
$file string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileResponse(string $expected, string $message = ''): void
Asserts that a file with the given name was sent in the response
string
$expected The absolute file path that should be sent in the response.
string
$message optional The failure message that will be appended to the generated message.
void
assertFinite(mixed $actual, string $message = ''): void
Asserts that a variable is finite.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFlashElement(string $expected, string $key = 'flash', string $message = ''): void
Asserts a flash element was set
string
$expected Expected element name
string
$key optional Flash key
string
$message optional Assertion failure message
void
assertFlashElementAt(int $at, string $expected, string $key = 'flash', string $message = ''): void
Asserts a flash element was set at a certain index
int
$at Flash index
string
$expected Expected element name
string
$key optional Flash key
string
$message optional Assertion failure message
void
assertFlashMessage(string $expected, string $key = 'flash', string $message = ''): void
Asserts a flash message was set
string
$expected Expected message
string
$key optional Flash key
string
$message optional Assertion failure message
void
assertFlashMessageAt(int $at, string $expected, string $key = 'flash', string $message = ''): void
Asserts a flash message was set at a certain index
int
$at Flash index
string
$expected Expected message
string
$key optional Flash key
string
$message optional Assertion failure message
void
assertGreaterThan(mixed $expected, mixed $actual, string $message = ''): void
Asserts that a value is greater than another value.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertGreaterThanOrEqual(mixed $expected, mixed $actual, string $message = ''): void
Asserts that a value is greater than or equal to another value.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertHeader(string $header, string $content, string $message = ''): void
Asserts response headers
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.
void
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 optional The failure message that will be appended to the generated message.
void
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 optional The failure message that will be appended to the generated message.
void
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.
array
$expected An array, see above
string
$string An HTML/XHTML/XML string
bool
$fullDebug optional Whether more verbose output should be used.
bool
assertInfinite(mixed $actual, string $message = ''): void
Asserts that a variable is infinite.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertInstanceOf(string $expected, mixed $actual, string $message = ''): void
Asserts that a variable is of a given type.
string
$expected string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertIsArray(mixed $actual, string $message = ''): void
Asserts that a variable is of type array.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsBool(mixed $actual, string $message = ''): void
Asserts that a variable is of type bool.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsCallable(mixed $actual, string $message = ''): void
Asserts that a variable is of type callable.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsClosedResource(mixed $actual, string $message = ''): void
Asserts that a variable is of type resource and is closed.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsFloat(mixed $actual, string $message = ''): void
Asserts that a variable is of type float.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsInt(mixed $actual, string $message = ''): void
Asserts that a variable is of type int.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsIterable(mixed $actual, string $message = ''): void
Asserts that a variable is of type iterable.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotArray(mixed $actual, string $message = ''): void
Asserts that a variable is not of type array.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotBool(mixed $actual, string $message = ''): void
Asserts that a variable is not of type bool.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotCallable(mixed $actual, string $message = ''): void
Asserts that a variable is not of type callable.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotClosedResource(mixed $actual, string $message = ''): void
Asserts that a variable is not of type resource.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotFloat(mixed $actual, string $message = ''): void
Asserts that a variable is not of type float.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotInt(mixed $actual, string $message = ''): void
Asserts that a variable is not of type int.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotIterable(mixed $actual, string $message = ''): void
Asserts that a variable is not of type iterable.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotNumeric(mixed $actual, string $message = ''): void
Asserts that a variable is not of type numeric.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotObject(mixed $actual, string $message = ''): void
Asserts that a variable is not of type object.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotReadable(string $filename, string $message = ''): void
Asserts that a file/dir exists and is not readable.
string
$filename string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotResource(mixed $actual, string $message = ''): void
Asserts that a variable is not of type resource.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotScalar(mixed $actual, string $message = ''): void
Asserts that a variable is not of type scalar.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotString(mixed $actual, string $message = ''): void
Asserts that a variable is not of type string.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotWritable(string $filename, string $message = ''): void
Asserts that a file/dir exists and is not writable.
string
$filename string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNumeric(mixed $actual, string $message = ''): void
Asserts that a variable is of type numeric.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsObject(mixed $actual, string $message = ''): void
Asserts that a variable is of type object.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsReadable(string $filename, string $message = ''): void
Asserts that a file/dir is readable.
string
$filename string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsResource(mixed $actual, string $message = ''): void
Asserts that a variable is of type resource.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsScalar(mixed $actual, string $message = ''): void
Asserts that a variable is of type scalar.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsString(mixed $actual, string $message = ''): void
Asserts that a variable is of type string.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsWritable(string $filename, string $message = ''): void
Asserts that a file/dir exists and is writable.
string
$filename string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertJson(string $actualJson, string $message = ''): void
Asserts that a string is a valid JSON string.
string
$actualJson string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertJsonFileEqualsJsonFile(string $expectedFile, string $actualFile, string $message = ''): void
Asserts that two JSON files are equal.
string
$expectedFile string
$actualFile string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertJsonFileNotEqualsJsonFile(string $expectedFile, string $actualFile, string $message = ''): void
Asserts that two JSON files are not equal.
string
$expectedFile string
$actualFile string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertJsonStringEqualsJsonFile(string $expectedFile, string $actualJson, string $message = ''): void
Asserts that the generated JSON encoded object and the content of the given file are equal.
string
$expectedFile string
$actualJson string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertJsonStringEqualsJsonString(string $expectedJson, string $actualJson, string $message = ''): void
Asserts that two given JSON encoded objects or arrays are equal.
string
$expectedJson string
$actualJson string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertJsonStringNotEqualsJsonFile(string $expectedFile, string $actualJson, string $message = ''): void
Asserts that the generated JSON encoded object and the content of the given file are not equal.
string
$expectedFile string
$actualJson string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertJsonStringNotEqualsJsonString(string $expectedJson, string $actualJson, string $message = ''): void
Asserts that two given JSON encoded objects or arrays are not equal.
string
$expectedJson string
$actualJson string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertLayout(string $content, string $message = ''): void
Asserts that the search string was in the layout name.
string
$content The content to check for.
string
$message optional The failure message that will be appended to the generated message.
void
assertLessThan(mixed $expected, mixed $actual, string $message = ''): void
Asserts that a value is smaller than another value.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertLessThanOrEqual(mixed $expected, mixed $actual, string $message = ''): void
Asserts that a value is smaller than or equal to another value.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void
Asserts that a string matches a given regular expression.
string
$pattern Regex pattern
string
$string String to test
string
$message optional Message
void
SebastianBergmann\RecursionContext\InvalidArgumentException
assertNan(mixed $actual, string $message = ''): void
Asserts that a variable is nan.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNoRedirect(string $message = ''): void
Asserts that the Location header is not set.
string
$message optional The failure message that will be appended to the generated message.
void
assertNotContains(mixed $needle, iterable $haystack, string $message = ''): void
Asserts that a haystack does not contain a needle.
iterable
$haystack string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertNotContainsEquals(mixed $needle, iterable $haystack, string $message = ''): void
iterable
$haystack string
$message optional void
assertNotContainsOnly(string $type, iterable $haystack, ?bool $isNativeType = null, string $message = ''): void
Asserts that a haystack does not contain only values of a given type.
string
$type iterable
$haystack ?bool
$isNativeType optional string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotCount(int $expectedCount, Countable|iterable $haystack, string $message = ''): void
Asserts the number of elements of an array, Countable or Traversable.
int
$expectedCount Countable|iterable
$haystack string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertNotEmpty(mixed $actual, string $message = ''): void
Asserts that a variable is not empty.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotEquals(mixed $expected, mixed $actual, string $message = ''): void
Asserts that two variables are not equal.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotEqualsCanonicalizing(mixed $expected, mixed $actual, string $message = ''): void
Asserts that two variables are not equal (canonicalizing).
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotEqualsIgnoringCase(mixed $expected, mixed $actual, string $message = ''): void
Asserts that two variables are not equal (ignoring case).
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotEqualsWithDelta(mixed $expected, mixed $actual, float $delta, string $message = ''): void
Asserts that two variables are not equal (with delta).
float
$delta string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotFalse(mixed $condition, string $message = ''): void
Asserts that a condition is not false.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotInstanceOf(string $expected, mixed $actual, string $message = ''): void
Asserts that a variable is not of a given type.
string
$expected string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertNotIsReadable(string $filename, string $message = ''): void
Asserts that a file/dir exists and is not readable.
string
$filename string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotIsWritable(string $filename, string $message = ''): void
Asserts that a file/dir exists and is not writable.
string
$filename string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotNull(mixed $actual, string $message = ''): void
Asserts that a variable is not null.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotRegExp(string $pattern, string $string, string $message = ''): void
Asserts that a string does not match a given regular expression.
string
$pattern string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotSame(mixed $expected, mixed $actual, string $message = ''): void
Asserts that two variables do not have the same type and value. Used on objects, it asserts that two variables do not reference the same object.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotSameSize(Countable|iterable $expected, Countable|iterable $actual, string $message = ''): void
Assert that the size of two arrays (or Countable
or Traversable
objects) is not the same.
Countable|iterable
$expected Countable|iterable
$actual string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertNotTrue(mixed $condition, string $message = ''): void
Asserts that a condition is not true.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
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 optional the text to display if the assertion is not correct
void
assertNull(mixed $actual, string $message = ''): void
Asserts that a variable is null.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertObjectEquals(object $expected, object $actual, string $method = 'equals', string $message = ''): void
object
$expected object
$actual string
$method optional string
$message optional void
ExpectationFailedException
assertObjectHasAttribute(string $attributeName, object $object, string $message = ''): void
Asserts that an object has a specified attribute.
string
$attributeName object
$object string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertObjectNotHasAttribute(string $attributeName, object $object, string $message = ''): void
Asserts that an object does not have a specified attribute.
string
$attributeName object
$object string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertPathEquals(string $expected, string $result, string $message = ''): void
Compatibility function to test paths.
string
$expected string
$result string
$message optional the text to display if the assertion is not correct
void
assertPostConditions(): void
Performs assertions shared by all tests of a test case.
This method is called between test and tearDown().
void
assertPreConditions(): void
Performs assertions shared by all tests of a test case.
This method is called between setUp() and test.
void
assertRedirect(array|string|null $url = null, string $message = ''): void
Asserts that the Location header is correct. Comparison is made against a full URL.
array|string|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.
void
assertRedirectContains(string $url, string $message = ''): void
Asserts that the Location header contains a substring
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.
void
assertRedirectEquals(array|string|null $url = null, string $message = ''): void
Asserts that the Location header is correct. Comparison is made against exactly the URL provided.
array|string|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.
void
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 optional The failure message that will be appended to the generated message.
void
assertRegExp(string $pattern, string $string, string $message = ''): void
Asserts that a string matches a given regular expression.
string
$pattern string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertRegExpSql(string $pattern, string $actual, bool $optional = false): void
Assertion for comparing a regex pattern against a query having its identifiers quoted. It accepts queries quoted with the characters <
and >
. If the third parameter is set to true, it will alter the pattern to both accept quoted and unquoted queries
string
$pattern The expected sql pattern
string
$actual The sql to compare
bool
$optional optional Whether quote characters (marked with <>) are optional
void
assertResponseCode(int $code, string $message = ''): void
Asserts a specific response status code.
int
$code Status code to assert.
string
$message optional Custom message for failure.
void
assertResponseContains(string $content, string $message = '', bool $ignoreCase = false): void
Asserts content exists in the response body.
string
$content The content to check for.
string
$message optional The failure message that will be appended to the generated message.
bool
$ignoreCase optional A flag to check whether we should ignore case or not.
void
assertResponseEmpty(string $message = ''): void
Assert response content is empty.
string
$message optional The failure message that will be appended to the generated message.
void
assertResponseEquals(mixed $content, string $message = ''): void
Asserts content in the response body equals.
mixed
$content The content to check for.
string
$message optional The failure message that will be appended to the generated message.
void
assertResponseError(string $message = ''): void
Asserts that the response status code is in the 4xx range.
string
$message optional Custom message for failure.
void
assertResponseFailure(string $message = ''): void
Asserts that the response status code is in the 5xx range.
string
$message optional Custom message for failure.
void
assertResponseNotContains(string $content, string $message = '', bool $ignoreCase = false): void
Asserts content does not exist in the response body.
string
$content The content to check for.
string
$message optional The failure message that will be appended to the generated message.
bool
$ignoreCase optional A flag to check whether we should ignore case or not.
void
assertResponseNotEmpty(string $message = ''): void
Assert response content is not empty.
string
$message optional The failure message that will be appended to the generated message.
void
assertResponseNotEquals(mixed $content, string $message = ''): void
Asserts content in the response body not equals.
mixed
$content The content to check for.
string
$message optional The failure message that will be appended to the generated message.
void
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 optional The failure message that will be appended to the generated message.
void
assertResponseOk(string $message = ''): void
Asserts that the response status code is in the 2xx range.
string
$message optional Custom message for failure.
void
assertResponseRegExp(string $pattern, string $message = ''): void
Asserts that the response body matches a given regular expression.
string
$pattern The pattern to compare against.
string
$message optional The failure message that will be appended to the generated message.
void
assertResponseSuccess(string $message = ''): void
Asserts that the response status code is in the 2xx/3xx range.
string
$message optional Custom message for failure.
void
assertSame(mixed $expected, mixed $actual, string $message = ''): void
Asserts that two variables have the same type and value. Used on objects, it asserts that two variables reference the same object.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertSameSize(Countable|iterable $expected, Countable|iterable $actual, string $message = ''): void
Assert that the size of two arrays (or Countable
or Traversable
objects) is the same.
Countable|iterable
$expected Countable|iterable
$actual string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertSession(mixed $expected, string $path, string $message = ''): void
Asserts session contents
mixed
$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.
void
assertSessionHasKey(string $path, string $message = ''): void
Asserts session key exists.
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.
void
assertSessionNotHasKey(string $path, string $message = ''): void
Asserts a session key does not exist.
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.
void
assertStringContainsString(string $needle, string $haystack, string $message = ''): void
string
$needle string
$haystack string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringContainsStringIgnoringCase(string $needle, string $haystack, string $message = ''): void
string
$needle string
$haystack string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringEndsNotWith(string $suffix, string $string, string $message = ''): void
Asserts that a string ends not with a given suffix.
string
$suffix string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringEndsWith(string $suffix, string $string, string $message = ''): void
Asserts that a string ends with a given suffix.
string
$suffix string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringEqualsFile(string $expectedFile, string $actualString, string $message = ''): void
Asserts that the contents of a string is equal to the contents of a file.
string
$expectedFile string
$actualString string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = ''): void
Asserts that the contents of a string is equal to the contents of a file (canonicalizing).
string
$expectedFile string
$actualString string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringEqualsFileIgnoringCase(string $expectedFile, string $actualString, string $message = ''): void
Asserts that the contents of a string is equal to the contents of a file (ignoring case).
string
$expectedFile string
$actualString string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringMatchesFormat(string $format, string $string, string $message = ''): void
Asserts that a string matches a given format string.
string
$format string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringMatchesFormatFile(string $formatFile, string $string, string $message = ''): void
Asserts that a string matches a given format file.
string
$formatFile string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringNotContainsString(string $needle, string $haystack, string $message = ''): void
string
$needle string
$haystack string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringNotContainsStringIgnoringCase(string $needle, string $haystack, string $message = ''): void
string
$needle string
$haystack string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringNotEqualsFile(string $expectedFile, string $actualString, string $message = ''): void
Asserts that the contents of a string is not equal to the contents of a file.
string
$expectedFile string
$actualString string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringNotEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = ''): void
Asserts that the contents of a string is not equal to the contents of a file (canonicalizing).
string
$expectedFile string
$actualString string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringNotEqualsFileIgnoringCase(string $expectedFile, string $actualString, string $message = ''): void
Asserts that the contents of a string is not equal to the contents of a file (ignoring case).
string
$expectedFile string
$actualString string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringNotMatchesFormat(string $format, string $string, string $message = ''): void
Asserts that a string does not match a given format string.
string
$format string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringNotMatchesFormatFile(string $formatFile, string $string, string $message = ''): void
Asserts that a string does not match a given format string.
string
$formatFile string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringStartsNotWith(string $prefix, string $string, string $message = ''): void
Asserts that a string starts not with a given prefix.
string
$prefix string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringStartsWith(string $prefix, string $string, string $message = ''): void
Asserts that a string starts with a given prefix.
string
$prefix string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertTemplate(string $content, string $message = ''): void
Asserts that the search string was in the template name.
string
$content The content to check for.
string
$message optional The failure message that will be appended to the generated message.
void
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.
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 the search should be case-sensitive.
void
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 optional The message to use for failure.
void
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 optional The message to use for failure.
void
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 optional The message to use for failure.
void
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.
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 the search should be case-sensitive.
void
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 optional The message to use for failure.
void
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 optional The message to use for failure.
void
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 optional The message to use for failure.
void
assertThat(mixed $value, Constraint $constraint, string $message = ''): void
Evaluates a PHPUnit\Framework\Constraint matcher object.
Constraint
$constraint string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertTrue(mixed $condition, string $message = ''): void
Asserts that a condition is true.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
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 optional the text to display if the assertion is not correct
void
assertXmlFileEqualsXmlFile(string $expectedFile, string $actualFile, string $message = ''): void
Asserts that two XML files are equal.
string
$expectedFile string
$actualFile string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertXmlFileNotEqualsXmlFile(string $expectedFile, string $actualFile, string $message = ''): void
Asserts that two XML files are not equal.
string
$expectedFile string
$actualFile string
$message optional void
PHPUnit\Util\Exception
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertXmlStringEqualsXmlFile(string $expectedFile, DOMDocument|string $actualXml, string $message = ''): void
Asserts that two XML documents are equal.
string
$expectedFile DOMDocument|string
$actualXml string
$message optional void
PHPUnit\Util\Xml\Exception
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertXmlStringEqualsXmlString(DOMDocument|string $expectedXml, DOMDocument|string $actualXml, string $message = ''): void
Asserts that two XML documents are equal.
DOMDocument|string
$expectedXml DOMDocument|string
$actualXml string
$message optional void
PHPUnit\Util\Xml\Exception
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertXmlStringNotEqualsXmlFile(string $expectedFile, DOMDocument|string $actualXml, string $message = ''): void
Asserts that two XML documents are not equal.
string
$expectedFile DOMDocument|string
$actualXml string
$message optional void
PHPUnit\Util\Xml\Exception
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertXmlStringNotEqualsXmlString(DOMDocument|string $expectedXml, DOMDocument|string $actualXml, string $message = ''): void
Asserts that two XML documents are not equal.
DOMDocument|string
$expectedXml DOMDocument|string
$actualXml string
$message optional void
PHPUnit\Util\Xml\Exception
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
at(int $index): InvokedAtIndexMatcher
Returns a matcher that matches when the method is executed at the given index.
int
$index InvokedAtIndexMatcher
atLeast(int $requiredInvocations): InvokedAtLeastCountMatcher
Returns a matcher that matches when the method is executed at least N times.
int
$requiredInvocations InvokedAtLeastCountMatcher
atLeastOnce(): InvokedAtLeastOnceMatcher
Returns a matcher that matches when the method is executed at least once.
InvokedAtLeastOnceMatcher
atMost(int $allowedInvocations): InvokedAtMostCountMatcher
Returns a matcher that matches when the method is executed at most N times.
int
$allowedInvocations InvokedAtMostCountMatcher
callback(callable $callback): Callback
callable
$callback Callback
classHasAttribute(string $attributeName): ClassHasAttribute
string
$attributeName ClassHasAttribute
classHasStaticAttribute(string $attributeName): ClassHasStaticAttribute
string
$attributeName ClassHasStaticAttribute
cleanup(): void
Clears the state used for requests.
void
cleanupContainer(): void
Clears any mocks that were defined and cleans up application class configuration.
void
clearPlugins(): void
Clear all plugins from the global plugin collection.
Useful in test case teardown methods.
void
configApplication(string $class, array|null $constructorArgs): void
Configure the application class to use in integration tests.
string
$class The application class name.
array|null
$constructorArgs The constructor arguments for your application class.
void
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. Sub-keys like 'headers' will be reset, though.
array
$data The request data to use.
void
containsEqual(mixed $value): TraversableContainsEqual
TraversableContainsEqual
containsIdentical(mixed $value): TraversableContainsIdentical
TraversableContainsIdentical
containsOnly(string $type): TraversableContainsOnly
string
$type TraversableContainsOnly
containsOnlyInstancesOf(string $className): TraversableContainsOnly
string
$className TraversableContainsOnly
controllerSpy(Cake\Event\EventInterface $event, Cake\Controller\Controller|null $controller = null): void
Adds additional event spies to the controller/view event manager.
Cake\Event\EventInterface
$event A dispatcher event.
Cake\Controller\Controller|null
$controller optional Controller instance.
void
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.
void
cookieEncrypted(string $name, mixed $value, string|false $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|false
$encrypt optional Encryption mode to use.
string|null
$key optional Encryption key used. Defaults to Security.salt.
void
count(): int
int
countOf(int $count): Count
int
$count Count
createApp(): Cake\Core\HttpApplicationInterfaceCake\Core\ConsoleApplicationInterface
Create an application instance.
Uses the configuration set in configApplication()
.
Cake\Core\HttpApplicationInterfaceCake\Core\ConsoleApplicationInterface
createConfiguredMock(string $originalClassName, array $configuration): MockObject
Returns a configured mock object for the specified class.
string
$originalClassName array
$configuration MockObject
createMock(string $originalClassName): MockObject
Returns a mock object for the specified class.
string
$originalClassName MockObject
createPartialMock(string $originalClassName, string[] $methods): MockObject
Returns a partial mock object for the specified class.
string
$originalClassName string[]
$methods MockObject
createResult(): TestResult
Creates a default TestResult object.
TestResult
createStub(string $originalClassName): Stub
Makes configurable stub for the specified class.
string
$originalClassName Stub
createTestProxy(string $originalClassName, array $constructorArguments = []): MockObject
Returns a test proxy for the specified class.
string
$originalClassName array
$constructorArguments optional MockObject
dataName(): int|string
int|string
delete(array|string $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.
array|string
$url The URL to request.
void
deprecated(callable $callable): void
Helper method for check deprecation methods
callable
$callable callable function that will receive asserts
void
directoryExists(): DirectoryExists
DirectoryExists
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.
void
doesNotPerformAssertions(): bool
bool
doubledTypes(): string[]
string[]
enableCsrfToken(string $cookieName = 'csrfToken'): 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.
string
$cookieName optional The name of the csrf token cookie.
void
enableRetainFlashMessages(): void
Calling this method will re-store flash messages into the test session after being removed by the FlashHelper
void
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.
void
equalTo(mixed $value): IsEqual
IsEqual
equalToCanonicalizing(mixed $value): IsEqualCanonicalizing
IsEqualCanonicalizing
equalToIgnoringCase(mixed $value): IsEqualIgnoringCase
IsEqualIgnoringCase
equalToWithDelta(mixed $value, float $delta): IsEqualWithDelta
float
$delta IsEqualWithDelta
exactly(int $count): InvokedCountMatcher
Returns a matcher that matches when the method is executed exactly $count times.
int
$count InvokedCountMatcher
expectDeprecation(): void
void
expectDeprecationMessage(string $message): void
string
$message void
expectDeprecationMessageMatches(string $regularExpression): void
string
$regularExpression void
expectError(): void
void
expectErrorMessage(string $message): void
string
$message void
expectErrorMessageMatches(string $regularExpression): void
string
$regularExpression void
expectException(string $exception): void
string
$exception void
expectExceptionCode(int|string $code): void
int|string
$code void
expectExceptionMessage(string $message): void
string
$message void
expectExceptionMessageMatches(string $regularExpression): void
string
$regularExpression void
expectExceptionObject(Exception $exception): void
Sets up an expectation for an exception to be raised by the code under test. Information for expected exception class, expected exception message, and expected exception code are retrieved from a given Exception object.
Exception
$exception void
expectNotToPerformAssertions(): void
void
expectNotice(): void
void
expectNoticeMessage(string $message): void
string
$message void
expectNoticeMessageMatches(string $regularExpression): void
string
$regularExpression void
expectOutputRegex(string $expectedRegex): void
string
$expectedRegex void
expectOutputString(string $expectedString): void
string
$expectedString void
expectWarning(): void
void
expectWarningMessage(string $message): void
string
$message void
expectWarningMessageMatches(string $regularExpression): void
string
$regularExpression void
extractExceptionMessage(Exception $exception): string
Extract verbose message for existing exception
Exception
$exception Exception to extract
string
extractVerboseMessage(string $message): string
Inspect controller to extract possible causes of the failed assertion
string
$message Original message to use as a base
string
fail(string $message = ''): void
Fails a test with the given message.
string
$message optional void
AssertionFailedError
fetchTable(string|null $alias = null, array<string, mixed> $options = []): Cake\ORM\Table
Convenience method to get a table instance.
string|null
$alias optional The alias name you want to get. Should be in CamelCase format. If null
then the value of $defaultTable property is used.
array<string, mixed>
$options optional The options you want to build the table with. If a table has already been loaded the registry options will be ignored.
Cake\ORM\Table
Cake\Core\Exception\CakeException
fileExists(): FileExists
FileExists
get(array|string $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.
array|string
$url The URL to request.
void
getActualOutput(): string
string
getActualOutputForAssertion(): string
string
getCount(): int
Return the current assertion count.
int
getDataSetAsString(bool $includeData = true): string
bool
$includeData optional string
getExpectedException(): ?string
?string
getExpectedExceptionCode(): null|int|string
null|int|string
getExpectedExceptionMessage(): ?string
?string
getExpectedExceptionMessageRegExp(): ?string
?string
getFixtureStrategy(): Cake\TestSuite\Fixture\FixtureStrategyInterface
Returns fixture strategy used by these tests.
Cake\TestSuite\Fixture\FixtureStrategyInterface
getFixtures(): array<string>
Get the fixtures this test should use.
array<string>
getGroups(): array
array
getMockBuilder(string $className): MockBuilder
Returns a builder object to create mock objects using a fluent interface.
string
$className MockBuilder
getMockClass(string $originalClassName, null|array $methods = [], array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = false, bool $callOriginalClone = true, bool $callAutoload = true, bool $cloneArguments = false): string
Mocks the specified class and returns the name of the mocked class.
string
$originalClassName null|array
$methods optional $methods
array
$arguments optional string
$mockClassName optional bool
$callOriginalConstructor optional bool
$callOriginalClone optional bool
$callAutoload optional bool
$cloneArguments optional string
getMockForAbstractClass(string $originalClassName, array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, array $mockedMethods = [], bool $cloneArguments = false): MockObject
Returns a mock object for the specified abstract class with all abstract methods of the class mocked. Concrete methods are not mocked by default. To mock concrete methods, use the 7th parameter ($mockedMethods).
string
$originalClassName array
$arguments optional string
$mockClassName optional bool
$callOriginalConstructor optional bool
$callOriginalClone optional bool
$callAutoload optional array
$mockedMethods optional bool
$cloneArguments optional MockObject
getMockForModel(string $alias, array<string> $methods = [], array<string, mixed> $options = []): Cake\ORM\TablePHPUnit\Framework\MockObject\MockObject
Mock a model, maintain fixtures and table association
string
$alias The model to get a mock for.
array<string>
$methods optional The list of methods to mock
array<string, mixed>
$options optional The config data for the mock's constructor.
Cake\ORM\TablePHPUnit\Framework\MockObject\MockObject
Cake\ORM\Exception\MissingTableClassException
getMockForTrait(string $traitName, array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, array $mockedMethods = [], bool $cloneArguments = false): MockObject
Returns a mock object for the specified trait with all abstract methods of the trait mocked. Concrete methods to mock can be specified with the $mockedMethods
parameter.
string
$traitName array
$arguments optional string
$mockClassName optional bool
$callOriginalConstructor optional bool
$callOriginalClone optional bool
$callAutoload optional array
$mockedMethods optional bool
$cloneArguments optional MockObject
getMockFromWsdl(string $wsdlFile, string $originalClassName = '', string $mockClassName = '', array $methods = [], bool $callOriginalConstructor = true, array $options = []): MockObject
Returns a mock object based on the given WSDL file.
string
$wsdlFile string
$originalClassName optional string
$mockClassName optional array
$methods optional bool
$callOriginalConstructor optional array
$options optional MockObject
getName(bool $withDataSet = true): string
bool
$withDataSet optional string
SebastianBergmann\RecursionContext\InvalidArgumentException
getNumAssertions(): int
Returns the number of assertions performed by this test.
int
getObjectForTrait(string $traitName, array $arguments = [], string $traitClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true): object
Returns an object for the specified trait.
string
$traitName array
$arguments optional string
$traitClassName optional bool
$callOriginalConstructor optional bool
$callOriginalClone optional bool
$callAutoload optional object
getProvidedData(): array
Gets the data set of a TestCase.
array
getResult()
getSession(): Cake\TestSuite\TestSession
Cake\TestSuite\TestSession
getSize(): int
Returns the size of the test.
int
SebastianBergmann\RecursionContext\InvalidArgumentException
getStatus(): int
int
getStatusMessage(): string
string
getTableLocator(): Cake\ORM\Locator\LocatorInterface
Gets the table locator.
Cake\ORM\Locator\LocatorInterface
getTestResultObject(): ?TestResult
?TestResult
greaterThan(mixed $value): GreaterThan
GreaterThan
greaterThanOrEqual(mixed $value): LogicalOr
LogicalOr
hasExpectationOnOutput(): bool
bool
hasFailed(): bool
bool
hasOutput(): bool
bool
hasSize(): bool
bool
SebastianBergmann\RecursionContext\InvalidArgumentException
head(array|string $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.
array|string
$url The URL to request.
void
identicalTo(mixed $value): IsIdentical
IsIdentical
iniSet(string $varName, string $newValue): void
This method is a wrapper for the ini_set() function that automatically resets the modified php.ini setting to its original value after the test is run.
string
$varName string
$newValue void
Exception
isEmpty(): IsEmpty
IsEmpty
isFalse(): IsFalse
IsFalse
isFinite(): IsFinite
IsFinite
isInIsolation(): bool
bool
isInfinite(): IsInfinite
IsInfinite
isInstanceOf(string $className): IsInstanceOf
string
$className IsInstanceOf
isJson(): IsJson
IsJson
isLarge(): bool
bool
SebastianBergmann\RecursionContext\InvalidArgumentException
isMedium(): bool
bool
SebastianBergmann\RecursionContext\InvalidArgumentException
isNan(): IsNan
IsNan
isNull(): IsNull
IsNull
isReadable(): IsReadable
IsReadable
isSmall(): bool
bool
SebastianBergmann\RecursionContext\InvalidArgumentException
isTrue(): IsTrue
IsTrue
isType(string $type): IsType
string
$type IsType
isWritable(): IsWritable
IsWritable
lessThan(mixed $value): LessThan
LessThan
lessThanOrEqual(mixed $value): LogicalOr
LogicalOr
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.
void
RuntimeException
loadPlugins(array<string, mixed> $plugins = []): 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<string, mixed>
$plugins optional List of Plugins to load.
Cake\Http\BaseApplication
loadRoutes(array|null $appArgs = null): void
Load routes for the application.
If no application class can be found an exception will be raised. Routes for plugins will not be loaded. Use loadPlugins()
or use Cake\TestSuite\IntegrationTestCaseTrait
to better simulate all routes and plugins being loaded.
array|null
$appArgs optional Constructor parameters for the application class.
void
logicalAnd(): LogicalAnd
LogicalAnd
Exception
logicalNot(Constraint $constraint): LogicalNot
Constraint
$constraint LogicalNot
logicalOr(): LogicalOr
LogicalOr
logicalXor(): LogicalXor
LogicalXor
markAsRisky(): void
void
markTestIncomplete(string $message = ''): void
Mark the test as incomplete.
string
$message optional void
IncompleteTestError
markTestSkipped(string $message = ''): void
Mark the test as skipped.
string
$message optional void
SkippedTestError
SyntheticSkippedError
matches(string $string): StringMatchesFormatDescription
string
$string StringMatchesFormatDescription
matchesRegularExpression(string $pattern): RegularExpression
string
$pattern RegularExpression
mockService(string $class, Closure $factory): $this
Add a mocked service to the container.
When the container is created the provided classname will be mapped to the factory function. The factory function will be used to create mocked services.
string
$class The class or interface you want to define.
Closure
$factory The factory function for mocked services.
$this
modifyContainer(Cake\Event\EventInterface $event, Cake\Core\ContainerInterface $container): Cake\Core\ContainerInterface|null
Wrap the application's container with one containing mocks.
If any mocked services are defined, the application's container will be replaced with one containing mocks. The original container will be set as a delegate to the mock container.
Cake\Event\EventInterface
$event The event
Cake\Core\ContainerInterface
$container The container to wrap.
Cake\Core\ContainerInterface|null
never(): InvokedCountMatcher
Returns a matcher that matches when the method is never executed.
InvokedCountMatcher
objectEquals(object $object, string $method = 'equals'): ObjectEquals
object
$object string
$method optional ObjectEquals
objectHasAttribute(mixed $attributeName): ObjectHasAttribute
ObjectHasAttribute
onConsecutiveCalls(mixed ...$args): ConsecutiveCallsStub
ConsecutiveCallsStub
onNotSuccessfulTest(Throwable $t): void
This method is called when a test method did not execute successfully.
Throwable
$t void
Throwable
once(): InvokedCountMatcher
Returns a matcher that matches when the method is executed exactly once.
InvokedCountMatcher
options(array|string $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.
array|string
$url The URL to request.
void
patch(array|string $url, array|string $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.
array|string
$url The URL to request.
array|string
$data optional The data for the request.
void
post(array|string $url, array|string $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.
array|string
$url The URL to request.
array|string
$data optional The data for the request.
void
prophesize(?string $classOrInterface = null): ObjectProphecy
?string
$classOrInterface optional ObjectProphecy
Prophecy\Exception\Doubler\ClassNotFoundException
Prophecy\Exception\Doubler\DoubleException
Prophecy\Exception\Doubler\InterfaceNotFoundException
provides(): list<ExecutionOrderDependency>
Returns the normalized test name as class::method.
list<ExecutionOrderDependency>
put(array|string $url, array|string $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.
array|string
$url The URL to request.
array|string
$data optional The data for the request.
void
recordDoubledType(string $originalClassName): void
string
$originalClassName void
registerComparator(Comparator $comparator): void
Comparator
$comparator void
registerMockObject(MockObject $mockObject): void
MockObject
$mockObject void
removeMockService(string $class): $this
Remove a mocked service to the container.
string
$class The class or interface you want to remove.
$this
removePlugins(array<string> $names = []): void
Remove plugins from the global plugin collection.
Useful in test case teardown methods.
array<string>
$names optional A list of plugins you want to remove.
void
requires(): list<ExecutionOrderDependency>
Returns a list of normalized dependency names, class::method.
This list can differ from the raw dependencies as the resolver has no need for the [!][shallow]clone prefix that is filtered out during normalization.
list<ExecutionOrderDependency>
resetCount(): void
Reset the assertion counter.
void
returnArgument(int $argumentIndex): ReturnArgumentStub
int
$argumentIndex ReturnArgumentStub
returnCallback(mixed $callback): ReturnCallbackStub
ReturnCallbackStub
returnSelf(): ReturnSelfStub
Returns the current object.
This method is useful when mocking a fluent interface.
ReturnSelfStub
returnValue(mixed $value): ReturnStub
ReturnStub
returnValueMap(array $valueMap): ReturnValueMapStub
array
$valueMap ReturnValueMapStub
run(TestResult $result = null): TestResult
Runs the test case and collects the results in a TestResult object. If no TestResult object is passed a new one will be created.
TestResult
$result optional TestResult
SebastianBergmann\CodeCoverage\InvalidArgumentException
SebastianBergmann\CodeCoverage\UnintentionallyCoveredCodeException
SebastianBergmann\RecursionContext\InvalidArgumentException
CodeCoverageException
UtilException
runBare(): void
void
Throwable
runTest()
Override to run the test and assert its state.
SebastianBergmann\ObjectEnumerator\InvalidArgumentException
AssertionFailedError
Exception
ExpectationFailedException
Throwable
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.
void
setAppNamespace(string $appNamespace = 'TestApp'): string|null
Set the app namespace
string
$appNamespace optional The app namespace, defaults to "TestApp".
string|null
setBackupGlobals(?bool $backupGlobals): void
?bool
$backupGlobals void
setBackupStaticAttributes(?bool $backupStaticAttributes): void
?bool
$backupStaticAttributes void
setBeStrictAboutChangesToGlobalState(?bool $beStrictAboutChangesToGlobalState): void
?bool
$beStrictAboutChangesToGlobalState void
setDependencies(list<ExecutionOrderDependency> $dependencies): void
list<ExecutionOrderDependency>
$dependencies void
setDependencyInput(array $dependencyInput): void
array
$dependencyInput void
setGroups(array $groups): void
array
$groups void
setInIsolation(bool $inIsolation): void
bool
$inIsolation void
setLocale(mixed ...$args): void
This method is a wrapper for the setlocale() function that automatically resets the locale to its original value after the test is run.
void
Exception
setName(string $name): void
string
$name void
setOutputCallback(callable $callback): void
callable
$callback void
setPreserveGlobalState(bool $preserveGlobalState): void
bool
$preserveGlobalState void
setRegisterMockObjectsFromTestArgumentsRecursively(bool $flag): void
bool
$flag void
setResult(mixed $result): void
void
setRunClassInSeparateProcess(bool $runClassInSeparateProcess): void
bool
$runClassInSeparateProcess void
setRunTestInSeparateProcess(bool $runTestInSeparateProcess): void
bool
$runTestInSeparateProcess void
setTableLocator(Cake\ORM\Locator\LocatorInterface $tableLocator): $this
Sets the table locator.
Cake\ORM\Locator\LocatorInterface
$tableLocator LocatorInterface instance.
$this
setTestResultObject(TestResult $result): void
TestResult
$result void
setUnlockedFields(array<string> $unlockedFields = []): void
Set list of fields that are excluded from field validation.
array<string>
$unlockedFields optional List of fields that are excluded from field validation.
void
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.
void
setUpBeforeClass(): void
This method is called before the first test of this test class is run.
void
setupFixtures(): void
Initialized and loads any use fixtures.
void
skipIf(bool $shouldSkip, string $message = ''): bool
Overrides SimpleTestCase::skipIf to provide a boolean return value
bool
$shouldSkip Whether the test should be skipped.
string
$message optional The message to display.
bool
skipUnless(bool $condition, string $message = ''): bool
Compatibility function for skipping.
bool
$condition Condition to trigger skipping
string
$message optional Message for skip
bool
sortId(): string
string
stringContains(string $string, bool $case = true): StringContains
string
$string bool
$case optional StringContains
stringEndsWith(string $suffix): StringEndsWith
string
$suffix StringEndsWith
stringStartsWith(mixed $prefix): StringStartsWith
StringStartsWith
tearDown(): void
teardown any static object changes and restore them.
void
tearDownAfterClass(): void
This method is called after the last test of this test class is run.
void
teardownFixtures(): void
Unloads any use fixtures.
void
throwException(Throwable $exception): ExceptionStub
Throwable
$exception ExceptionStub
toString(): string
Returns a string representation of the test case.
string
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
useHttpServer(bool $enable): void
No-op method.
bool
$enable Unused.
void
usesDataProvider(): bool
bool
viewVariable(string $name): mixed
Fetches a view variable by name.
If the view variable does not exist, null will be returned.
string
$name The view variable to get.
mixed
withErrorReporting(int $errorLevel, callable $callable): void
Helper method for tests that needs to use error_reporting()
int
$errorLevel value of error_reporting() that needs to use
callable
$callable callable function that will receive asserts
void
The customized application constructor arguments.
array|null
The customized application class name.
string|null
Configure values to restore at end of test.
array
The controller used in the last request.
Cake\Controller\Controller|null
Cookie data to use in the next request.
array
string|null
The name that will be used when retrieving the csrf token.
string
Boolean flag for whether the request should have a CSRF token added.
bool
The exception being thrown if the case.
Throwable|null
Stored flash messages before render
array
The last rendered layout
string
The data used to build the next request.
array
The session instance from the last request
Cake\Http\Session
The response for the most recent request.
Psr\Http\Message\ResponseInterface|null
Boolean flag for whether the request should re-store flash messages
bool
Boolean flag for whether the request should have a SecurityComponent token added.
bool
Session data to use in the next request.
array
Table locator instance
Cake\ORM\Locator\LocatorInterface|null
List of fields that are excluded from field validation.
array<string>
Valid cipher names for encrypted cookies.
array<string>
The last rendered view
string
By default, all fixtures attached to this class will be truncated and reloaded after each test. Set this to false to handle manually
bool
?bool
string[]
string[]
bool
array<string, array<int, string>>
array<string, array<int, string>>
This object's default table alias.
string|null
Control table create/drops on each test method.
If true, tables will still be dropped at the end of each test runner execution.
bool
The class responsible for managing the creation, loading and removing of fixtures
Cake\TestSuite\Fixture\FixtureManager|null
Cake\TestSuite\Fixture\FixtureStrategyInterface|null
Fixtures used by this test case.
array<string>
bool
list<ExecutionOrderDependency>
bool
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/class-Cake.TestSuite.IntegrationTestCase.html