Class
IntegrationTestCase
A test case class intended to make integration tests of your controllers easier.
This test class provides a number of helper methods and features that make dispatching requests and checking their responses simpler. It favours full integration tests over mock objects as you can test more of your code easily and avoid some of the maintenance pitfalls that mock objects create.
Namespace: Cake\TestSuite
Deprecated: 3.7.0 Use Cake\TestSuite\IntegrationTestTrait instead
Property Summary
-
$_appArgs protected
array|null
The customized application constructor arguments.
-
$_appClass protected
string|null
The customized application class name.
-
$_configure protected
array
Configure values to restore at end of test.
-
$_controller protected
Cake\Controller\Controller|null
The controller used in the last request.
-
$_cookie protected
array
Cookie data to use in the next request.
-
$_cookieEncryptionKey protected
string|null
-
$_csrfToken protected
bool
Boolean flag for whether or not the request should have a CSRF token added.
-
$_exception protected
Exception|null
The exception being thrown if the case.
-
$_flashMessages protected
array|null
Stored flash messages before render
-
$_layoutName protected
string|null
The last rendered layout
-
$_request protected
array
The data used to build the next request.
-
$_requestSession protected
Cake\Http\Session|null
The session instance from the last request
-
$_response protected
Cake\Http\Response|null
The response for the most recent request.
-
$_retainFlashMessages protected
bool
Boolean flag for whether or not the request should re-store flash messages
-
$_securityToken protected
bool
Boolean flag for whether or not the request should have a SecurityComponent token added.
-
$_session protected
array
Session data to use in the next request.
-
$_tableLocator protected
Cake\ORM\Locator\LocatorInterface
Table locator instance
-
$_unlockedFields protected
string[]
List of fields that are excluded from field validation.
-
$_useHttpServer protected
bool
Track whether or not tests are run against the PSR7 HTTP stack.
-
$_validCiphers protected
string[]
Valid cipher names for encrypted cookies.
-
$_viewName protected
string|null
The last rendered view
-
$autoFixtures public
bool
By default, all fixtures attached to this class will be truncated and reloaded after each test. Set this to false to handle manually
-
$backupGlobals protected
bool
Enable or disable the backup and restoration of the $GLOBALS array. Overwrite this attribute in a child class of TestCase. Setting this attribute in setUp() has no effect!
-
$backupGlobalsBlacklist protected
array
-
$backupStaticAttributes protected
bool
Enable or disable the backup and restoration of static attributes. Overwrite this attribute in a child class of TestCase. Setting this attribute in setUp() has no effect!
-
$backupStaticAttributesBlacklist protected
array
-
$dropTables public
bool
Control table create/drops on each test method.
-
$fixtureManager public
Cake\TestSuite\Fixture\FixtureManager|null
The class responsible for managing the creation, loading and removing of fixtures
-
$fixtures public
string[]|string|null
Fixtures used by this test case.
-
$preserveGlobalState protected
bool
Whether or not this test should preserve the global state when running in a separate PHP process.
-
$runTestInSeparateProcess protected
bool
Whether or not this test is to be run in a separate PHP process.
Method Summary
-
__construct() public
Constructs a test case with the given name.
-
_addTokens() protected
Add the CSRF and Security Component tokens if necessary.
-
_assertAttributes() protected
Check the attributes as part of an assertTags() check.
-
_buildFieldToken() protected
Generate the token data for the provided inputs.
-
_buildRequest() protected
Creates a request object with the configured options and parameters.
-
_castToString() protected
Recursively casts all data to string as that is how data would be POSTed in the real world
-
_checkCipher() protected
Helper method for validating encryption cipher names.
-
_decode() protected
Decodes and decrypts a single value.
-
_decrypt() protected
Decrypts $value using public $type method in Security class
-
_encrypt() protected
Encrypts $value using public $type method in Security class
-
_explode() protected
Explode method to return array from string set in CookieComponent::_implode() Maintains reading backwards compatibility with 1.x CookieComponent::_implode().
-
_getBodyAsString() protected
Get the response body as string
-
_getCookieEncryptionKey() protected
Returns the encryption key to be used.
-
_getTableClassName() protected
Gets the class name for the table.
-
_handleError() protected
Attempts to render an error response for a given exception.
-
_implode() protected
Implode method to keep keys are multidimensional arrays
-
_makeDispatcher() protected
Get the correct dispatcher instance.
-
_normalizePath() protected
Normalize a path for comparison.
-
_sendRequest() protected
Creates and send the request into a Dispatcher instance.
-
_url() protected
Creates a valid request url and parameter array more like Request::_url()
-
addFixture() protected
Adds a fixture to this test case.
-
addToAssertionCount() public
Adds a value to the assertion counter.
-
any() public static
Returns a matcher that matches when the method is executed zero or more times.
-
anything() public static
-
arrayHasKey() public static
-
assertArrayHasKey() public static
Asserts that an array has a specified key.
-
assertArrayNotHasKey() public static
Asserts that an array does not have a specified key.
-
assertArraySubset() public static
Asserts that an array has a specified subset.
-
assertAttributeContains() public static
Asserts that a haystack that is stored in a static attribute of a class or an attribute of an object contains a needle.
-
assertAttributeContainsOnly() public static
Asserts that a haystack that is stored in a static attribute of a class or an attribute of an object contains only values of a given type.
-
assertAttributeCount() public static
Asserts the number of elements of an array, Countable or Traversable that is stored in an attribute.
-
assertAttributeEmpty() public static
Asserts that a static attribute of a class or an attribute of an object is empty.
-
assertAttributeEquals() public static
Asserts that a variable is equal to an attribute of an object.
-
assertAttributeGreaterThan() public static
Asserts that an attribute is greater than another value.
-
assertAttributeGreaterThanOrEqual() public static
Asserts that an attribute is greater than or equal to another value.
-
assertAttributeInstanceOf() public static
Asserts that an attribute is of a given type.
-
assertAttributeInternalType() public static
Asserts that an attribute is of a given type.
-
assertAttributeLessThan() public static
Asserts that an attribute is smaller than another value.
-
assertAttributeLessThanOrEqual() public static
Asserts that an attribute is smaller than or equal to another value.
-
assertAttributeNotContains() public static
Asserts that a haystack that is stored in a static attribute of a class or an attribute of an object does not contain a needle.
-
assertAttributeNotContainsOnly() public static
Asserts that a haystack that is stored in a static attribute of a class or an attribute of an object does not contain only values of a given type.
-
assertAttributeNotCount() public static
Asserts the number of elements of an array, Countable or Traversable that is stored in an attribute.
-
assertAttributeNotEmpty() public static
Asserts that a static attribute of a class or an attribute of an object is not empty.
-
assertAttributeNotEquals() public static
Asserts that a variable is not equal to an attribute of an object.
-
assertAttributeNotInstanceOf() public static
Asserts that an attribute is of a given type.
-
assertAttributeNotInternalType() public static
Asserts that an attribute is of a given type.
-
assertAttributeNotSame() public static
Asserts that a variable and an attribute of an object do not have the same type and value.
-
assertAttributeSame() public static
Asserts that a variable and an attribute of an object have the same type and value.
-
assertClassHasAttribute() public static
Asserts that a class has a specified attribute.
-
assertClassHasStaticAttribute() public static
Asserts that a class has a specified static attribute.
-
assertClassNotHasAttribute() public static
Asserts that a class does not have a specified attribute.
-
assertClassNotHasStaticAttribute() public static
Asserts that a class does not have a specified static attribute.
-
assertContains() public static
Asserts that a haystack contains a needle.
-
assertContainsOnly() public static
Asserts that a haystack contains only values of a given type.
-
assertContainsOnlyInstancesOf() public static
Asserts that a haystack contains only instances of a given classname
-
assertContentType() public
Asserts content type
-
assertCookie() public
Asserts cookie values
-
assertCookieEncrypted() public
Asserts cookie values which are encrypted by the CookieComponent.
-
assertCookieNotSet() public
Asserts a cookie has not been set in the response
-
assertCount() public static
Asserts the number of elements of an array, Countable or Traversable.
-
assertDirectoryExists() public static
Asserts that a directory exists.
-
assertDirectoryIsReadable() public static
Asserts that a directory exists and is readable.
-
assertDirectoryIsWritable() public static
Asserts that a directory exists and is writable.
-
assertDirectoryNotExists() public static
Asserts that a directory does not exist.
-
assertDirectoryNotIsReadable() public static
Asserts that a directory exists and is not readable.
-
assertDirectoryNotIsWritable() public static
Asserts that a directory exists and is not writable.
-
assertEmpty() public static
Asserts that a variable is empty.
-
assertEqualXMLStructure() public static
Asserts that a hierarchy of DOMElements matches.
-
assertEquals() public static
Asserts that two variables are equal.
-
assertEventFired() public
Asserts that a global event was fired. You must track events in your event manager for this assertion to work
-
assertEventFiredWith() public
Asserts an event was fired with data
-
assertFalse() public static
Asserts that a condition is false.
-
assertFileEquals() public static
Asserts that the contents of one file is equal to the contents of another file.
-
assertFileExists() public static
Asserts that a file exists.
-
assertFileIsReadable() public static
Asserts that a file exists and is readable.
-
assertFileIsWritable() public static
Asserts that a file exists and is writable.
-
assertFileNotEquals() public static
Asserts that the contents of one file is not equal to the contents of another file.
-
assertFileNotExists() public static
Asserts that a file does not exist.
-
assertFileNotIsReadable() public static
Asserts that a file exists and is not readable.
-
assertFileNotIsWritable() public static
Asserts that a file exists and is not writable.
-
assertFileResponse() public
Asserts that a file with the given name was sent in the response
-
assertFinite() public static
Asserts that a variable is finite.
-
assertFlashElement() public
Asserts a flash element was set
-
assertFlashElementAt() public
Asserts a flash element was set at a certain index
-
assertFlashMessage() public
Asserts a flash message was set
-
assertFlashMessageAt() public
Asserts a flash message was set at a certain index
-
assertGreaterThan() public static
Asserts that a value is greater than another value.
-
assertGreaterThanOrEqual() public static
Asserts that a value is greater than or equal to another value.
-
assertHeader() public
Asserts response headers
-
assertHeaderContains() public
Asserts response header contains a string
-
assertHeaderNotContains() public
Asserts response header does not contain a string
-
assertHtml() public
Asserts HTML tags.
-
assertInfinite() public static
Asserts that a variable is infinite.
-
assertInstanceOf() public static
Asserts that a variable is of a given type.
-
assertInternalType() public static
Asserts that a variable is of a given type.
-
assertIsReadable() public static
Asserts that a file/dir is readable.
-
assertIsWritable() public static
Asserts that a file/dir exists and is writable.
-
assertJson() public static
Asserts that a string is a valid JSON string.
-
assertJsonFileEqualsJsonFile() public static
Asserts that two JSON files are equal.
-
assertJsonFileNotEqualsJsonFile() public static
Asserts that two JSON files are not equal.
-
assertJsonStringEqualsJsonFile() public static
Asserts that the generated JSON encoded object and the content of the given file are equal.
-
assertJsonStringEqualsJsonString() public static
Asserts that two given JSON encoded objects or arrays are equal.
-
assertJsonStringNotEqualsJsonFile() public static
Asserts that the generated JSON encoded object and the content of the given file are not equal.
-
assertJsonStringNotEqualsJsonString() public static
Asserts that two given JSON encoded objects or arrays are not equal.
-
assertLayout() public
Asserts that the search string was in the layout name.
-
assertLessThan() public static
Asserts that a value is smaller than another value.
-
assertLessThanOrEqual() public static
Asserts that a value is smaller than or equal to another value.
-
assertNan() public static
Asserts that a variable is nan.
-
assertNoRedirect() public
Asserts that the Location header is not set.
-
assertNotContains() public static
Asserts that a haystack does not contain a needle.
-
assertNotContainsOnly() public static
Asserts that a haystack does not contain only values of a given type.
-
assertNotCount() public static
Asserts the number of elements of an array, Countable or Traversable.
-
assertNotEmpty() public static
Asserts that a variable is not empty.
-
assertNotEquals() public static
Asserts that two variables are not equal.
-
assertNotFalse() public static
Asserts that a condition is not false.
-
assertNotInstanceOf() public static
Asserts that a variable is not of a given type.
-
assertNotInternalType() public static
Asserts that a variable is not of a given type.
-
assertNotIsReadable() public static
Asserts that a file/dir exists and is not readable.
-
assertNotIsWritable() public static
Asserts that a file/dir exists and is not writable.
-
assertNotNull() public static
Asserts that a variable is not null.
-
assertNotRegExp() public static
Asserts that a string does not match a given regular expression.
-
assertNotSame() public static
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.
-
assertNotSameSize() public static
Assert that the size of two arrays (or
Countable
orTraversable
objects) is not the same. -
assertNotTrue() public static
Asserts that a condition is not true.
-
assertNotWithinRange() protected static
Compatibility function to test if a value is not between an acceptable range.
-
assertNull() public static
Asserts that a variable is null.
-
assertObjectHasAttribute() public static
Asserts that an object has a specified attribute.
-
assertObjectNotHasAttribute() public static
Asserts that an object does not have a specified attribute.
-
assertPathEquals() protected static
Compatibility function to test paths.
-
assertPostConditions() protected
Performs assertions shared by all tests of a test case.
-
assertPreConditions() protected
Performs assertions shared by all tests of a test case.
-
assertRedirect() public
Asserts that the Location header is correct. Comparison is made against a full URL.
-
assertRedirectContains() public
Asserts that the Location header contains a substring
-
assertRedirectEquals() public
Asserts that the Location header is correct. Comparison is made against exactly the URL provided.
-
assertRedirectNotContains() public
Asserts that the Location header does not contain a substring
-
assertRegExp() public static
Asserts that a string matches a given regular expression.
-
assertResponseCode() public
Asserts a specific response status code.
-
assertResponseContains() public
Asserts content exists in the response body.
-
assertResponseEmpty() public
Assert response content is empty.
-
assertResponseEquals() public
Asserts content in the response body equals.
-
assertResponseError() public
Asserts that the response status code is in the 4xx range.
-
assertResponseFailure() public
Asserts that the response status code is in the 5xx range.
-
assertResponseNotContains() public
Asserts content does not exist in the response body.
-
assertResponseNotEmpty() public
Assert response content is not empty.
-
assertResponseNotEquals() public
Asserts content in the response body not equals.
-
assertResponseNotRegExp() public
Asserts that the response body does not match a given regular expression.
-
assertResponseOk() public
Asserts that the response status code is in the 2xx range.
-
assertResponseRegExp() public
Asserts that the response body matches a given regular expression.
-
assertResponseSuccess() public
Asserts that the response status code is in the 2xx/3xx range.
-
assertSame() public static
Asserts that two variables have the same type and value. Used on objects, it asserts that two variables reference the same object.
-
assertSameSize() public static
Assert that the size of two arrays (or
Countable
orTraversable
objects) is the same. -
assertSession() public
Asserts session contents
-
assertStringEndsNotWith() public static
Asserts that a string ends not with a given suffix.
-
assertStringEndsWith() public static
Asserts that a string ends with a given suffix.
-
assertStringEqualsFile() public static
Asserts that the contents of a string is equal to the contents of a file.
-
assertStringMatchesFormat() public static
Asserts that a string matches a given format string.
-
assertStringMatchesFormatFile() public static
Asserts that a string matches a given format file.
-
assertStringNotEqualsFile() public static
Asserts that the contents of a string is not equal to the contents of a file.
-
assertStringNotMatchesFormat() public static
Asserts that a string does not match a given format string.
-
assertStringNotMatchesFormatFile() public static
Asserts that a string does not match a given format string.
-
assertStringStartsNotWith() public static
Asserts that a string starts not with a given prefix.
-
assertStringStartsWith() public static
Asserts that a string starts with a given prefix.
-
assertTags() public deprecated
Asserts HTML tags.
-
assertTemplate() public
Asserts that the search string was in the template name.
-
assertTextContains() public
Assert that a string contains another string, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
-
assertTextEndsNotWith() public
Asserts that a string ends not with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
-
assertTextEndsWith() public
Asserts that a string ends with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
-
assertTextEquals() public
Assert text equality, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
-
assertTextNotContains() public
Assert that a text doesn't contain another text, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
-
assertTextNotEquals() public
Assert text equality, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
-
assertTextStartsNotWith() public
Asserts that a string starts not with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
-
assertTextStartsWith() public
Asserts that a string starts with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
-
assertThat() public static
Evaluates a PHPUnit\Framework\Constraint matcher object.
-
assertTrue() public static
Asserts that a condition is true.
-
assertWithinRange() protected static
Compatibility function to test if a value is between an acceptable range.
-
assertXmlFileEqualsXmlFile() public static
Asserts that two XML files are equal.
-
assertXmlFileNotEqualsXmlFile() public static
Asserts that two XML files are not equal.
-
assertXmlStringEqualsXmlFile() public static
Asserts that two XML documents are equal.
-
assertXmlStringEqualsXmlString() public static
Asserts that two XML documents are equal.
-
assertXmlStringNotEqualsXmlFile() public static
Asserts that two XML documents are not equal.
-
assertXmlStringNotEqualsXmlString() public static
Asserts that two XML documents are not equal.
-
at() public static
Returns a matcher that matches when the method is executed at the given index.
-
atLeast() public static
Returns a matcher that matches when the method is executed at least N times.
-
atLeastOnce() public static
Returns a matcher that matches when the method is executed at least once.
-
atMost() public static
Returns a matcher that matches when the method is executed at most N times.
-
attribute() public static
-
attributeEqualTo() public static
-
callback() public static
-
checkRequirements() protected
-
classHasAttribute() public static
-
classHasStaticAttribute() public static
-
cleanup() public
Clears the state used for requests.
-
clearPlugins() public
Clear all plugins from the global plugin collection.
-
configApplication() public
Configure the application class to use in integration tests.
-
configRequest() public
Configures the data for the next request.
-
contains() public static
-
containsOnly() public static
-
containsOnlyInstancesOf() public static
-
controllerSpy() public
Adds additional event spies to the controller/view event manager.
-
cookie() public
Sets a request cookie for future requests.
-
cookieEncrypted() public
Sets a encrypted request cookie for future requests.
-
count() public
Counts the number of test cases executed by run(TestResult result).
-
countOf() public static
-
createConfiguredMock() protected
Returns a configured test double for the specified class.
-
createMock() protected
Returns a test double for the specified class.
-
createPartialMock() protected
Returns a partial test double for the specified class.
-
createResult() protected
Creates a default TestResult object.
-
createTestProxy() protected
Returns a test proxy for the specified class.
-
dataDescription() public
-
dataName() public
-
delete() public
Performs a DELETE request using the current request data.
-
deprecated() public
Helper method for check deprecation methods
-
directoryExists() public static
-
disableErrorHandlerMiddleware() public
Disable the error handler middleware.
-
doesNotPerformAssertions() public
-
enableCsrfToken() public
Calling this method will add a CSRF token to the request.
-
enableRetainFlashMessages() public
Calling this method will re-store flash messages into the test session after being removed by the FlashHelper
-
enableSecurityToken() public
Calling this method will enable a SecurityComponent compatible token to be added to request data. This lets you easily test actions protected by SecurityComponent.
-
equalTo() public static
-
exactly() public static
Returns a matcher that matches when the method is executed exactly $count times.
-
expectException() public
-
expectExceptionCode() public
-
expectExceptionMessage() public
-
expectExceptionMessageRegExp() public
-
expectExceptionObject() public
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.
-
expectOutputRegex() public
-
expectOutputString() public
-
extractExceptionMessage() protected
Extract verbose message for existing exception
-
extractVerboseMessage() protected
Inspect controller to extract possible causes of the failed assertion
-
fail() public static
Fails a test with the given message.
-
fileExists() public static
-
get() public
Performs a GET request using the current request data.
-
getActualOutput() public
-
getAnnotations() public
Returns the annotations for this test.
-
getCount() public static
Return the current assertion count.
-
getDataSetAsString() public
Gets the data set description of a TestCase.
-
getExpectedException() public
-
getExpectedExceptionCode() public
-
getExpectedExceptionMessage() public
-
getExpectedExceptionMessageRegExp() public
-
getFixtures() public
Gets fixtures.
-
getGroups() public
-
getMockBuilder() public
Returns a builder object to create mock objects using a fluent interface.
-
getMockClass() protected
Mocks the specified class and returns the name of the mocked class.
-
getMockForAbstractClass() protected
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).
-
getMockForModel() public
Mock a model, maintain fixtures and table association
-
getMockForTrait() protected
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. -
getMockFromWsdl() protected
Returns a mock object based on the given WSDL file.
-
getName() public
Gets the name of a TestCase.
-
getNumAssertions() public
Returns the number of assertions performed by this test.
-
getObjectAttribute() public static
Returns the value of an object's attribute. This also works for attributes that are declared protected or private.
-
getObjectForTrait() protected
Returns an object for the specified trait.
-
getProvidedData() protected
Gets the data set of a TestCase.
-
getResult() public
-
getSize() public
Returns the size of the test.
-
getStaticAttribute() public static
Returns the value of a static attribute. This also works for attributes that are declared protected or private.
-
getStatus() public
Returns the status of this test.
-
getStatusMessage() public
Returns the status message of this test.
-
getTableLocator() public
Gets the table locator.
-
getTestResultObject() public
-
greaterThan() public static
-
greaterThanOrEqual() public static
-
handleDependencies() protected
-
hasDependencies() public
Returns true if the tests has dependencies
-
hasExpectationOnOutput() public
-
hasFailed() public
Returns whether or not this test has failed.
-
hasOutput() public
-
hasSize() public
-
head() public
Performs a HEAD request using the current request data.
-
identicalTo() public static
-
iniSet() protected
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.
-
isEmpty() public static
-
isFalse() public static
-
isFinite() public static
-
isInIsolation() public
-
isInfinite() public static
-
isInstanceOf() public static
-
isJson() public static
-
isLarge() public
-
isMedium() public
-
isNan() public static
-
isNull() public static
-
isReadable() public static
-
isSmall() public
-
isTrue() public static
-
isType() public static
-
isWritable() public static
-
lessThan() public static
-
lessThanOrEqual() public static
-
loadFixtures() public
Chooses which fixtures to load for a given test
-
loadPlugins() public
Load plugins into a simulated application.
-
logicalAnd() public static
-
logicalNot() public static
-
logicalOr() public static
-
logicalXor() public static
-
markAsRisky() public
-
markTestIncomplete() public static
Mark the test as incomplete.
-
markTestSkipped() public static
Mark the test as skipped.
-
matches() public static
-
matchesRegularExpression() public static
-
never() public static
Returns a matcher that matches when the method is never executed.
-
objectHasAttribute() public static
-
onConsecutiveCalls() public static
-
onNotSuccessfulTest() protected
This method is called when a test method did not execute successfully.
-
once() public static
Returns a matcher that matches when the method is executed exactly once.
-
options() public
Performs an OPTIONS request using the current request data.
-
patch() public
Performs a PATCH request using the current request data.
-
post() public
Performs a POST request using the current request data.
-
prepareTemplate() protected
Performs custom preparations on the process isolation template.
-
prophesize() protected
-
put() public
Performs a PUT request using the current request data.
-
readAttribute() public static
Returns the value of an attribute of a class or an object. This also works for attributes that are declared protected or private.
-
registerComparator() public
-
registerMockObject() public
-
removePlugins() public
Remove plugins from the global plugin collection.
-
resetCount() public static
Reset the assertion counter.
-
returnArgument() public static
-
returnCallback() public static
-
returnSelf() public static
Returns the current object.
-
returnValue() public static
-
returnValueMap() public static
-
run() public
Runs the test case and collects the results in a TestResult object. If no TestResult object is passed a new one will be created.
-
runBare() public
Runs the bare test sequence.
-
runTest() protected
Override to run the test and assert its state.
-
session() public
Sets session data.
-
setAppNamespace() public static
Set the app namespace
-
setBackupGlobals() public
Calling this method in setUp() has no effect!
-
setBackupStaticAttributes() public
Calling this method in setUp() has no effect!
-
setBeStrictAboutChangesToGlobalState() public
-
setDependencies() public
Sets the dependencies of a TestCase.
-
setDependencyInput() public
Sets
-
setExpectedExceptionFromAnnotation() protected
-
setGroups() public
-
setInIsolation() public
-
setLocale() protected
This method is a wrapper for the setlocale() function that automatically resets the locale to its original value after the test is run.
-
setName() public
Sets the name of a TestCase.
-
setOutputCallback() public
-
setPreserveGlobalState() public
-
setRegisterMockObjectsFromTestArgumentsRecursively() public
-
setResult() public
-
setRunClassInSeparateProcess() public
-
setRunTestInSeparateProcess() public
-
setTableLocator() public
Sets the table locator.
-
setTestResultObject() public
-
setUnlockedFields() public
Set list of fields that are excluded from field validation.
-
setUp() public
Setup the test case, backup the static object values so they can be restored. Specifically backs up the contents of Configure and paths in App if they have not already been backed up.
-
setUpBeforeClass() public static
This method is called before the first test of this test class is run.
-
setUseErrorHandler() public
-
setUseErrorHandlerFromAnnotation() protected
-
setupServer() public
Auto-detect if the HTTP middleware stack should be used.
-
skipIf() public
Overrides SimpleTestCase::skipIf to provide a boolean return value
-
skipUnless() protected
Compatibility function for skipping.
-
stringContains() public static
-
stringEndsWith() public static
-
stringStartsWith() public static
-
tableLocator() public deprecated
Sets the table locator. If no parameters are passed, it will return the currently used locator.
-
tearDown() public
teardown any static object changes and restore them.
-
tearDownAfterClass() public static
This method is called after the last test of this test class is run.
-
throwException() public static
-
toString() public
Returns a string representation of the test case.
-
useHttpServer() public
Toggle whether or not you want to use the HTTP Server stack.
-
usesDataProvider() public
-
verifyMockObjects() protected
Verifies the mock object expectations.
-
viewVariable() public
Fetches a view variable by name.
-
withErrorReporting() public
Helper method for tests that needs to use error_reporting()
Method Detail
__construct() ¶ public
__construct(string $name = null, array $data = [], string $dataName = '')
Constructs a test case with the given name.
Parameters
-
string
$name optional -
array
$data optional -
string
$dataName optional
_addTokens() ¶ protected
_addTokens(string $url, array $data): array
Add the CSRF and Security Component tokens if necessary.
Parameters
-
string
$url The URL the form is being submitted on.
-
array
$data The request body data.
Returns
array
_assertAttributes() ¶ protected
_assertAttributes(array $assertions, string $string, bool $fullDebug = false, array|string $regex = ''): string|bool
Check the attributes as part of an assertTags() check.
Parameters
-
array
$assertions Assertions to run.
-
string
$string The HTML string to check.
-
bool
$fullDebug optional Whether or not more verbose output should be used.
-
array|string
$regex optional Full regexp from
assertHtml
Returns
string|bool
_buildFieldToken() ¶ protected
_buildFieldToken(string $url, array $fields, string[] $unlockedFields = []): array
Generate the token data for the provided inputs.
Parameters
-
string
$url The URL the form is being submitted to.
-
array
$fields If set specifies the list of fields to use when generating the hash.
-
string[]
$unlockedFields optional The list of fields that are excluded from field validation.
Returns
array
_buildRequest() ¶ protected
_buildRequest(string|array $url, string $method, string|array|null $data): array
Creates a request object with the configured options and parameters.
Parameters
-
string|array
$url The URL
-
string
$method The HTTP method
-
string|array|null
$data The request data.
Returns
array
_castToString() ¶ protected
_castToString(array $data): array
Recursively casts all data to string as that is how data would be POSTed in the real world
Parameters
-
array
$data POST data
Returns
array
_checkCipher() ¶ protected
_checkCipher(string $encrypt): void
Helper method for validating encryption cipher names.
Parameters
-
string
$encrypt The cipher name.
Returns
void
Throws
RuntimeException
When an invalid cipher is provided.
_decode() ¶ protected
_decode(string $value, string|false $encrypt, string|null $key): string|array
Decodes and decrypts a single value.
Parameters
-
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.
Returns
string|array
_decrypt() ¶ protected
_decrypt(string[]|string $values, string|false $mode, string|null $key = null): string|array
Decrypts $value using public $type method in Security class
Parameters
-
string[]|string
$values Values to decrypt
-
string|false
$mode Encryption mode
-
string|null
$key optional Used as the security salt if specified.
Returns
string|array
_encrypt() ¶ protected
_encrypt(string|array $value, string|false $encrypt, string|null $key = null): string
Encrypts $value using public $type method in Security class
Parameters
-
string|array
$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.
Returns
string
_explode() ¶ protected
_explode(string $string): string|array
Explode method to return array from string set in CookieComponent::_implode() Maintains reading backwards compatibility with 1.x CookieComponent::_implode().
Parameters
-
string
$string A string containing JSON encoded data, or a bare string.
Returns
string|array
_getBodyAsString() ¶ protected
_getBodyAsString(): string
Get the response body as string
Returns
string
_getCookieEncryptionKey() ¶ protected
_getCookieEncryptionKey(): string
Returns the encryption key to be used.
Returns
string
_getTableClassName() ¶ protected
_getTableClassName(string $alias, array $options): string
Gets the class name for the table.
Parameters
-
string
$alias The model to get a mock for.
-
array
$options The config data for the mock's constructor.
Returns
string
Throws
Cake\ORM\Exception\MissingTableClassException
_handleError() ¶ protected
_handleError(Exception $exception): void
Attempts to render an error response for a given exception.
This method will attempt to use the configured exception renderer. If that class does not exist, the built-in renderer will be used.
Parameters
-
Exception
$exception Exception to handle.
Returns
void
Throws
Exception
_implode() ¶ protected
_implode(array $array): string
Implode method to keep keys are multidimensional arrays
Parameters
-
array
$array Map of key and values
Returns
string
_makeDispatcher() ¶ protected
_makeDispatcher(): Cake\TestSuite\MiddlewareDispatcherCake\TestSuite\LegacyRequestDispatcher
Get the correct dispatcher instance.
Returns
Cake\TestSuite\MiddlewareDispatcherCake\TestSuite\LegacyRequestDispatcher
_normalizePath() ¶ protected
_normalizePath(string $path): string
Normalize a path for comparison.
Parameters
-
string
$path Path separated by "/" slash.
Returns
string
_sendRequest() ¶ protected
_sendRequest(string|array $url, string $method, string|array|null $data = []): void
Creates and send the request into a Dispatcher instance.
Receives and stores the response for future inspection.
Parameters
-
string|array
$url The URL
-
string
$method The HTTP method
-
string|array|null
$data optional The request data.
Returns
void
Throws
PHPUnit\Exception
_url() ¶ protected
_url(string|array $url): array
Creates a valid request url and parameter array more like Request::_url()
Parameters
-
string|array
$url The URL
Returns
array
addFixture() ¶ protected
addFixture(string $fixture): $this
Adds a fixture to this test case.
Examples:
- core.Tags
- app.MyRecords
- plugin.MyPluginName.MyModelName
Use this method inside your test cases' {@link getFixtures()} method to build up the fixture list.
Parameters
-
string
$fixture Fixture
Returns
$this
addToAssertionCount() ¶ public
addToAssertionCount(int $count)
Adds a value to the assertion counter.
Parameters
-
int
$count
any() ¶ public static
any(): AnyInvokedCountMatcher
Returns a matcher that matches when the method is executed zero or more times.
Returns
AnyInvokedCountMatcher
arrayHasKey() ¶ public static
arrayHasKey(mixed $key): ArrayHasKey
Parameters
-
mixed
$key
Returns
ArrayHasKey
assertArrayHasKey() ¶ public static
assertArrayHasKey(mixed $key, array|ArrayAccess $array, string $message = '')
Asserts that an array has a specified key.
Parameters
-
mixed
$key -
array|ArrayAccess
$array -
string
$message optional
assertArrayNotHasKey() ¶ public static
assertArrayNotHasKey(mixed $key, array|ArrayAccess $array, string $message = '')
Asserts that an array does not have a specified key.
Parameters
-
mixed
$key -
array|ArrayAccess
$array -
string
$message optional
assertArraySubset() ¶ public static
assertArraySubset(array|ArrayAccess $subset, array|ArrayAccess $array, bool $strict = false, string $message = '')
Asserts that an array has a specified subset.
Parameters
-
array|ArrayAccess
$subset -
array|ArrayAccess
$array -
bool
$strict optional Check for object identity
-
string
$message optional
assertAttributeContains() ¶ public static
assertAttributeContains(mixed $needle, string $haystackAttributeName, string|object $haystackClassOrObject, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false)
Asserts that a haystack that is stored in a static attribute of a class or an attribute of an object contains a needle.
Parameters
-
mixed
$needle -
string
$haystackAttributeName -
string|object
$haystackClassOrObject -
string
$message optional -
bool
$ignoreCase optional -
bool
$checkForObjectIdentity optional -
bool
$checkForNonObjectIdentity optional
assertAttributeContainsOnly() ¶ public static
assertAttributeContainsOnly(string $type, string $haystackAttributeName, string|object $haystackClassOrObject, bool $isNativeType = null, string $message = '')
Asserts that a haystack that is stored in a static attribute of a class or an attribute of an object contains only values of a given type.
Parameters
-
string
$type -
string
$haystackAttributeName -
string|object
$haystackClassOrObject -
bool
$isNativeType optional -
string
$message optional
assertAttributeCount() ¶ public static
assertAttributeCount(int $expectedCount, string $haystackAttributeName, string|object $haystackClassOrObject, string $message = '')
Asserts the number of elements of an array, Countable or Traversable that is stored in an attribute.
Parameters
-
int
$expectedCount -
string
$haystackAttributeName -
string|object
$haystackClassOrObject -
string
$message optional
assertAttributeEmpty() ¶ public static
assertAttributeEmpty(string $haystackAttributeName, string|object $haystackClassOrObject, string $message = '')
Asserts that a static attribute of a class or an attribute of an object is empty.
Parameters
-
string
$haystackAttributeName -
string|object
$haystackClassOrObject -
string
$message optional
assertAttributeEquals() ¶ public static
assertAttributeEquals(mixed $expected, string $actualAttributeName, string|object $actualClassOrObject, string $message = '', float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false)
Asserts that a variable is equal to an attribute of an object.
Parameters
-
mixed
$expected -
string
$actualAttributeName -
string|object
$actualClassOrObject -
string
$message optional -
float
$delta optional -
int
$maxDepth optional -
bool
$canonicalize optional -
bool
$ignoreCase optional
assertAttributeGreaterThan() ¶ public static
assertAttributeGreaterThan(mixed $expected, string $actualAttributeName, string|object $actualClassOrObject, string $message = '')
Asserts that an attribute is greater than another value.
Parameters
-
mixed
$expected -
string
$actualAttributeName -
string|object
$actualClassOrObject -
string
$message optional
assertAttributeGreaterThanOrEqual() ¶ public static
assertAttributeGreaterThanOrEqual(mixed $expected, string $actualAttributeName, string|object $actualClassOrObject, string $message = '')
Asserts that an attribute is greater than or equal to another value.
Parameters
-
mixed
$expected -
string
$actualAttributeName -
string|object
$actualClassOrObject -
string
$message optional
assertAttributeInstanceOf() ¶ public static
assertAttributeInstanceOf(string $expected, string $attributeName, string|object $classOrObject, string $message = '')
Asserts that an attribute is of a given type.
Parameters
-
string
$expected -
string
$attributeName -
string|object
$classOrObject -
string
$message optional
assertAttributeInternalType() ¶ public static
assertAttributeInternalType(string $expected, string $attributeName, string|object $classOrObject, string $message = '')
Asserts that an attribute is of a given type.
Parameters
-
string
$expected -
string
$attributeName -
string|object
$classOrObject -
string
$message optional
assertAttributeLessThan() ¶ public static
assertAttributeLessThan(mixed $expected, string $actualAttributeName, string|object $actualClassOrObject, string $message = '')
Asserts that an attribute is smaller than another value.
Parameters
-
mixed
$expected -
string
$actualAttributeName -
string|object
$actualClassOrObject -
string
$message optional
assertAttributeLessThanOrEqual() ¶ public static
assertAttributeLessThanOrEqual(mixed $expected, string $actualAttributeName, string|object $actualClassOrObject, string $message = '')
Asserts that an attribute is smaller than or equal to another value.
Parameters
-
mixed
$expected -
string
$actualAttributeName -
string|object
$actualClassOrObject -
string
$message optional
assertAttributeNotContains() ¶ public static
assertAttributeNotContains(mixed $needle, string $haystackAttributeName, string|object $haystackClassOrObject, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false)
Asserts that a haystack that is stored in a static attribute of a class or an attribute of an object does not contain a needle.
Parameters
-
mixed
$needle -
string
$haystackAttributeName -
string|object
$haystackClassOrObject -
string
$message optional -
bool
$ignoreCase optional -
bool
$checkForObjectIdentity optional -
bool
$checkForNonObjectIdentity optional
assertAttributeNotContainsOnly() ¶ public static
assertAttributeNotContainsOnly(string $type, string $haystackAttributeName, string|object $haystackClassOrObject, bool $isNativeType = null, string $message = '')
Asserts that a haystack that is stored in a static attribute of a class or an attribute of an object does not contain only values of a given type.
Parameters
-
string
$type -
string
$haystackAttributeName -
string|object
$haystackClassOrObject -
bool
$isNativeType optional -
string
$message optional
assertAttributeNotCount() ¶ public static
assertAttributeNotCount(int $expectedCount, string $haystackAttributeName, string|object $haystackClassOrObject, string $message = '')
Asserts the number of elements of an array, Countable or Traversable that is stored in an attribute.
Parameters
-
int
$expectedCount -
string
$haystackAttributeName -
string|object
$haystackClassOrObject -
string
$message optional
assertAttributeNotEmpty() ¶ public static
assertAttributeNotEmpty(string $haystackAttributeName, string|object $haystackClassOrObject, string $message = '')
Asserts that a static attribute of a class or an attribute of an object is not empty.
Parameters
-
string
$haystackAttributeName -
string|object
$haystackClassOrObject -
string
$message optional
assertAttributeNotEquals() ¶ public static
assertAttributeNotEquals(mixed $expected, string $actualAttributeName, string|object $actualClassOrObject, string $message = '', float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false)
Asserts that a variable is not equal to an attribute of an object.
Parameters
-
mixed
$expected -
string
$actualAttributeName -
string|object
$actualClassOrObject -
string
$message optional -
float
$delta optional -
int
$maxDepth optional -
bool
$canonicalize optional -
bool
$ignoreCase optional
assertAttributeNotInstanceOf() ¶ public static
assertAttributeNotInstanceOf(string $expected, string $attributeName, string|object $classOrObject, string $message = '')
Asserts that an attribute is of a given type.
Parameters
-
string
$expected -
string
$attributeName -
string|object
$classOrObject -
string
$message optional
assertAttributeNotInternalType() ¶ public static
assertAttributeNotInternalType(string $expected, string $attributeName, string|object $classOrObject, string $message = '')
Asserts that an attribute is of a given type.
Parameters
-
string
$expected -
string
$attributeName -
string|object
$classOrObject -
string
$message optional
assertAttributeNotSame() ¶ public static
assertAttributeNotSame(mixed $expected, string $actualAttributeName, string|object $actualClassOrObject, string $message = '')
Asserts that a variable and an attribute of an object do not have the same type and value.
Parameters
-
mixed
$expected -
string
$actualAttributeName -
string|object
$actualClassOrObject -
string
$message optional
assertAttributeSame() ¶ public static
assertAttributeSame(mixed $expected, string $actualAttributeName, string|object $actualClassOrObject, string $message = '')
Asserts that a variable and an attribute of an object have the same type and value.
Parameters
-
mixed
$expected -
string
$actualAttributeName -
string|object
$actualClassOrObject -
string
$message optional
assertClassHasAttribute() ¶ public static
assertClassHasAttribute(string $attributeName, string $className, string $message = '')
Asserts that a class has a specified attribute.
Parameters
-
string
$attributeName -
string
$className -
string
$message optional
assertClassHasStaticAttribute() ¶ public static
assertClassHasStaticAttribute(string $attributeName, string $className, string $message = '')
Asserts that a class has a specified static attribute.
Parameters
-
string
$attributeName -
string
$className -
string
$message optional
assertClassNotHasAttribute() ¶ public static
assertClassNotHasAttribute(string $attributeName, string $className, string $message = '')
Asserts that a class does not have a specified attribute.
Parameters
-
string
$attributeName -
string
$className -
string
$message optional
assertClassNotHasStaticAttribute() ¶ public static
assertClassNotHasStaticAttribute(string $attributeName, string $className, string $message = '')
Asserts that a class does not have a specified static attribute.
Parameters
-
string
$attributeName -
string
$className -
string
$message optional
assertContains() ¶ public static
assertContains(mixed $needle, mixed $haystack, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false)
Asserts that a haystack contains a needle.
Parameters
-
mixed
$needle -
mixed
$haystack -
string
$message optional -
bool
$ignoreCase optional -
bool
$checkForObjectIdentity optional -
bool
$checkForNonObjectIdentity optional
assertContainsOnly() ¶ public static
assertContainsOnly(string $type, mixed $haystack, bool $isNativeType = null, string $message = '')
Asserts that a haystack contains only values of a given type.
Parameters
-
string
$type -
mixed
$haystack -
bool
$isNativeType optional -
string
$message optional
assertContainsOnlyInstancesOf() ¶ public static
assertContainsOnlyInstancesOf(string $classname, arrayTraversable $haystack, string $message = '')
Asserts that a haystack contains only instances of a given classname
Parameters
-
string
$classname -
arrayTraversable
$haystack -
string
$message optional
assertContentType() ¶ public
assertContentType(string $type, string $message = ''): void
Asserts content type
Parameters
-
string
$type The content-type to check for.
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertCookie() ¶ public
assertCookie(string $expected, string $name, string $message = ''): void
Asserts cookie values
Parameters
-
string
$expected The expected contents.
-
string
$name The cookie name.
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertCookieEncrypted() ¶ public
assertCookieEncrypted(string $expected, string $name, string|bool $encrypt = 'aes', string|null $key = null, string $message = ''): void
Asserts cookie values which are encrypted by the CookieComponent.
The difference from assertCookie() is this decrypts the cookie value like the CookieComponent for this assertion.
Parameters
-
string
$expected The expected contents.
-
string
$name The cookie name.
-
string|bool
$encrypt optional Encryption mode to use.
-
string|null
$key optional Encryption key used. Defaults to Security.salt.
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
See Also
assertCookieNotSet() ¶ public
assertCookieNotSet(string $cookie, string $message = ''): void
Asserts a cookie has not been set in the response
Parameters
-
string
$cookie The cookie name to check
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertCount() ¶ public static
assertCount(int $expectedCount, mixed $haystack, string $message = '')
Asserts the number of elements of an array, Countable or Traversable.
Parameters
-
int
$expectedCount -
mixed
$haystack -
string
$message optional
assertDirectoryExists() ¶ public static
assertDirectoryExists(string $directory, string $message = '')
Asserts that a directory exists.
Parameters
-
string
$directory -
string
$message optional
assertDirectoryIsReadable() ¶ public static
assertDirectoryIsReadable(string $directory, string $message = '')
Asserts that a directory exists and is readable.
Parameters
-
string
$directory -
string
$message optional
assertDirectoryIsWritable() ¶ public static
assertDirectoryIsWritable(string $directory, string $message = '')
Asserts that a directory exists and is writable.
Parameters
-
string
$directory -
string
$message optional
assertDirectoryNotExists() ¶ public static
assertDirectoryNotExists(string $directory, string $message = '')
Asserts that a directory does not exist.
Parameters
-
string
$directory -
string
$message optional
assertDirectoryNotIsReadable() ¶ public static
assertDirectoryNotIsReadable(string $directory, string $message = '')
Asserts that a directory exists and is not readable.
Parameters
-
string
$directory -
string
$message optional
assertDirectoryNotIsWritable() ¶ public static
assertDirectoryNotIsWritable(string $directory, string $message = '')
Asserts that a directory exists and is not writable.
Parameters
-
string
$directory -
string
$message optional
assertEmpty() ¶ public static
assertEmpty(mixed $actual, string $message = '')
Asserts that a variable is empty.
Parameters
-
mixed
$actual -
string
$message optional
Throws
AssertionFailedError
assertEqualXMLStructure() ¶ public static
assertEqualXMLStructure(DOMElement $expectedElement, DOMElement $actualElement, bool $checkAttributes = false, string $message = '')
Asserts that a hierarchy of DOMElements matches.
Parameters
-
DOMElement
$expectedElement -
DOMElement
$actualElement -
bool
$checkAttributes optional -
string
$message optional
assertEquals() ¶ public static
assertEquals(mixed $expected, mixed $actual, string $message = '', float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false)
Asserts that two variables are equal.
Parameters
-
mixed
$expected -
mixed
$actual -
string
$message optional -
float
$delta optional -
int
$maxDepth optional -
bool
$canonicalize optional -
bool
$ignoreCase optional
assertEventFired() ¶ public
assertEventFired(string $name, EventManager|null $eventManager = null, string $message = ''): void
Asserts that a global event was fired. You must track events in your event manager for this assertion to work
Parameters
-
string
$name Event name
-
EventManager|null
$eventManager optional Event manager to check, defaults to global event manager
-
string
$message optional Assertion failure message
Returns
void
assertEventFiredWith() ¶ public
assertEventFiredWith(string $name, string $dataKey, string $dataValue, EventManager|null $eventManager = null, string $message = ''): void
Asserts an event was fired with data
If a third argument is passed, that value is used to compare with the value in $dataKey
Parameters
-
string
$name Event name
-
string
$dataKey Data key
-
string
$dataValue Data value
-
EventManager|null
$eventManager optional Event manager to check, defaults to global event manager
-
string
$message optional Assertion failure message
Returns
void
assertFalse() ¶ public static
assertFalse(bool $condition, string $message = '')
Asserts that a condition is false.
Parameters
-
bool
$condition -
string
$message optional
Throws
AssertionFailedError
assertFileEquals() ¶ public static
assertFileEquals(string $expected, string $actual, string $message = '', bool $canonicalize = false, bool $ignoreCase = false)
Asserts that the contents of one file is equal to the contents of another file.
Parameters
-
string
$expected -
string
$actual -
string
$message optional -
bool
$canonicalize optional -
bool
$ignoreCase optional
assertFileExists() ¶ public static
assertFileExists(string $filename, string $message = '')
Asserts that a file exists.
Parameters
-
string
$filename -
string
$message optional
assertFileIsReadable() ¶ public static
assertFileIsReadable(string $file, string $message = '')
Asserts that a file exists and is readable.
Parameters
-
string
$file -
string
$message optional
assertFileIsWritable() ¶ public static
assertFileIsWritable(string $file, string $message = '')
Asserts that a file exists and is writable.
Parameters
-
string
$file -
string
$message optional
assertFileNotEquals() ¶ public static
assertFileNotEquals(string $expected, string $actual, string $message = '', bool $canonicalize = false, bool $ignoreCase = false)
Asserts that the contents of one file is not equal to the contents of another file.
Parameters
-
string
$expected -
string
$actual -
string
$message optional -
bool
$canonicalize optional -
bool
$ignoreCase optional
assertFileNotExists() ¶ public static
assertFileNotExists(string $filename, string $message = '')
Asserts that a file does not exist.
Parameters
-
string
$filename -
string
$message optional
assertFileNotIsReadable() ¶ public static
assertFileNotIsReadable(string $file, string $message = '')
Asserts that a file exists and is not readable.
Parameters
-
string
$file -
string
$message optional
assertFileNotIsWritable() ¶ public static
assertFileNotIsWritable(string $file, string $message = '')
Asserts that a file exists and is not writable.
Parameters
-
string
$file -
string
$message optional
assertFileResponse() ¶ public
assertFileResponse(string $expected, string $message = ''): void
Asserts that a file with the given name was sent in the response
Parameters
-
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.
Returns
void
assertFinite() ¶ public static
assertFinite(mixed $actual, string $message = '')
Asserts that a variable is finite.
Parameters
-
mixed
$actual -
string
$message optional
assertFlashElement() ¶ public
assertFlashElement(string $expected, string $key = 'flash', string $message = ''): void
Asserts a flash element was set
Parameters
-
string
$expected Expected element name
-
string
$key optional Flash key
-
string
$message optional Assertion failure message
Returns
void
assertFlashElementAt() ¶ public
assertFlashElementAt(int $at, string $expected, string $key = 'flash', string $message = ''): void
Asserts a flash element was set at a certain index
Parameters
-
int
$at Flash index
-
string
$expected Expected element name
-
string
$key optional Flash key
-
string
$message optional Assertion failure message
Returns
void
assertFlashMessage() ¶ public
assertFlashMessage(string $expected, string $key = 'flash', string $message = ''): void
Asserts a flash message was set
Parameters
-
string
$expected Expected message
-
string
$key optional Flash key
-
string
$message optional Assertion failure message
Returns
void
assertFlashMessageAt() ¶ public
assertFlashMessageAt(int $at, string $expected, string $key = 'flash', string $message = ''): void
Asserts a flash message was set at a certain index
Parameters
-
int
$at Flash index
-
string
$expected Expected message
-
string
$key optional Flash key
-
string
$message optional Assertion failure message
Returns
void
assertGreaterThan() ¶ public static
assertGreaterThan(mixed $expected, mixed $actual, string $message = '')
Asserts that a value is greater than another value.
Parameters
-
mixed
$expected -
mixed
$actual -
string
$message optional
assertGreaterThanOrEqual() ¶ public static
assertGreaterThanOrEqual(mixed $expected, mixed $actual, string $message = '')
Asserts that a value is greater than or equal to another value.
Parameters
-
mixed
$expected -
mixed
$actual -
string
$message optional
assertHeader() ¶ public
assertHeader(string $header, string $content, string $message = ''): void
Asserts response headers
Parameters
-
string
$header The header to check
-
string
$content The content to check for.
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertHeaderContains() ¶ public
assertHeaderContains(string $header, string $content, string $message = ''): void
Asserts response header contains a string
Parameters
-
string
$header The header to check
-
string
$content The content to check for.
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertHeaderNotContains() ¶ public
assertHeaderNotContains(string $header, string $content, string $message = ''): void
Asserts response header does not contain a string
Parameters
-
string
$header The header to check
-
string
$content The content to check for.
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertHtml() ¶ public
assertHtml(array $expected, string $string, bool $fullDebug = false): bool
Asserts HTML tags.
Takes an array $expected and generates a regex from it to match the provided $string. Samples for $expected:
Checks for an input tag with a name attribute (contains any non-empty value) and an id attribute that contains 'my-input':
['input' => ['name', 'id' => 'my-input']]
Checks for two p elements with some text in them:
[
['p' => true],
'textA',
'/p',
['p' => true],
'textB',
'/p'
]
You can also specify a pattern expression as part of the attribute values, or the tag being defined, if you prepend the value with preg: and enclose it with slashes, like so:
[
['input' => ['name', 'id' => 'preg:/FieldName\d+/']],
'preg:/My\s+field/'
]
Important: This function is very forgiving about whitespace and also accepts any permutation of attribute order. It will also allow whitespace between specified tags.
Parameters
-
array
$expected An array, see above
-
string
$string An HTML/XHTML/XML string
-
bool
$fullDebug optional Whether or not more verbose output should be used.
Returns
bool
assertInfinite() ¶ public static
assertInfinite(mixed $actual, string $message = '')
Asserts that a variable is infinite.
Parameters
-
mixed
$actual -
string
$message optional
assertInstanceOf() ¶ public static
assertInstanceOf(string $expected, mixed $actual, string $message = '')
Asserts that a variable is of a given type.
Parameters
-
string
$expected -
mixed
$actual -
string
$message optional
assertInternalType() ¶ public static
assertInternalType(string $expected, mixed $actual, string $message = '')
Asserts that a variable is of a given type.
Parameters
-
string
$expected -
mixed
$actual -
string
$message optional
assertIsReadable() ¶ public static
assertIsReadable(string $filename, string $message = '')
Asserts that a file/dir is readable.
Parameters
-
string
$filename -
string
$message optional
assertIsWritable() ¶ public static
assertIsWritable(string $filename, string $message = '')
Asserts that a file/dir exists and is writable.
Parameters
-
string
$filename -
string
$message optional
assertJson() ¶ public static
assertJson(string $actualJson, string $message = '')
Asserts that a string is a valid JSON string.
Parameters
-
string
$actualJson -
string
$message optional
assertJsonFileEqualsJsonFile() ¶ public static
assertJsonFileEqualsJsonFile(string $expectedFile, string $actualFile, string $message = '')
Asserts that two JSON files are equal.
Parameters
-
string
$expectedFile -
string
$actualFile -
string
$message optional
assertJsonFileNotEqualsJsonFile() ¶ public static
assertJsonFileNotEqualsJsonFile(string $expectedFile, string $actualFile, string $message = '')
Asserts that two JSON files are not equal.
Parameters
-
string
$expectedFile -
string
$actualFile -
string
$message optional
assertJsonStringEqualsJsonFile() ¶ public static
assertJsonStringEqualsJsonFile(string $expectedFile, string $actualJson, string $message = '')
Asserts that the generated JSON encoded object and the content of the given file are equal.
Parameters
-
string
$expectedFile -
string
$actualJson -
string
$message optional
assertJsonStringEqualsJsonString() ¶ public static
assertJsonStringEqualsJsonString(string $expectedJson, string $actualJson, string $message = '')
Asserts that two given JSON encoded objects or arrays are equal.
Parameters
-
string
$expectedJson -
string
$actualJson -
string
$message optional
assertJsonStringNotEqualsJsonFile() ¶ public static
assertJsonStringNotEqualsJsonFile(string $expectedFile, string $actualJson, string $message = '')
Asserts that the generated JSON encoded object and the content of the given file are not equal.
Parameters
-
string
$expectedFile -
string
$actualJson -
string
$message optional
assertJsonStringNotEqualsJsonString() ¶ public static
assertJsonStringNotEqualsJsonString(string $expectedJson, string $actualJson, string $message = '')
Asserts that two given JSON encoded objects or arrays are not equal.
Parameters
-
string
$expectedJson -
string
$actualJson -
string
$message optional
assertLayout() ¶ public
assertLayout(string $content, string $message = ''): void
Asserts that the search string was in the layout name.
Parameters
-
string
$content The content to check for.
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertLessThan() ¶ public static
assertLessThan(mixed $expected, mixed $actual, string $message = '')
Asserts that a value is smaller than another value.
Parameters
-
mixed
$expected -
mixed
$actual -
string
$message optional
assertLessThanOrEqual() ¶ public static
assertLessThanOrEqual(mixed $expected, mixed $actual, string $message = '')
Asserts that a value is smaller than or equal to another value.
Parameters
-
mixed
$expected -
mixed
$actual -
string
$message optional
assertNan() ¶ public static
assertNan(mixed $actual, string $message = '')
Asserts that a variable is nan.
Parameters
-
mixed
$actual -
string
$message optional
assertNoRedirect() ¶ public
assertNoRedirect(string $message = ''): void
Asserts that the Location header is not set.
Parameters
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertNotContains() ¶ public static
assertNotContains(mixed $needle, mixed $haystack, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false)
Asserts that a haystack does not contain a needle.
Parameters
-
mixed
$needle -
mixed
$haystack -
string
$message optional -
bool
$ignoreCase optional -
bool
$checkForObjectIdentity optional -
bool
$checkForNonObjectIdentity optional
assertNotContainsOnly() ¶ public static
assertNotContainsOnly(string $type, mixed $haystack, bool $isNativeType = null, string $message = '')
Asserts that a haystack does not contain only values of a given type.
Parameters
-
string
$type -
mixed
$haystack -
bool
$isNativeType optional -
string
$message optional
assertNotCount() ¶ public static
assertNotCount(int $expectedCount, mixed $haystack, string $message = '')
Asserts the number of elements of an array, Countable or Traversable.
Parameters
-
int
$expectedCount -
mixed
$haystack -
string
$message optional
assertNotEmpty() ¶ public static
assertNotEmpty(mixed $actual, string $message = '')
Asserts that a variable is not empty.
Parameters
-
mixed
$actual -
string
$message optional
Throws
AssertionFailedError
assertNotEquals() ¶ public static
assertNotEquals(mixed $expected, mixed $actual, string $message = '', float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false)
Asserts that two variables are not equal.
Parameters
-
mixed
$expected -
mixed
$actual -
string
$message optional -
float
$delta optional -
int
$maxDepth optional -
bool
$canonicalize optional -
bool
$ignoreCase optional
assertNotFalse() ¶ public static
assertNotFalse(bool $condition, string $message = '')
Asserts that a condition is not false.
Parameters
-
bool
$condition -
string
$message optional
Throws
AssertionFailedError
assertNotInstanceOf() ¶ public static
assertNotInstanceOf(string $expected, mixed $actual, string $message = '')
Asserts that a variable is not of a given type.
Parameters
-
string
$expected -
mixed
$actual -
string
$message optional
assertNotInternalType() ¶ public static
assertNotInternalType(string $expected, mixed $actual, string $message = '')
Asserts that a variable is not of a given type.
Parameters
-
string
$expected -
mixed
$actual -
string
$message optional
assertNotIsReadable() ¶ public static
assertNotIsReadable(string $filename, string $message = '')
Asserts that a file/dir exists and is not readable.
Parameters
-
string
$filename -
string
$message optional
assertNotIsWritable() ¶ public static
assertNotIsWritable(string $filename, string $message = '')
Asserts that a file/dir exists and is not writable.
Parameters
-
string
$filename -
string
$message optional
assertNotNull() ¶ public static
assertNotNull(mixed $actual, string $message = '')
Asserts that a variable is not null.
Parameters
-
mixed
$actual -
string
$message optional
assertNotRegExp() ¶ public static
assertNotRegExp(string $pattern, string $string, string $message = '')
Asserts that a string does not match a given regular expression.
Parameters
-
string
$pattern -
string
$string -
string
$message optional
assertNotSame() ¶ public static
assertNotSame(mixed $expected, mixed $actual, string $message = '')
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.
Parameters
-
mixed
$expected -
mixed
$actual -
string
$message optional
assertNotSameSize() ¶ public static
assertNotSameSize(arrayCountableTraversable $expected, arrayCountableTraversable $actual, string $message = '')
Assert that the size of two arrays (or Countable
or Traversable
objects)
is not the same.
Parameters
-
arrayCountableTraversable
$expected -
arrayCountableTraversable
$actual -
string
$message optional
assertNotTrue() ¶ public static
assertNotTrue(bool $condition, string $message = '')
Asserts that a condition is not true.
Parameters
-
bool
$condition -
string
$message optional
Throws
AssertionFailedError
assertNotWithinRange() ¶ protected static
assertNotWithinRange(float $expected, float $result, float $margin, string $message = ''): void
Compatibility function to test if a value is not between an acceptable range.
Parameters
-
float
$expected -
float
$result -
float
$margin the rage of acceptation
-
string
$message optional the text to display if the assertion is not correct
Returns
void
assertNull() ¶ public static
assertNull(mixed $actual, string $message = '')
Asserts that a variable is null.
Parameters
-
mixed
$actual -
string
$message optional
assertObjectHasAttribute() ¶ public static
assertObjectHasAttribute(string $attributeName, object $object, string $message = '')
Asserts that an object has a specified attribute.
Parameters
-
string
$attributeName -
object
$object -
string
$message optional
assertObjectNotHasAttribute() ¶ public static
assertObjectNotHasAttribute(string $attributeName, object $object, string $message = '')
Asserts that an object does not have a specified attribute.
Parameters
-
string
$attributeName -
object
$object -
string
$message optional
assertPathEquals() ¶ protected static
assertPathEquals(string $expected, string $result, string $message = ''): void
Compatibility function to test paths.
Parameters
-
string
$expected -
string
$result -
string
$message optional the text to display if the assertion is not correct
Returns
void
assertPostConditions() ¶ protected
assertPostConditions()
Performs assertions shared by all tests of a test case.
This method is called after the execution of a test ends and before tearDown() is called.
assertPreConditions() ¶ protected
assertPreConditions()
Performs assertions shared by all tests of a test case.
This method is called before the execution of a test starts and after setUp() is called.
assertRedirect() ¶ public
assertRedirect(string|array|null $url = null, string $message = ''): void
Asserts that the Location header is correct. Comparison is made against a full URL.
Parameters
-
string|array|null
$url optional The URL you expected the client to go to. This can either be a string URL or an array compatible with Router::url(). Use null to simply check for the existence of this header.
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertRedirectContains() ¶ public
assertRedirectContains(string $url, string $message = ''): void
Asserts that the Location header contains a substring
Parameters
-
string
$url The URL you expected the client to go to.
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertRedirectEquals() ¶ public
assertRedirectEquals(string|array|null $url = null, string $message = ''): void
Asserts that the Location header is correct. Comparison is made against exactly the URL provided.
Parameters
-
string|array|null
$url optional The URL you expected the client to go to. This can either be a string URL or an array compatible with Router::url(). Use null to simply check for the existence of this header.
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertRedirectNotContains() ¶ public
assertRedirectNotContains(string $url, string $message = ''): void
Asserts that the Location header does not contain a substring
Parameters
-
string
$url The URL you expected the client to go to.
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertRegExp() ¶ public static
assertRegExp(string $pattern, string $string, string $message = '')
Asserts that a string matches a given regular expression.
Parameters
-
string
$pattern -
string
$string -
string
$message optional
assertResponseCode() ¶ public
assertResponseCode(int $code, string $message = null): void
Asserts a specific response status code.
Parameters
-
int
$code Status code to assert.
-
string
$message optional Custom message for failure.
Returns
void
assertResponseContains() ¶ public
assertResponseContains(string $content, string $message = '', bool $ignoreCase = false): void
Asserts content exists in the response body.
Parameters
-
string
$content The content to check for.
-
string
$message optional The failure message that will be appended to the generated message.
-
bool
$ignoreCase optional A flag to check whether we should ignore case or not.
Returns
void
assertResponseEmpty() ¶ public
assertResponseEmpty(string $message = ''): void
Assert response content is empty.
Parameters
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertResponseEquals() ¶ public
assertResponseEquals(mixed $content, string $message = ''): void
Asserts content in the response body equals.
Parameters
-
mixed
$content The content to check for.
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertResponseError() ¶ public
assertResponseError(string $message = null): void
Asserts that the response status code is in the 4xx range.
Parameters
-
string
$message optional Custom message for failure.
Returns
void
assertResponseFailure() ¶ public
assertResponseFailure(string $message = null): void
Asserts that the response status code is in the 5xx range.
Parameters
-
string
$message optional Custom message for failure.
Returns
void
assertResponseNotContains() ¶ public
assertResponseNotContains(string $content, string $message = '', bool $ignoreCase = false): void
Asserts content does not exist in the response body.
Parameters
-
string
$content The content to check for.
-
string
$message optional The failure message that will be appended to the generated message.
-
bool
$ignoreCase optional A flag to check whether we should ignore case or not.
Returns
void
assertResponseNotEmpty() ¶ public
assertResponseNotEmpty(string $message = ''): void
Assert response content is not empty.
Parameters
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertResponseNotEquals() ¶ public
assertResponseNotEquals(mixed $content, string $message = ''): void
Asserts content in the response body not equals.
Parameters
-
mixed
$content The content to check for.
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertResponseNotRegExp() ¶ public
assertResponseNotRegExp(string $pattern, string $message = ''): void
Asserts that the response body does not match a given regular expression.
Parameters
-
string
$pattern The pattern to compare against.
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertResponseOk() ¶ public
assertResponseOk(string $message = null): void
Asserts that the response status code is in the 2xx range.
Parameters
-
string
$message optional Custom message for failure.
Returns
void
assertResponseRegExp() ¶ public
assertResponseRegExp(string $pattern, string $message = ''): void
Asserts that the response body matches a given regular expression.
Parameters
-
string
$pattern The pattern to compare against.
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertResponseSuccess() ¶ public
assertResponseSuccess(string $message = null): void
Asserts that the response status code is in the 2xx/3xx range.
Parameters
-
string
$message optional Custom message for failure.
Returns
void
assertSame() ¶ public static
assertSame(mixed $expected, mixed $actual, string $message = '')
Asserts that two variables have the same type and value. Used on objects, it asserts that two variables reference the same object.
Parameters
-
mixed
$expected -
mixed
$actual -
string
$message optional
assertSameSize() ¶ public static
assertSameSize(arrayCountableTraversable $expected, arrayCountableTraversable $actual, string $message = '')
Assert that the size of two arrays (or Countable
or Traversable
objects)
is the same.
Parameters
-
arrayCountableTraversable
$expected -
arrayCountableTraversable
$actual -
string
$message optional
assertSession() ¶ public
assertSession(string $expected, string $path, string $message = ''): void
Asserts session contents
Parameters
-
string
$expected The expected contents.
-
string
$path The session data path. Uses Hash::get() compatible notation
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertStringEndsNotWith() ¶ public static
assertStringEndsNotWith(string $suffix, string $string, string $message = '')
Asserts that a string ends not with a given suffix.
Parameters
-
string
$suffix -
string
$string -
string
$message optional
assertStringEndsWith() ¶ public static
assertStringEndsWith(string $suffix, string $string, string $message = '')
Asserts that a string ends with a given suffix.
Parameters
-
string
$suffix -
string
$string -
string
$message optional
assertStringEqualsFile() ¶ public static
assertStringEqualsFile(string $expectedFile, string $actualString, string $message = '', bool $canonicalize = false, bool $ignoreCase = false)
Asserts that the contents of a string is equal to the contents of a file.
Parameters
-
string
$expectedFile -
string
$actualString -
string
$message optional -
bool
$canonicalize optional -
bool
$ignoreCase optional
assertStringMatchesFormat() ¶ public static
assertStringMatchesFormat(string $format, string $string, string $message = '')
Asserts that a string matches a given format string.
Parameters
-
string
$format -
string
$string -
string
$message optional
assertStringMatchesFormatFile() ¶ public static
assertStringMatchesFormatFile(string $formatFile, string $string, string $message = '')
Asserts that a string matches a given format file.
Parameters
-
string
$formatFile -
string
$string -
string
$message optional
assertStringNotEqualsFile() ¶ public static
assertStringNotEqualsFile(string $expectedFile, string $actualString, string $message = '', bool $canonicalize = false, bool $ignoreCase = false)
Asserts that the contents of a string is not equal to the contents of a file.
Parameters
-
string
$expectedFile -
string
$actualString -
string
$message optional -
bool
$canonicalize optional -
bool
$ignoreCase optional
assertStringNotMatchesFormat() ¶ public static
assertStringNotMatchesFormat(string $format, string $string, string $message = '')
Asserts that a string does not match a given format string.
Parameters
-
string
$format -
string
$string -
string
$message optional
assertStringNotMatchesFormatFile() ¶ public static
assertStringNotMatchesFormatFile(string $formatFile, string $string, string $message = '')
Asserts that a string does not match a given format string.
Parameters
-
string
$formatFile -
string
$string -
string
$message optional
assertStringStartsNotWith() ¶ public static
assertStringStartsNotWith(string $prefix, string $string, string $message = '')
Asserts that a string starts not with a given prefix.
Parameters
-
string
$prefix -
string
$string -
string
$message optional
assertStringStartsWith() ¶ public static
assertStringStartsWith(string $prefix, string $string, string $message = '')
Asserts that a string starts with a given prefix.
Parameters
-
string
$prefix -
string
$string -
string
$message optional
assertTags() ¶ public
assertTags(string $string, array $expected, bool $fullDebug = false): void
Asserts HTML tags.
Parameters
-
string
$string An HTML/XHTML/XML string
-
array
$expected An array, see above
-
bool
$fullDebug optional Whether or not more verbose output should be used.
Returns
void
assertTemplate() ¶ public
assertTemplate(string $content, string $message = ''): void
Asserts that the search string was in the template name.
Parameters
-
string
$content The content to check for.
-
string
$message optional The failure message that will be appended to the generated message.
Returns
void
assertTextContains() ¶ public
assertTextContains(string $needle, string $haystack, string $message = '', bool $ignoreCase = false): void
Assert that a string contains another string, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Parameters
-
string
$needle The string to search for.
-
string
$haystack The string to search through.
-
string
$message optional The message to display on failure.
-
bool
$ignoreCase optional Whether or not the search should be case-sensitive.
Returns
void
assertTextEndsNotWith() ¶ public
assertTextEndsNotWith(string $suffix, string $string, string $message = ''): void
Asserts that a string ends not with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Parameters
-
string
$suffix The suffix to not find.
-
string
$string The string to search.
-
string
$message optional The message to use for failure.
Returns
void
assertTextEndsWith() ¶ public
assertTextEndsWith(string $suffix, string $string, string $message = ''): void
Asserts that a string ends with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Parameters
-
string
$suffix The suffix to find.
-
string
$string The string to search.
-
string
$message optional The message to use for failure.
Returns
void
assertTextEquals() ¶ public
assertTextEquals(string $expected, string $result, string $message = ''): void
Assert text equality, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Parameters
-
string
$expected The expected value.
-
string
$result The actual value.
-
string
$message optional The message to use for failure.
Returns
void
assertTextNotContains() ¶ public
assertTextNotContains(string $needle, string $haystack, string $message = '', bool $ignoreCase = false): void
Assert that a text doesn't contain another text, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Parameters
-
string
$needle The string to search for.
-
string
$haystack The string to search through.
-
string
$message optional The message to display on failure.
-
bool
$ignoreCase optional Whether or not the search should be case-sensitive.
Returns
void
assertTextNotEquals() ¶ public
assertTextNotEquals(string $expected, string $result, string $message = ''): void
Assert text equality, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Parameters
-
string
$expected The expected value.
-
string
$result The actual value.
-
string
$message optional The message to use for failure.
Returns
void
assertTextStartsNotWith() ¶ public
assertTextStartsNotWith(string $prefix, string $string, string $message = ''): void
Asserts that a string starts not with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Parameters
-
string
$prefix The prefix to not find.
-
string
$string The string to search.
-
string
$message optional The message to use for failure.
Returns
void
assertTextStartsWith() ¶ public
assertTextStartsWith(string $prefix, string $string, string $message = ''): void
Asserts that a string starts with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Parameters
-
string
$prefix The prefix to check for.
-
string
$string The string to search in.
-
string
$message optional The message to use for failure.
Returns
void
assertThat() ¶ public static
assertThat(mixed $value, Constraint $constraint, string $message = '')
Evaluates a PHPUnit\Framework\Constraint matcher object.
Parameters
-
mixed
$value -
Constraint
$constraint -
string
$message optional
assertTrue() ¶ public static
assertTrue(bool $condition, string $message = '')
Asserts that a condition is true.
Parameters
-
bool
$condition -
string
$message optional
Throws
AssertionFailedError
assertWithinRange() ¶ protected static
assertWithinRange(float $expected, float $result, float $margin, string $message = ''): void
Compatibility function to test if a value is between an acceptable range.
Parameters
-
float
$expected -
float
$result -
float
$margin the rage of acceptation
-
string
$message optional the text to display if the assertion is not correct
Returns
void
assertXmlFileEqualsXmlFile() ¶ public static
assertXmlFileEqualsXmlFile(string $expectedFile, string $actualFile, string $message = '')
Asserts that two XML files are equal.
Parameters
-
string
$expectedFile -
string
$actualFile -
string
$message optional
assertXmlFileNotEqualsXmlFile() ¶ public static
assertXmlFileNotEqualsXmlFile(string $expectedFile, string $actualFile, string $message = '')
Asserts that two XML files are not equal.
Parameters
-
string
$expectedFile -
string
$actualFile -
string
$message optional
assertXmlStringEqualsXmlFile() ¶ public static
assertXmlStringEqualsXmlFile(string $expectedFile, string|DOMDocument $actualXml, string $message = '')
Asserts that two XML documents are equal.
Parameters
-
string
$expectedFile -
string|DOMDocument
$actualXml -
string
$message optional
assertXmlStringEqualsXmlString() ¶ public static
assertXmlStringEqualsXmlString(string|DOMDocument $expectedXml, string|DOMDocument $actualXml, string $message = '')
Asserts that two XML documents are equal.
Parameters
-
string|DOMDocument
$expectedXml -
string|DOMDocument
$actualXml -
string
$message optional
assertXmlStringNotEqualsXmlFile() ¶ public static
assertXmlStringNotEqualsXmlFile(string $expectedFile, string|DOMDocument $actualXml, string $message = '')
Asserts that two XML documents are not equal.
Parameters
-
string
$expectedFile -
string|DOMDocument
$actualXml -
string
$message optional
assertXmlStringNotEqualsXmlString() ¶ public static
assertXmlStringNotEqualsXmlString(string|DOMDocument $expectedXml, string|DOMDocument $actualXml, string $message = '')
Asserts that two XML documents are not equal.
Parameters
-
string|DOMDocument
$expectedXml -
string|DOMDocument
$actualXml -
string
$message optional
at() ¶ public static
at(int $index): InvokedAtIndexMatcher
Returns a matcher that matches when the method is executed at the given index.
Parameters
-
int
$index
Returns
InvokedAtIndexMatcher
atLeast() ¶ public static
atLeast(int $requiredInvocations): InvokedAtLeastCountMatcher
Returns a matcher that matches when the method is executed at least N times.
Parameters
-
int
$requiredInvocations
Returns
InvokedAtLeastCountMatcher
atLeastOnce() ¶ public static
atLeastOnce(): InvokedAtLeastOnceMatcher
Returns a matcher that matches when the method is executed at least once.
Returns
InvokedAtLeastOnceMatcher
atMost() ¶ public static
atMost(int $allowedInvocations): InvokedAtMostCountMatcher
Returns a matcher that matches when the method is executed at most N times.
Parameters
-
int
$allowedInvocations
Returns
InvokedAtMostCountMatcher
attribute() ¶ public static
attribute(Constraint $constraint, string $attributeName): Attribute
Parameters
-
Constraint
$constraint -
string
$attributeName
Returns
Attribute
attributeEqualTo() ¶ public static
attributeEqualTo(string $attributeName, mixed $value, float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false): Attribute
Parameters
-
string
$attributeName -
mixed
$value -
float
$delta optional -
int
$maxDepth optional -
bool
$canonicalize optional -
bool
$ignoreCase optional
Returns
Attribute
callback() ¶ public static
callback(callable $callback): Callback
Parameters
-
callable
$callback
Returns
Callback
classHasAttribute() ¶ public static
classHasAttribute(string $attributeName): ClassHasAttribute
Parameters
-
string
$attributeName
Returns
ClassHasAttribute
classHasStaticAttribute() ¶ public static
classHasStaticAttribute(string $attributeName): ClassHasStaticAttribute
Parameters
-
string
$attributeName
Returns
ClassHasStaticAttribute
clearPlugins() ¶ public
clearPlugins(): void
Clear all plugins from the global plugin collection.
Useful in test case teardown methods.
Returns
void
configApplication() ¶ public
configApplication(string $class, array|null $constructorArgs): void
Configure the application class to use in integration tests.
Combined with useHttpServer()
to customize the class name and constructor arguments
of your application class.
Parameters
-
string
$class The application class name.
-
array|null
$constructorArgs The constructor arguments for your application class.
Returns
void
configRequest() ¶ public
configRequest(array $data): void
Configures the data for the next request.
This data is cleared in the tearDown() method.
You can call this method multiple times to append into the current state.
Parameters
-
array
$data The request data to use.
Returns
void
contains() ¶ public static
contains(mixed $value, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): TraversableContains
Parameters
-
mixed
$value -
bool
$checkForObjectIdentity optional -
bool
$checkForNonObjectIdentity optional
Returns
TraversableContains
containsOnly() ¶ public static
containsOnly(string $type): TraversableContainsOnly
Parameters
-
string
$type
Returns
TraversableContainsOnly
containsOnlyInstancesOf() ¶ public static
containsOnlyInstancesOf(string $classname): TraversableContainsOnly
Parameters
-
string
$classname
Returns
TraversableContainsOnly
controllerSpy() ¶ public
controllerSpy(Cake\Event\Event $event, Cake\Controller\Controller|null $controller = null): void
Adds additional event spies to the controller/view event manager.
Parameters
-
Cake\Event\Event
$event A dispatcher event.
-
Cake\Controller\Controller|null
$controller optional Controller instance.
Returns
void
cookie() ¶ public
cookie(string $name, mixed $value): void
Sets a request cookie for future requests.
This method lets you configure the session data you want to be used for requests that follow. The session state is reset in each tearDown().
You can call this method multiple times to append into the current state.
Parameters
-
string
$name The cookie name to use.
-
mixed
$value The value of the cookie.
Returns
void
cookieEncrypted() ¶ public
cookieEncrypted(string $name, mixed $value, string|bool $encrypt = 'aes', string|null $key = null): void
Sets a encrypted request cookie for future requests.
The difference from cookie() is this encrypts the cookie value like the CookieComponent.
Parameters
-
string
$name The cookie name to use.
-
mixed
$value The value of the cookie.
-
string|bool
$encrypt optional Encryption mode to use.
-
string|null
$key optional Encryption key used. Defaults to Security.salt.
Returns
void
See Also
count() ¶ public
count(): int
Counts the number of test cases executed by run(TestResult result).
Returns
int
createConfiguredMock() ¶ protected
createConfiguredMock(string $originalClassName, array $configuration): MockObject
Returns a configured test double for the specified class.
Parameters
-
string
$originalClassName -
array
$configuration
Returns
MockObject
Throws
Exception
createMock() ¶ protected
createMock(string $originalClassName): MockObject
Returns a test double for the specified class.
Parameters
-
string
$originalClassName
Returns
MockObject
Throws
Exception
createPartialMock() ¶ protected
createPartialMock(string $originalClassName, string[] $methods): MockObject
Returns a partial test double for the specified class.
Parameters
-
string
$originalClassName -
string[]
$methods
Returns
MockObject
Throws
Exception
createResult() ¶ protected
createResult(): TestResult
Creates a default TestResult object.
Returns
TestResult
createTestProxy() ¶ protected
createTestProxy(string $originalClassName, array $constructorArguments = []): MockObject
Returns a test proxy for the specified class.
Parameters
-
string
$originalClassName -
array
$constructorArguments optional
Returns
MockObject
Throws
Exception
delete() ¶ public
delete(string|array $url): void
Performs a DELETE request using the current request data.
The response of the dispatched request will be stored as a property. You can use various assert methods to check the response.
Parameters
-
string|array
$url The URL to request.
Returns
void
Throws
PHPUnit\Exception
deprecated() ¶ public
deprecated(callable $callable): void
Helper method for check deprecation methods
Parameters
-
callable
$callable callable function that will receive asserts
Returns
void
disableErrorHandlerMiddleware() ¶ public
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.
Returns
void
enableCsrfToken() ¶ public
enableCsrfToken(): void
Calling this method will add a CSRF token to the request.
Both the POST data and cookie will be populated when this option is enabled. The default parameter names will be used.
Returns
void
enableRetainFlashMessages() ¶ public
enableRetainFlashMessages(): void
Calling this method will re-store flash messages into the test session after being removed by the FlashHelper
Returns
void
enableSecurityToken() ¶ public
enableSecurityToken(): void
Calling this method will enable a SecurityComponent compatible token to be added to request data. This lets you easily test actions protected by SecurityComponent.
Returns
void
equalTo() ¶ public static
equalTo(mixed $value, float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false): IsEqual
Parameters
-
mixed
$value -
float
$delta optional -
int
$maxDepth optional -
bool
$canonicalize optional -
bool
$ignoreCase optional
Returns
IsEqual
exactly() ¶ public static
exactly(int $count): InvokedCountMatcher
Returns a matcher that matches when the method is executed exactly $count times.
Parameters
-
int
$count
Returns
InvokedCountMatcher
expectExceptionCode() ¶ public
expectExceptionCode(int|string $code)
Parameters
-
int|string
$code
Throws
Exception
expectExceptionMessage() ¶ public
expectExceptionMessage(string $message)
Parameters
-
string
$message
Throws
Exception
expectExceptionMessageRegExp() ¶ public
expectExceptionMessageRegExp(string $messageRegExp)
Parameters
-
string
$messageRegExp
Throws
Exception
expectExceptionObject() ¶ public
expectExceptionObject(Exception $exception)
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.
Parameters
-
Exception
$exception
expectOutputRegex() ¶ public
expectOutputRegex(string $expectedRegex)
Parameters
-
string
$expectedRegex
Throws
Exception
expectOutputString() ¶ public
expectOutputString(string $expectedString)
Parameters
-
string
$expectedString
extractExceptionMessage() ¶ protected
extractExceptionMessage(Exception $exception): string
Extract verbose message for existing exception
Parameters
-
Exception
$exception Exception to extract
Returns
string
extractVerboseMessage() ¶ protected
extractVerboseMessage(string $message = null): string|null
Inspect controller to extract possible causes of the failed assertion
Parameters
-
string
$message optional Original message to use as a base
Returns
string|null
fail() ¶ public static
fail(string $message = '')
Fails a test with the given message.
Parameters
-
string
$message optional
Throws
AssertionFailedError
get() ¶ public
get(string|array $url): void
Performs a GET request using the current request data.
The response of the dispatched request will be stored as a property. You can use various assert methods to check the response.
Parameters
-
string|array
$url The URL to request.
Returns
void
Throws
PHPUnit\Exception
getAnnotations() ¶ public
getAnnotations(): array
Returns the annotations for this test.
Returns
array
getDataSetAsString() ¶ public
getDataSetAsString(bool $includeData = true): string
Gets the data set description of a TestCase.
Parameters
-
bool
$includeData optional
Returns
string
getExpectedExceptionCode() ¶ public
getExpectedExceptionCode(): null|int|string
Returns
null|int|string
getExpectedExceptionMessageRegExp() ¶ public
getExpectedExceptionMessageRegExp(): string
Returns
string
getMockBuilder() ¶ public
getMockBuilder(string|string[] $className): MockBuilder
Returns a builder object to create mock objects using a fluent interface.
Parameters
-
string|string[]
$className
Returns
MockBuilder
getMockClass() ¶ protected
getMockClass(string $originalClassName, 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.
Parameters
-
string
$originalClassName -
array
$methods optional -
array
$arguments optional -
string
$mockClassName optional -
bool
$callOriginalConstructor optional -
bool
$callOriginalClone optional -
bool
$callAutoload optional -
bool
$cloneArguments optional
Returns
string
getMockForAbstractClass() ¶ protected
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).
Parameters
-
string
$originalClassName -
array
$arguments optional -
string
$mockClassName optional -
bool
$callOriginalConstructor optional -
bool
$callOriginalClone optional -
bool
$callAutoload optional -
array
$mockedMethods optional -
bool
$cloneArguments optional
Returns
MockObject
getMockForModel() ¶ public
getMockForModel(string $alias, string[]|null $methods = [], array $options = []): Cake\ORM\TablePHPUnit_Framework_MockObject_MockObject
Mock a model, maintain fixtures and table association
Parameters
-
string
$alias The model to get a mock for.
-
string[]|null
$methods optional The list of methods to mock
-
array
$options optional The config data for the mock's constructor.
Returns
Cake\ORM\TablePHPUnit_Framework_MockObject_MockObject
Throws
Cake\ORM\Exception\MissingTableClassException
getMockForTrait() ¶ protected
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.
Parameters
-
string
$traitName -
array
$arguments optional -
string
$mockClassName optional -
bool
$callOriginalConstructor optional -
bool
$callOriginalClone optional -
bool
$callAutoload optional -
array
$mockedMethods optional -
bool
$cloneArguments optional
Returns
MockObject
getMockFromWsdl() ¶ protected
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.
Parameters
-
string
$wsdlFile -
string
$originalClassName optional -
string
$mockClassName optional -
array
$methods optional -
bool
$callOriginalConstructor optional -
array
$options optional An array of options passed to SOAPClient::_construct
Returns
MockObject
getName() ¶ public
getName(bool $withDataSet = true): string
Gets the name of a TestCase.
Parameters
-
bool
$withDataSet optional
Returns
string
getNumAssertions() ¶ public
getNumAssertions(): int
Returns the number of assertions performed by this test.
Returns
int
getObjectAttribute() ¶ public static
getObjectAttribute(object $object, string $attributeName): mixed
Returns the value of an object's attribute. This also works for attributes that are declared protected or private.
Parameters
-
object
$object -
string
$attributeName
Returns
mixed
Throws
Exception
getObjectForTrait() ¶ protected
getObjectForTrait(string $traitName, array $arguments = [], string $traitClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true): object
Returns an object for the specified trait.
Parameters
-
string
$traitName -
array
$arguments optional -
string
$traitClassName optional -
bool
$callOriginalConstructor optional -
bool
$callOriginalClone optional -
bool
$callAutoload optional
Returns
object
Throws
Exception
getProvidedData() ¶ protected
getProvidedData(): array
Gets the data set of a TestCase.
Returns
array
getStaticAttribute() ¶ public static
getStaticAttribute(string $className, string $attributeName): mixed
Returns the value of a static attribute. This also works for attributes that are declared protected or private.
Parameters
-
string
$className -
string
$attributeName
Returns
mixed
Throws
Exception
getStatusMessage() ¶ public
getStatusMessage(): string
Returns the status message of this test.
Returns
string
getTableLocator() ¶ public
getTableLocator(): Cake\ORM\Locator\LocatorInterface
Gets the table locator.
Returns
Cake\ORM\Locator\LocatorInterface
greaterThan() ¶ public static
greaterThan(mixed $value): GreaterThan
Parameters
-
mixed
$value
Returns
GreaterThan
greaterThanOrEqual() ¶ public static
greaterThanOrEqual(mixed $value): LogicalOr
Parameters
-
mixed
$value
Returns
LogicalOr
hasDependencies() ¶ public
hasDependencies(): bool
Returns true if the tests has dependencies
Returns
bool
head() ¶ public
head(string|array $url): void
Performs a HEAD request using the current request data.
The response of the dispatched request will be stored as a property. You can use various assert methods to check the response.
Parameters
-
string|array
$url The URL to request.
Returns
void
Throws
PHPUnit\Exception
identicalTo() ¶ public static
identicalTo(mixed $value): IsIdentical
Parameters
-
mixed
$value
Returns
IsIdentical
iniSet() ¶ protected
iniSet(string $varName, string $newValue)
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.
Parameters
-
string
$varName -
string
$newValue
Throws
Exception
isInstanceOf() ¶ public static
isInstanceOf(string $className): IsInstanceOf
Parameters
-
string
$className
Returns
IsInstanceOf
lessThan() ¶ public static
lessThan(mixed $value): LessThan
Parameters
-
mixed
$value
Returns
LessThan
lessThanOrEqual() ¶ public static
lessThanOrEqual(mixed $value): LogicalOr
Parameters
-
mixed
$value
Returns
LogicalOr
loadFixtures() ¶ public
loadFixtures(): void
Chooses which fixtures to load for a given test
Each parameter is a model name that corresponds to a fixture, i.e. 'Posts', 'Authors', etc. Passing no parameters will cause all fixtures on the test case to load.
Returns
void
Throws
Exception
when no fixture manager is available.
See Also
loadPlugins() ¶ public
loadPlugins(array $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.
Parameters
-
array
$plugins optional List of Plugins to load.
Returns
Cake\Http\BaseApplication
logicalNot() ¶ public static
logicalNot(Constraint $constraint): LogicalNot
Parameters
-
Constraint
$constraint
Returns
LogicalNot
markTestIncomplete() ¶ public static
markTestIncomplete(string $message = '')
Mark the test as incomplete.
Parameters
-
string
$message optional
Throws
IncompleteTestError
markTestSkipped() ¶ public static
markTestSkipped(string $message = '')
Mark the test as skipped.
Parameters
-
string
$message optional
Throws
SkippedTestError
matches() ¶ public static
matches(string $string): StringMatchesFormatDescription
Parameters
-
string
$string
Returns
StringMatchesFormatDescription
matchesRegularExpression() ¶ public static
matchesRegularExpression(string $pattern): RegularExpression
Parameters
-
string
$pattern
Returns
RegularExpression
never() ¶ public static
never(): InvokedCountMatcher
Returns a matcher that matches when the method is never executed.
Returns
InvokedCountMatcher
objectHasAttribute() ¶ public static
objectHasAttribute(string $attributeName): ObjectHasAttribute
Parameters
-
string
$attributeName
Returns
ObjectHasAttribute
onConsecutiveCalls() ¶ public static
onConsecutiveCalls(): ConsecutiveCallsStub
Returns
ConsecutiveCallsStub
onNotSuccessfulTest() ¶ protected
onNotSuccessfulTest(Throwable $t)
This method is called when a test method did not execute successfully.
Parameters
-
Throwable
$t
Throws
Throwable
once() ¶ public static
once(): InvokedCountMatcher
Returns a matcher that matches when the method is executed exactly once.
Returns
InvokedCountMatcher
options() ¶ public
options(string|array $url): void
Performs an OPTIONS request using the current request data.
The response of the dispatched request will be stored as a property. You can use various assert methods to check the response.
Parameters
-
string|array
$url The URL to request.
Returns
void
Throws
PHPUnit\Exception
patch() ¶ public
patch(string|array $url, string|array|null $data = []): void
Performs a PATCH request using the current request data.
The response of the dispatched request will be stored as a property. You can use various assert methods to check the response.
Parameters
-
string|array
$url The URL to request.
-
string|array|null
$data optional The data for the request.
Returns
void
Throws
PHPUnit\Exception
post() ¶ public
post(string|array $url, string|array|null $data = []): void
Performs a POST request using the current request data.
The response of the dispatched request will be stored as a property. You can use various assert methods to check the response.
Parameters
-
string|array
$url The URL to request.
-
string|array|null
$data optional The data for the request.
Returns
void
Throws
PHPUnit\Exception
prepareTemplate() ¶ protected
prepareTemplate(Text_Template $template)
Performs custom preparations on the process isolation template.
Parameters
-
Text_Template
$template
prophesize() ¶ protected
prophesize(string|null $classOrInterface = null): Prophecy\Prophecy\ObjectProphecy
Parameters
-
string|null
$classOrInterface optional
Returns
Prophecy\Prophecy\ObjectProphecy
Throws
LogicException
put() ¶ public
put(string|array $url, string|array|null $data = []): void
Performs a PUT request using the current request data.
The response of the dispatched request will be stored as a property. You can use various assert methods to check the response.
Parameters
-
string|array
$url The URL to request.
-
string|array|null
$data optional The data for the request.
Returns
void
Throws
PHPUnit\Exception
readAttribute() ¶ public static
readAttribute(string|object $classOrObject, string $attributeName): mixed
Returns the value of an attribute of a class or an object. This also works for attributes that are declared protected or private.
Parameters
-
string|object
$classOrObject -
string
$attributeName
Returns
mixed
Throws
Exception
registerComparator() ¶ public
registerComparator(Comparator $comparator)
Parameters
-
Comparator
$comparator
registerMockObject() ¶ public
registerMockObject(MockObject $mockObject)
Parameters
-
MockObject
$mockObject
removePlugins() ¶ public
removePlugins(string[] $names = []): void
Remove plugins from the global plugin collection.
Useful in test case teardown methods.
Parameters
-
string[]
$names optional A list of plugins you want to remove.
Returns
void
returnArgument() ¶ public static
returnArgument(int $argumentIndex): ReturnArgumentStub
Parameters
-
int
$argumentIndex
Returns
ReturnArgumentStub
returnCallback() ¶ public static
returnCallback(mixed $callback): ReturnCallbackStub
Parameters
-
mixed
$callback
Returns
ReturnCallbackStub
returnSelf() ¶ public static
returnSelf(): ReturnSelfStub
Returns the current object.
This method is useful when mocking a fluent interface.
Returns
ReturnSelfStub
returnValue() ¶ public static
returnValue(mixed $value): ReturnStub
Parameters
-
mixed
$value
Returns
ReturnStub
returnValueMap() ¶ public static
returnValueMap(array $valueMap): ReturnValueMapStub
Parameters
-
array
$valueMap
Returns
ReturnValueMapStub
run() ¶ public
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.
Parameters
-
TestResult
$result optional
Returns
TestResult
Throws
Exception
runTest() ¶ protected
runTest(): mixed
Override to run the test and assert its state.
Returns
mixed
Throws
Exception|Exception
Exception
session() ¶ public
session(array $data): void
Sets session data.
This method lets you configure the session data you want to be used for requests that follow. The session state is reset in each tearDown().
You can call this method multiple times to append into the current state.
Parameters
-
array
$data The session data to use.
Returns
void
setAppNamespace() ¶ public static
setAppNamespace(string $appNamespace = 'TestApp'): void
Set the app namespace
Parameters
-
string
$appNamespace optional The app namespace, defaults to "TestApp".
Returns
void
setBackupGlobals() ¶ public
setBackupGlobals(bool $backupGlobals)
Calling this method in setUp() has no effect!
Parameters
-
bool
$backupGlobals
setBackupStaticAttributes() ¶ public
setBackupStaticAttributes(bool $backupStaticAttributes)
Calling this method in setUp() has no effect!
Parameters
-
bool
$backupStaticAttributes
setBeStrictAboutChangesToGlobalState() ¶ public
setBeStrictAboutChangesToGlobalState(bool $beStrictAboutChangesToGlobalState)
Parameters
-
bool
$beStrictAboutChangesToGlobalState
setDependencies() ¶ public
setDependencies(string[] $dependencies)
Sets the dependencies of a TestCase.
Parameters
-
string[]
$dependencies
setDependencyInput() ¶ public
setDependencyInput(array $dependencyInput)
Sets
Parameters
-
array
$dependencyInput
setInIsolation() ¶ public
setInIsolation(bool $inIsolation)
Parameters
-
bool
$inIsolation
Throws
Exception
setLocale() ¶ protected
setLocale()
This method is a wrapper for the setlocale() function that automatically resets the locale to its original value after the test is run.
Throws
Exception
setOutputCallback() ¶ public
setOutputCallback(callable $callback)
Parameters
-
callable
$callback
Throws
Exception
setPreserveGlobalState() ¶ public
setPreserveGlobalState(bool $preserveGlobalState)
Parameters
-
bool
$preserveGlobalState
Throws
Exception
setRegisterMockObjectsFromTestArgumentsRecursively() ¶ public
setRegisterMockObjectsFromTestArgumentsRecursively(bool $flag)
Parameters
-
bool
$flag
setRunClassInSeparateProcess() ¶ public
setRunClassInSeparateProcess(bool $runClassInSeparateProcess)
Parameters
-
bool
$runClassInSeparateProcess
Throws
Exception
setRunTestInSeparateProcess() ¶ public
setRunTestInSeparateProcess(bool $runTestInSeparateProcess)
Parameters
-
bool
$runTestInSeparateProcess
Throws
Exception
setTableLocator() ¶ public
setTableLocator(Cake\ORM\Locator\LocatorInterface $tableLocator): $this
Sets the table locator.
Parameters
-
Cake\ORM\Locator\LocatorInterface
$tableLocator LocatorInterface instance.
Returns
$this
setTestResultObject() ¶ public
setTestResultObject(TestResult $result)
Parameters
-
TestResult
$result
setUnlockedFields() ¶ public
setUnlockedFields(string[] $unlockedFields = []): void
Set list of fields that are excluded from field validation.
Parameters
-
string[]
$unlockedFields optional List of fields that are excluded from field validation.
Returns
void
setUp() ¶ public
setUp(): void
Setup the test case, backup the static object values so they can be restored. Specifically backs up the contents of Configure and paths in App if they have not already been backed up.
Returns
void
setUpBeforeClass() ¶ public static
setUpBeforeClass()
This method is called before the first test of this test class is run.
setUseErrorHandler() ¶ public
setUseErrorHandler(bool $useErrorHandler)
Parameters
-
bool
$useErrorHandler
setupServer() ¶ public
setupServer(): void
Auto-detect if the HTTP middleware stack should be used.
Returns
void
skipIf() ¶ public
skipIf(bool $shouldSkip, string $message = ''): bool
Overrides SimpleTestCase::skipIf to provide a boolean return value
Parameters
-
bool
$shouldSkip Whether or not the test should be skipped.
-
string
$message optional The message to display.
Returns
bool
skipUnless() ¶ protected
skipUnless(bool $condition, string $message = ''): bool
Compatibility function for skipping.
Parameters
-
bool
$condition Condition to trigger skipping
-
string
$message optional Message for skip
Returns
bool
stringContains() ¶ public static
stringContains(string $string, bool $case = true): StringContains
Parameters
-
string
$string -
bool
$case optional
Returns
StringContains
stringEndsWith() ¶ public static
stringEndsWith(mixed $suffix): StringEndsWith
Parameters
-
mixed
$suffix
Returns
StringEndsWith
stringStartsWith() ¶ public static
stringStartsWith(mixed $prefix): StringStartsWith
Parameters
-
mixed
$prefix
Returns
StringStartsWith
tableLocator() ¶ public
tableLocator(Cake\ORM\Locator\LocatorInterface|null $tableLocator = null): Cake\ORM\Locator\LocatorInterface
Sets the table locator. If no parameters are passed, it will return the currently used locator.
Parameters
-
Cake\ORM\Locator\LocatorInterface|null
$tableLocator optional LocatorInterface instance.
Returns
Cake\ORM\Locator\LocatorInterface
tearDown() ¶ public
tearDown(): void
teardown any static object changes and restore them.
Returns
void
tearDownAfterClass() ¶ public static
tearDownAfterClass()
This method is called after the last test of this test class is run.
throwException() ¶ public static
throwException(Throwable $exception): ExceptionStub
Parameters
-
Throwable
$exception
Returns
ExceptionStub
toString() ¶ public
toString(): string
Returns a string representation of the test case.
Returns
string
useHttpServer() ¶ public
useHttpServer(bool $enable): void
Toggle whether or not you want to use the HTTP Server stack.
Parameters
-
bool
$enable Enable/disable the usage of the HTTP Stack.
Returns
void
viewVariable() ¶ public
viewVariable(string $name): mixed
Fetches a view variable by name.
If the view variable does not exist, null will be returned.
Parameters
-
string
$name The view variable to get.
Returns
mixed
withErrorReporting() ¶ public
withErrorReporting(int $errorLevel, callable $callable): void
Helper method for tests that needs to use error_reporting()
Parameters
-
int
$errorLevel value of error_reporting() that needs to use
-
callable
$callable callable function that will receive asserts
Returns
void
Property Detail
$_controller ¶ protected
The controller used in the last request.
Type
Cake\Controller\Controller|null
$_csrfToken ¶ protected
Boolean flag for whether or not the request should have a CSRF token added.
Type
bool
$_retainFlashMessages ¶ protected
Boolean flag for whether or not the request should re-store flash messages
Type
bool
$_securityToken ¶ protected
Boolean flag for whether or not the request should have a SecurityComponent token added.
Type
bool
$_useHttpServer ¶ protected
Track whether or not tests are run against the PSR7 HTTP stack.
Type
bool
$autoFixtures ¶ public
By default, all fixtures attached to this class will be truncated and reloaded after each test. Set this to false to handle manually
Type
bool
$backupGlobals ¶ protected
Enable or disable the backup and restoration of the $GLOBALS array. Overwrite this attribute in a child class of TestCase. Setting this attribute in setUp() has no effect!
Type
bool
$backupStaticAttributes ¶ protected
Enable or disable the backup and restoration of static attributes. Overwrite this attribute in a child class of TestCase. Setting this attribute in setUp() has no effect!
Type
bool
$dropTables ¶ public
Control table create/drops on each test method.
If true, tables will still be dropped at the end of each test runner execution.
Type
bool
$fixtureManager ¶ public
The class responsible for managing the creation, loading and removing of fixtures
Type
Cake\TestSuite\Fixture\FixtureManager|null
$preserveGlobalState ¶ protected
Whether or not this test should preserve the global state when running in a separate PHP process.
Type
bool
$runTestInSeparateProcess ¶ protected
Whether or not this test is to be run in a separate PHP process.
Type
bool