Cake TestCase class
array
Configure values to restore at end of test.
Cake\ORM\Locator\LocatorInterface|null
Table locator instance
bool
By default, all fixtures attached to this class will be truncated and reloaded after each test. Set this to false to handle manually
?bool
string[]
string[]
bool
array<string, array<int, string>>
array<string, array<int, string>>
string|null
This object's default table alias.
bool
Control table create/drops on each test method.
Cake\TestSuite\Fixture\FixtureManager|null
The class responsible for managing the creation, loading and removing of fixtures
Cake\TestSuite\Fixture\FixtureStrategyInterface|null
array<string>
Fixtures used by this test case.
bool
list<ExecutionOrderDependency>
bool
Check the attributes as part of an assertTags() check.
Gets the class name for the table.
Normalize a path for comparison.
Adds a fixture to this test case.
Returns a matcher that matches when the method is executed zero or more times.
Asserts that an array has a specified key.
Asserts that an array does not have a specified key.
Asserts that a class has a specified attribute.
Asserts that a class has a specified static attribute.
Asserts that a class does not have a specified attribute.
Asserts that a class does not have a specified static attribute.
Asserts that a haystack contains a needle.
Asserts that a haystack contains only values of a given type.
Asserts that a haystack contains only instances of a given class name.
Asserts the number of elements of an array, Countable or Traversable.
Asserts that a directory does not exist.
Asserts that a directory exists.
Asserts that a directory exists and is not readable.
Asserts that a directory exists and is not writable.
Asserts that a directory exists and is readable.
Asserts that a directory exists and is writable.
Asserts that a directory does not exist.
Asserts that a directory exists and is not readable.
Asserts that a directory exists and is not writable.
Asserts that a string does not match a given regular expression.
Asserts that a variable is empty.
Asserts that a hierarchy of DOMElements matches.
Asserts that two variables are equal.
Asserts that two variables are equal (canonicalizing).
Asserts that two variables are equal (ignoring case).
Assert that a string matches SQL with db-specific characters like quotes removed.
Asserts that two variables are equal (with delta).
Asserts that a global event was fired. You must track events in your event manager for this assertion to work
Asserts an event was fired with data
Asserts that a condition is false.
Asserts that a file does not exist.
Asserts that the contents of one file is equal to the contents of another file.
Asserts that the contents of one file is equal to the contents of another file (canonicalizing).
Asserts that the contents of one file is equal to the contents of another file (ignoring case).
Asserts that a file exists.
Asserts that a file exists and is not readable.
Asserts that a file exists and is not writable.
Asserts that a file exists and is readable.
Asserts that a file exists and is writable.
Asserts that the contents of one file is not equal to the contents of another file.
Asserts that the contents of one file is not equal to the contents of another file (canonicalizing).
Asserts that the contents of one file is not equal to the contents of another file (ignoring case).
Asserts that a file does not exist.
Asserts that a file exists and is not readable.
Asserts that a file exists and is not writable.
Asserts that a variable is finite.
Asserts that a value is greater than another value.
Asserts that a value is greater than or equal to another value.
Asserts HTML tags.
Asserts that a variable is infinite.
Asserts that a variable is of a given type.
Asserts that a variable is of type array.
Asserts that a variable is of type bool.
Asserts that a variable is of type callable.
Asserts that a variable is of type resource and is closed.
Asserts that a variable is of type float.
Asserts that a variable is of type int.
Asserts that a variable is of type iterable.
Asserts that a variable is not of type array.
Asserts that a variable is not of type bool.
Asserts that a variable is not of type callable.
Asserts that a variable is not of type resource.
Asserts that a variable is not of type float.
Asserts that a variable is not of type int.
Asserts that a variable is not of type iterable.
Asserts that a variable is not of type numeric.
Asserts that a variable is not of type object.
Asserts that a file/dir exists and is not readable.
Asserts that a variable is not of type resource.
Asserts that a variable is not of type scalar.
Asserts that a variable is not of type string.
Asserts that a file/dir exists and is not writable.
Asserts that a variable is of type numeric.
Asserts that a variable is of type object.
Asserts that a file/dir is readable.
Asserts that a variable is of type resource.
Asserts that a variable is of type scalar.
Asserts that a variable is of type string.
Asserts that a file/dir exists and is writable.
Asserts that a string is a valid JSON string.
Asserts that two JSON files are equal.
Asserts that two JSON files are not equal.
Asserts that the generated JSON encoded object and the content of the given file are equal.
Asserts that two given JSON encoded objects or arrays are equal.
Asserts that the generated JSON encoded object and the content of the given file are not equal.
Asserts that two given JSON encoded objects or arrays are not equal.
Asserts that a value is smaller than another value.
Asserts that a value is smaller than or equal to another value.
Asserts that a string matches a given regular expression.
Asserts that a variable is nan.
Asserts that a haystack does not contain a needle.
Asserts that a haystack does not contain only values of a given type.
Asserts the number of elements of an array, Countable or Traversable.
Asserts that a variable is not empty.
Asserts that two variables are not equal.
Asserts that two variables are not equal (canonicalizing).
Asserts that two variables are not equal (ignoring case).
Asserts that two variables are not equal (with delta).
Asserts that a condition is not false.
Asserts that a variable is not of a given type.
Asserts that a file/dir exists and is not readable.
Asserts that a file/dir exists and is not writable.
Asserts that a variable is not null.
Asserts that a string does not match a given regular expression.
Asserts that two variables do not have the same type and value. Used on objects, it asserts that two variables do not reference the same object.
Assert that the size of two arrays (or Countable
or Traversable
objects) is not the same.
Asserts that a condition is not true.
Compatibility function to test if a value is not between an acceptable range.
Asserts that a variable is null.
Asserts that an object has a specified attribute.
Asserts that an object does not have a specified attribute.
Compatibility function to test paths.
Performs assertions shared by all tests of a test case.
Performs assertions shared by all tests of a test case.
Asserts that a string matches a given regular expression.
Assertion for comparing a regex pattern against a query having its identifiers quoted. It accepts queries quoted with the characters <
and >
. If the third parameter is set to true, it will alter the pattern to both accept quoted and unquoted queries
Asserts that two variables have the same type and value. Used on objects, it asserts that two variables reference the same object.
Assert that the size of two arrays (or Countable
or Traversable
objects) is the same.
Asserts that a string ends not with a given suffix.
Asserts that a string ends with a given suffix.
Asserts that the contents of a string is equal to the contents of a file.
Asserts that the contents of a string is equal to the contents of a file (canonicalizing).
Asserts that the contents of a string is equal to the contents of a file (ignoring case).
Asserts that a string matches a given format string.
Asserts that a string matches a given format file.
Asserts that the contents of a string is not equal to the contents of a file.
Asserts that the contents of a string is not equal to the contents of a file (canonicalizing).
Asserts that the contents of a string is not equal to the contents of a file (ignoring case).
Asserts that a string does not match a given format string.
Asserts that a string does not match a given format string.
Asserts that a string starts not with a given prefix.
Asserts that a string starts with a given prefix.
Assert that a string contains another string, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Asserts that a string ends not with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Asserts that a string ends with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Assert text equality, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Assert that a text doesn't contain another text, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Assert text equality, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Asserts that a string starts not with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Asserts that a string starts with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Evaluates a PHPUnit\Framework\Constraint matcher object.
Asserts that a condition is true.
Compatibility function to test if a value is between an acceptable range.
Asserts that two XML files are equal.
Asserts that two XML files are not equal.
Asserts that two XML documents are equal.
Asserts that two XML documents are equal.
Asserts that two XML documents are not equal.
Asserts that two XML documents are not equal.
Returns a matcher that matches when the method is executed at the given index.
Returns a matcher that matches when the method is executed at least N times.
Returns a matcher that matches when the method is executed at least once.
Returns a matcher that matches when the method is executed at most N times.
Clear all plugins from the global plugin collection.
Returns a configured mock object for the specified class.
Returns a mock object for the specified class.
Returns a partial mock object for the specified class.
Creates a default TestResult object.
Makes configurable stub for the specified class.
Returns a test proxy for the specified class.
Helper method for check deprecation methods
Returns a matcher that matches when the method is executed exactly $count times.
Sets up an expectation for an exception to be raised by the code under test. Information for expected exception class, expected exception message, and expected exception code are retrieved from a given Exception object.
Fails a test with the given message.
Convenience method to get a table instance.
Return the current assertion count.
Returns fixture strategy used by these tests.
Get the fixtures this test should use.
Returns a builder object to create mock objects using a fluent interface.
Mocks the specified class and returns the name of the mocked class.
Returns a mock object for the specified abstract class with all abstract methods of the class mocked. Concrete methods are not mocked by default. To mock concrete methods, use the 7th parameter ($mockedMethods).
Mock a model, maintain fixtures and table association
Returns a mock object for the specified trait with all abstract methods of the trait mocked. Concrete methods to mock can be specified with the $mockedMethods
parameter.
Returns a mock object based on the given WSDL file.
Returns the number of assertions performed by this test.
Returns an object for the specified trait.
Gets the data set of a TestCase.
Returns the size of the test.
Gets the table locator.
This method is a wrapper for the ini_set() function that automatically resets the modified php.ini setting to its original value after the test is run.
Chooses which fixtures to load for a given test
Load plugins into a simulated application.
Load routes for the application.
Mark the test as incomplete.
Mark the test as skipped.
Returns a matcher that matches when the method is never executed.
This method is called when a test method did not execute successfully.
Returns a matcher that matches when the method is executed exactly once.
Returns the normalized test name as class::method.
Remove plugins from the global plugin collection.
Returns a list of normalized dependency names, class::method.
Reset the assertion counter.
Returns the current object.
Runs the test case and collects the results in a TestResult object. If no TestResult object is passed a new one will be created.
Override to run the test and assert its state.
Set the app namespace
This method is a wrapper for the setlocale() function that automatically resets the locale to its original value after the test is run.
Sets the table locator.
Setup the test case, backup the static object values so they can be restored. Specifically backs up the contents of Configure and paths in App if they have not already been backed up.
This method is called before the first test of this test class is run.
Initialized and loads any use fixtures.
Overrides SimpleTestCase::skipIf to provide a boolean return value
Compatibility function for skipping.
teardown any static object changes and restore them.
This method is called after the last test of this test class is run.
Unloads any use fixtures.
Returns a string representation of the test case.
Helper method for tests that needs to use error_reporting()
__construct(?string $name = null, array $data = [], int|string $dataName = '')
?string
$name optional array
$data optional int|string
$dataName optional _assertAttributes(array<string, mixed> $assertions, string $string, bool $fullDebug = false, array|string $regex = ''): string|false
Check the attributes as part of an assertTags() check.
array<string, mixed>
$assertions Assertions to run.
string
$string The HTML string to check.
bool
$fullDebug optional Whether more verbose output should be used.
array|string
$regex optional Full regexp from assertHtml
string|false
_getTableClassName(string $alias, array<string, mixed> $options): string
Gets the class name for the table.
string
$alias The model to get a mock for.
array<string, mixed>
$options The config data for the mock's constructor.
string
Cake\ORM\Exception\MissingTableClassException
_normalizePath(string $path): string
Normalize a path for comparison.
string
$path Path separated by "/" slash.
string
addFixture(string $fixture): $this
Adds a fixture to this test case.
Examples:
Use this method inside your test cases' {@link getFixtures()} method to build up the fixture list.
string
$fixture Fixture
$this
addToAssertionCount(int $count): void
int
$count void
addWarning(string $warning): void
string
$warning void
any(): AnyInvokedCountMatcher
Returns a matcher that matches when the method is executed zero or more times.
AnyInvokedCountMatcher
anything(): IsAnything
IsAnything
arrayHasKey(int|string $key): ArrayHasKey
int|string
$key ArrayHasKey
assertArrayHasKey(int|string $key, array|ArrayAccess $array, string $message = ''): void
Asserts that an array has a specified key.
int|string
$key array|ArrayAccess
$array string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertArrayNotHasKey(int|string $key, array|ArrayAccess $array, string $message = ''): void
Asserts that an array does not have a specified key.
int|string
$key array|ArrayAccess
$array string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertClassHasAttribute(string $attributeName, string $className, string $message = ''): void
Asserts that a class has a specified attribute.
string
$attributeName string
$className string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertClassHasStaticAttribute(string $attributeName, string $className, string $message = ''): void
Asserts that a class has a specified static attribute.
string
$attributeName string
$className string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertClassNotHasAttribute(string $attributeName, string $className, string $message = ''): void
Asserts that a class does not have a specified attribute.
string
$attributeName string
$className string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertClassNotHasStaticAttribute(string $attributeName, string $className, string $message = ''): void
Asserts that a class does not have a specified static attribute.
string
$attributeName string
$className string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertContains(mixed $needle, iterable $haystack, string $message = ''): void
Asserts that a haystack contains a needle.
iterable
$haystack string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertContainsEquals(mixed $needle, iterable $haystack, string $message = ''): void
iterable
$haystack string
$message optional void
assertContainsOnly(string $type, iterable $haystack, ?bool $isNativeType = null, string $message = ''): void
Asserts that a haystack contains only values of a given type.
string
$type iterable
$haystack ?bool
$isNativeType optional string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertContainsOnlyInstancesOf(string $className, iterable $haystack, string $message = ''): void
Asserts that a haystack contains only instances of a given class name.
string
$className iterable
$haystack string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertCount(int $expectedCount, Countable|iterable $haystack, string $message = ''): void
Asserts the number of elements of an array, Countable or Traversable.
int
$expectedCount Countable|iterable
$haystack string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertDirectoryDoesNotExist(string $directory, string $message = ''): void
Asserts that a directory does not exist.
string
$directory Directory
string
$message optional Message
void
SebastianBergmann\RecursionContext\InvalidArgumentException
assertDirectoryExists(string $directory, string $message = ''): void
Asserts that a directory exists.
string
$directory string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertDirectoryIsNotReadable(string $directory, string $message = ''): void
Asserts that a directory exists and is not readable.
string
$directory string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertDirectoryIsNotWritable(string $directory, string $message = ''): void
Asserts that a directory exists and is not writable.
string
$directory string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertDirectoryIsReadable(string $directory, string $message = ''): void
Asserts that a directory exists and is readable.
string
$directory string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertDirectoryIsWritable(string $directory, string $message = ''): void
Asserts that a directory exists and is writable.
string
$directory string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertDirectoryNotExists(string $directory, string $message = ''): void
Asserts that a directory does not exist.
string
$directory string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertDirectoryNotIsReadable(string $directory, string $message = ''): void
Asserts that a directory exists and is not readable.
string
$directory string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertDirectoryNotIsWritable(string $directory, string $message = ''): void
Asserts that a directory exists and is not writable.
string
$directory string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertDoesNotMatchRegularExpression(string $pattern, string $string, string $message = ''): void
Asserts that a string does not match a given regular expression.
string
$pattern Regex pattern
string
$string String to test
string
$message optional Message
void
SebastianBergmann\RecursionContext\InvalidArgumentException
assertEmpty(mixed $actual, string $message = ''): void
Asserts that a variable is empty.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertEqualXMLStructure(DOMElement $expectedElement, DOMElement $actualElement, bool $checkAttributes = false, string $message = ''): void
Asserts that a hierarchy of DOMElements matches.
DOMElement
$expectedElement DOMElement
$actualElement bool
$checkAttributes optional string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
AssertionFailedError
ExpectationFailedException
assertEquals(mixed $expected, mixed $actual, string $message = ''): void
Asserts that two variables are equal.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertEqualsCanonicalizing(mixed $expected, mixed $actual, string $message = ''): void
Asserts that two variables are equal (canonicalizing).
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertEqualsIgnoringCase(mixed $expected, mixed $actual, string $message = ''): void
Asserts that two variables are equal (ignoring case).
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertEqualsSql(string $expected, string $actual, string $message = ''): void
Assert that a string matches SQL with db-specific characters like quotes removed.
string
$expected The expected sql
string
$actual The sql to compare
string
$message optional The message to display on failure
void
assertEqualsWithDelta(mixed $expected, mixed $actual, float $delta, string $message = ''): void
Asserts that two variables are equal (with delta).
float
$delta string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertEventFired(string $name, Cake\Event\EventManager|null $eventManager = null, string $message = ''): void
Asserts that a global event was fired. You must track events in your event manager for this assertion to work
string
$name Event name
Cake\Event\EventManager|null
$eventManager optional Event manager to check, defaults to global event manager
string
$message optional Assertion failure message
void
assertEventFiredWith(string $name, string $dataKey, mixed $dataValue, Cake\Event\EventManager|null $eventManager = null, string $message = ''): void
Asserts an event was fired with data
If a third argument is passed, that value is used to compare with the value in $dataKey
string
$name Event name
string
$dataKey Data key
mixed
$dataValue Data value
Cake\Event\EventManager|null
$eventManager optional Event manager to check, defaults to global event manager
string
$message optional Assertion failure message
void
assertFalse(mixed $condition, string $message = ''): void
Asserts that a condition is false.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileDoesNotExist(string $filename, string $message = ''): void
Asserts that a file does not exist.
string
$filename Filename
string
$message optional Message
void
SebastianBergmann\RecursionContext\InvalidArgumentException
assertFileEquals(string $expected, string $actual, string $message = ''): void
Asserts that the contents of one file is equal to the contents of another file.
string
$expected string
$actual string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileEqualsCanonicalizing(string $expected, string $actual, string $message = ''): void
Asserts that the contents of one file is equal to the contents of another file (canonicalizing).
string
$expected string
$actual string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileEqualsIgnoringCase(string $expected, string $actual, string $message = ''): void
Asserts that the contents of one file is equal to the contents of another file (ignoring case).
string
$expected string
$actual string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileExists(string $filename, string $message = ''): void
Asserts that a file exists.
string
$filename string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileIsNotReadable(string $file, string $message = ''): void
Asserts that a file exists and is not readable.
string
$file string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileIsNotWritable(string $file, string $message = ''): void
Asserts that a file exists and is not writable.
string
$file string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileIsReadable(string $file, string $message = ''): void
Asserts that a file exists and is readable.
string
$file string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileIsWritable(string $file, string $message = ''): void
Asserts that a file exists and is writable.
string
$file string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileNotEquals(string $expected, string $actual, string $message = ''): void
Asserts that the contents of one file is not equal to the contents of another file.
string
$expected string
$actual string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileNotEqualsCanonicalizing(string $expected, string $actual, string $message = ''): void
Asserts that the contents of one file is not equal to the contents of another file (canonicalizing).
string
$expected string
$actual string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileNotEqualsIgnoringCase(string $expected, string $actual, string $message = ''): void
Asserts that the contents of one file is not equal to the contents of another file (ignoring case).
string
$expected string
$actual string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileNotExists(string $filename, string $message = ''): void
Asserts that a file does not exist.
string
$filename string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileNotIsReadable(string $file, string $message = ''): void
Asserts that a file exists and is not readable.
string
$file string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFileNotIsWritable(string $file, string $message = ''): void
Asserts that a file exists and is not writable.
string
$file string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertFinite(mixed $actual, string $message = ''): void
Asserts that a variable is finite.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertGreaterThan(mixed $expected, mixed $actual, string $message = ''): void
Asserts that a value is greater than another value.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertGreaterThanOrEqual(mixed $expected, mixed $actual, string $message = ''): void
Asserts that a value is greater than or equal to another value.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertHtml(array $expected, string $string, bool $fullDebug = false): bool
Asserts HTML tags.
Takes an array $expected and generates a regex from it to match the provided $string. Samples for $expected:
Checks for an input tag with a name attribute (contains any non-empty value) and an id attribute that contains 'my-input':
['input' => ['name', 'id' => 'my-input']]
Checks for two p elements with some text in them:
[ ['p' => true], 'textA', '/p', ['p' => true], 'textB', '/p' ]
You can also specify a pattern expression as part of the attribute values, or the tag being defined, if you prepend the value with preg: and enclose it with slashes, like so:
[ ['input' => ['name', 'id' => 'preg:/FieldName\d+/']], 'preg:/My\s+field/' ]
Important: This function is very forgiving about whitespace and also accepts any permutation of attribute order. It will also allow whitespace between specified tags.
array
$expected An array, see above
string
$string An HTML/XHTML/XML string
bool
$fullDebug optional Whether more verbose output should be used.
bool
assertInfinite(mixed $actual, string $message = ''): void
Asserts that a variable is infinite.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertInstanceOf(string $expected, mixed $actual, string $message = ''): void
Asserts that a variable is of a given type.
string
$expected string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertIsArray(mixed $actual, string $message = ''): void
Asserts that a variable is of type array.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsBool(mixed $actual, string $message = ''): void
Asserts that a variable is of type bool.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsCallable(mixed $actual, string $message = ''): void
Asserts that a variable is of type callable.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsClosedResource(mixed $actual, string $message = ''): void
Asserts that a variable is of type resource and is closed.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsFloat(mixed $actual, string $message = ''): void
Asserts that a variable is of type float.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsInt(mixed $actual, string $message = ''): void
Asserts that a variable is of type int.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsIterable(mixed $actual, string $message = ''): void
Asserts that a variable is of type iterable.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotArray(mixed $actual, string $message = ''): void
Asserts that a variable is not of type array.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotBool(mixed $actual, string $message = ''): void
Asserts that a variable is not of type bool.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotCallable(mixed $actual, string $message = ''): void
Asserts that a variable is not of type callable.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotClosedResource(mixed $actual, string $message = ''): void
Asserts that a variable is not of type resource.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotFloat(mixed $actual, string $message = ''): void
Asserts that a variable is not of type float.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotInt(mixed $actual, string $message = ''): void
Asserts that a variable is not of type int.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotIterable(mixed $actual, string $message = ''): void
Asserts that a variable is not of type iterable.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotNumeric(mixed $actual, string $message = ''): void
Asserts that a variable is not of type numeric.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotObject(mixed $actual, string $message = ''): void
Asserts that a variable is not of type object.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotReadable(string $filename, string $message = ''): void
Asserts that a file/dir exists and is not readable.
string
$filename string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotResource(mixed $actual, string $message = ''): void
Asserts that a variable is not of type resource.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotScalar(mixed $actual, string $message = ''): void
Asserts that a variable is not of type scalar.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotString(mixed $actual, string $message = ''): void
Asserts that a variable is not of type string.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNotWritable(string $filename, string $message = ''): void
Asserts that a file/dir exists and is not writable.
string
$filename string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsNumeric(mixed $actual, string $message = ''): void
Asserts that a variable is of type numeric.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsObject(mixed $actual, string $message = ''): void
Asserts that a variable is of type object.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsReadable(string $filename, string $message = ''): void
Asserts that a file/dir is readable.
string
$filename string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsResource(mixed $actual, string $message = ''): void
Asserts that a variable is of type resource.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsScalar(mixed $actual, string $message = ''): void
Asserts that a variable is of type scalar.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsString(mixed $actual, string $message = ''): void
Asserts that a variable is of type string.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertIsWritable(string $filename, string $message = ''): void
Asserts that a file/dir exists and is writable.
string
$filename string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertJson(string $actualJson, string $message = ''): void
Asserts that a string is a valid JSON string.
string
$actualJson string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertJsonFileEqualsJsonFile(string $expectedFile, string $actualFile, string $message = ''): void
Asserts that two JSON files are equal.
string
$expectedFile string
$actualFile string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertJsonFileNotEqualsJsonFile(string $expectedFile, string $actualFile, string $message = ''): void
Asserts that two JSON files are not equal.
string
$expectedFile string
$actualFile string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertJsonStringEqualsJsonFile(string $expectedFile, string $actualJson, string $message = ''): void
Asserts that the generated JSON encoded object and the content of the given file are equal.
string
$expectedFile string
$actualJson string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertJsonStringEqualsJsonString(string $expectedJson, string $actualJson, string $message = ''): void
Asserts that two given JSON encoded objects or arrays are equal.
string
$expectedJson string
$actualJson string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertJsonStringNotEqualsJsonFile(string $expectedFile, string $actualJson, string $message = ''): void
Asserts that the generated JSON encoded object and the content of the given file are not equal.
string
$expectedFile string
$actualJson string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertJsonStringNotEqualsJsonString(string $expectedJson, string $actualJson, string $message = ''): void
Asserts that two given JSON encoded objects or arrays are not equal.
string
$expectedJson string
$actualJson string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertLessThan(mixed $expected, mixed $actual, string $message = ''): void
Asserts that a value is smaller than another value.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertLessThanOrEqual(mixed $expected, mixed $actual, string $message = ''): void
Asserts that a value is smaller than or equal to another value.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void
Asserts that a string matches a given regular expression.
string
$pattern Regex pattern
string
$string String to test
string
$message optional Message
void
SebastianBergmann\RecursionContext\InvalidArgumentException
assertNan(mixed $actual, string $message = ''): void
Asserts that a variable is nan.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotContains(mixed $needle, iterable $haystack, string $message = ''): void
Asserts that a haystack does not contain a needle.
iterable
$haystack string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertNotContainsEquals(mixed $needle, iterable $haystack, string $message = ''): void
iterable
$haystack string
$message optional void
assertNotContainsOnly(string $type, iterable $haystack, ?bool $isNativeType = null, string $message = ''): void
Asserts that a haystack does not contain only values of a given type.
string
$type iterable
$haystack ?bool
$isNativeType optional string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotCount(int $expectedCount, Countable|iterable $haystack, string $message = ''): void
Asserts the number of elements of an array, Countable or Traversable.
int
$expectedCount Countable|iterable
$haystack string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertNotEmpty(mixed $actual, string $message = ''): void
Asserts that a variable is not empty.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotEquals(mixed $expected, mixed $actual, string $message = ''): void
Asserts that two variables are not equal.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotEqualsCanonicalizing(mixed $expected, mixed $actual, string $message = ''): void
Asserts that two variables are not equal (canonicalizing).
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotEqualsIgnoringCase(mixed $expected, mixed $actual, string $message = ''): void
Asserts that two variables are not equal (ignoring case).
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotEqualsWithDelta(mixed $expected, mixed $actual, float $delta, string $message = ''): void
Asserts that two variables are not equal (with delta).
float
$delta string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotFalse(mixed $condition, string $message = ''): void
Asserts that a condition is not false.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotInstanceOf(string $expected, mixed $actual, string $message = ''): void
Asserts that a variable is not of a given type.
string
$expected string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertNotIsReadable(string $filename, string $message = ''): void
Asserts that a file/dir exists and is not readable.
string
$filename string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotIsWritable(string $filename, string $message = ''): void
Asserts that a file/dir exists and is not writable.
string
$filename string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotNull(mixed $actual, string $message = ''): void
Asserts that a variable is not null.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotRegExp(string $pattern, string $string, string $message = ''): void
Asserts that a string does not match a given regular expression.
string
$pattern string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotSame(mixed $expected, mixed $actual, string $message = ''): void
Asserts that two variables do not have the same type and value. Used on objects, it asserts that two variables do not reference the same object.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotSameSize(Countable|iterable $expected, Countable|iterable $actual, string $message = ''): void
Assert that the size of two arrays (or Countable
or Traversable
objects) is not the same.
Countable|iterable
$expected Countable|iterable
$actual string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertNotTrue(mixed $condition, string $message = ''): void
Asserts that a condition is not true.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertNotWithinRange(float $expected, float $result, float $margin, string $message = ''): void
Compatibility function to test if a value is not between an acceptable range.
float
$expected float
$result float
$margin the rage of acceptation
string
$message optional the text to display if the assertion is not correct
void
assertNull(mixed $actual, string $message = ''): void
Asserts that a variable is null.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertObjectEquals(object $expected, object $actual, string $method = 'equals', string $message = ''): void
object
$expected object
$actual string
$method optional string
$message optional void
ExpectationFailedException
assertObjectHasAttribute(string $attributeName, object $object, string $message = ''): void
Asserts that an object has a specified attribute.
string
$attributeName object
$object string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertObjectNotHasAttribute(string $attributeName, object $object, string $message = ''): void
Asserts that an object does not have a specified attribute.
string
$attributeName object
$object string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertPathEquals(string $expected, string $result, string $message = ''): void
Compatibility function to test paths.
string
$expected string
$result string
$message optional the text to display if the assertion is not correct
void
assertPostConditions(): void
Performs assertions shared by all tests of a test case.
This method is called between test and tearDown().
void
assertPreConditions(): void
Performs assertions shared by all tests of a test case.
This method is called between setUp() and test.
void
assertRegExp(string $pattern, string $string, string $message = ''): void
Asserts that a string matches a given regular expression.
string
$pattern string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertRegExpSql(string $pattern, string $actual, bool $optional = false): void
Assertion for comparing a regex pattern against a query having its identifiers quoted. It accepts queries quoted with the characters <
and >
. If the third parameter is set to true, it will alter the pattern to both accept quoted and unquoted queries
string
$pattern The expected sql pattern
string
$actual The sql to compare
bool
$optional optional Whether quote characters (marked with <>) are optional
void
assertSame(mixed $expected, mixed $actual, string $message = ''): void
Asserts that two variables have the same type and value. Used on objects, it asserts that two variables reference the same object.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertSameSize(Countable|iterable $expected, Countable|iterable $actual, string $message = ''): void
Assert that the size of two arrays (or Countable
or Traversable
objects) is the same.
Countable|iterable
$expected Countable|iterable
$actual string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertStringContainsString(string $needle, string $haystack, string $message = ''): void
string
$needle string
$haystack string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringContainsStringIgnoringCase(string $needle, string $haystack, string $message = ''): void
string
$needle string
$haystack string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringEndsNotWith(string $suffix, string $string, string $message = ''): void
Asserts that a string ends not with a given suffix.
string
$suffix string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringEndsWith(string $suffix, string $string, string $message = ''): void
Asserts that a string ends with a given suffix.
string
$suffix string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringEqualsFile(string $expectedFile, string $actualString, string $message = ''): void
Asserts that the contents of a string is equal to the contents of a file.
string
$expectedFile string
$actualString string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = ''): void
Asserts that the contents of a string is equal to the contents of a file (canonicalizing).
string
$expectedFile string
$actualString string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringEqualsFileIgnoringCase(string $expectedFile, string $actualString, string $message = ''): void
Asserts that the contents of a string is equal to the contents of a file (ignoring case).
string
$expectedFile string
$actualString string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringMatchesFormat(string $format, string $string, string $message = ''): void
Asserts that a string matches a given format string.
string
$format string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringMatchesFormatFile(string $formatFile, string $string, string $message = ''): void
Asserts that a string matches a given format file.
string
$formatFile string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringNotContainsString(string $needle, string $haystack, string $message = ''): void
string
$needle string
$haystack string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringNotContainsStringIgnoringCase(string $needle, string $haystack, string $message = ''): void
string
$needle string
$haystack string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringNotEqualsFile(string $expectedFile, string $actualString, string $message = ''): void
Asserts that the contents of a string is not equal to the contents of a file.
string
$expectedFile string
$actualString string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringNotEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = ''): void
Asserts that the contents of a string is not equal to the contents of a file (canonicalizing).
string
$expectedFile string
$actualString string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringNotEqualsFileIgnoringCase(string $expectedFile, string $actualString, string $message = ''): void
Asserts that the contents of a string is not equal to the contents of a file (ignoring case).
string
$expectedFile string
$actualString string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringNotMatchesFormat(string $format, string $string, string $message = ''): void
Asserts that a string does not match a given format string.
string
$format string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringNotMatchesFormatFile(string $formatFile, string $string, string $message = ''): void
Asserts that a string does not match a given format string.
string
$formatFile string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringStartsNotWith(string $prefix, string $string, string $message = ''): void
Asserts that a string starts not with a given prefix.
string
$prefix string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertStringStartsWith(string $prefix, string $string, string $message = ''): void
Asserts that a string starts with a given prefix.
string
$prefix string
$string string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertTextContains(string $needle, string $haystack, string $message = '', bool $ignoreCase = false): void
Assert that a string contains another string, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
string
$needle The string to search for.
string
$haystack The string to search through.
string
$message optional The message to display on failure.
bool
$ignoreCase optional Whether the search should be case-sensitive.
void
assertTextEndsNotWith(string $suffix, string $string, string $message = ''): void
Asserts that a string ends not with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
string
$suffix The suffix to not find.
string
$string The string to search.
string
$message optional The message to use for failure.
void
assertTextEndsWith(string $suffix, string $string, string $message = ''): void
Asserts that a string ends with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
string
$suffix The suffix to find.
string
$string The string to search.
string
$message optional The message to use for failure.
void
assertTextEquals(string $expected, string $result, string $message = ''): void
Assert text equality, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
string
$expected The expected value.
string
$result The actual value.
string
$message optional The message to use for failure.
void
assertTextNotContains(string $needle, string $haystack, string $message = '', bool $ignoreCase = false): void
Assert that a text doesn't contain another text, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
string
$needle The string to search for.
string
$haystack The string to search through.
string
$message optional The message to display on failure.
bool
$ignoreCase optional Whether the search should be case-sensitive.
void
assertTextNotEquals(string $expected, string $result, string $message = ''): void
Assert text equality, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
string
$expected The expected value.
string
$result The actual value.
string
$message optional The message to use for failure.
void
assertTextStartsNotWith(string $prefix, string $string, string $message = ''): void
Asserts that a string starts not with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
string
$prefix The prefix to not find.
string
$string The string to search.
string
$message optional The message to use for failure.
void
assertTextStartsWith(string $prefix, string $string, string $message = ''): void
Asserts that a string starts with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
string
$prefix The prefix to check for.
string
$string The string to search in.
string
$message optional The message to use for failure.
void
assertThat(mixed $value, Constraint $constraint, string $message = ''): void
Evaluates a PHPUnit\Framework\Constraint matcher object.
Constraint
$constraint string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertTrue(mixed $condition, string $message = ''): void
Asserts that a condition is true.
string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertWithinRange(float $expected, float $result, float $margin, string $message = ''): void
Compatibility function to test if a value is between an acceptable range.
float
$expected float
$result float
$margin the rage of acceptation
string
$message optional the text to display if the assertion is not correct
void
assertXmlFileEqualsXmlFile(string $expectedFile, string $actualFile, string $message = ''): void
Asserts that two XML files are equal.
string
$expectedFile string
$actualFile string
$message optional void
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
ExpectationFailedException
assertXmlFileNotEqualsXmlFile(string $expectedFile, string $actualFile, string $message = ''): void
Asserts that two XML files are not equal.
string
$expectedFile string
$actualFile string
$message optional void
PHPUnit\Util\Exception
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertXmlStringEqualsXmlFile(string $expectedFile, DOMDocument|string $actualXml, string $message = ''): void
Asserts that two XML documents are equal.
string
$expectedFile DOMDocument|string
$actualXml string
$message optional void
PHPUnit\Util\Xml\Exception
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertXmlStringEqualsXmlString(DOMDocument|string $expectedXml, DOMDocument|string $actualXml, string $message = ''): void
Asserts that two XML documents are equal.
DOMDocument|string
$expectedXml DOMDocument|string
$actualXml string
$message optional void
PHPUnit\Util\Xml\Exception
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertXmlStringNotEqualsXmlFile(string $expectedFile, DOMDocument|string $actualXml, string $message = ''): void
Asserts that two XML documents are not equal.
string
$expectedFile DOMDocument|string
$actualXml string
$message optional void
PHPUnit\Util\Xml\Exception
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
assertXmlStringNotEqualsXmlString(DOMDocument|string $expectedXml, DOMDocument|string $actualXml, string $message = ''): void
Asserts that two XML documents are not equal.
DOMDocument|string
$expectedXml DOMDocument|string
$actualXml string
$message optional void
PHPUnit\Util\Xml\Exception
SebastianBergmann\RecursionContext\InvalidArgumentException
ExpectationFailedException
at(int $index): InvokedAtIndexMatcher
Returns a matcher that matches when the method is executed at the given index.
int
$index InvokedAtIndexMatcher
atLeast(int $requiredInvocations): InvokedAtLeastCountMatcher
Returns a matcher that matches when the method is executed at least N times.
int
$requiredInvocations InvokedAtLeastCountMatcher
atLeastOnce(): InvokedAtLeastOnceMatcher
Returns a matcher that matches when the method is executed at least once.
InvokedAtLeastOnceMatcher
atMost(int $allowedInvocations): InvokedAtMostCountMatcher
Returns a matcher that matches when the method is executed at most N times.
int
$allowedInvocations InvokedAtMostCountMatcher
callback(callable $callback): Callback
callable
$callback Callback
classHasAttribute(string $attributeName): ClassHasAttribute
string
$attributeName ClassHasAttribute
classHasStaticAttribute(string $attributeName): ClassHasStaticAttribute
string
$attributeName ClassHasStaticAttribute
clearPlugins(): void
Clear all plugins from the global plugin collection.
Useful in test case teardown methods.
void
containsEqual(mixed $value): TraversableContainsEqual
TraversableContainsEqual
containsIdentical(mixed $value): TraversableContainsIdentical
TraversableContainsIdentical
containsOnly(string $type): TraversableContainsOnly
string
$type TraversableContainsOnly
containsOnlyInstancesOf(string $className): TraversableContainsOnly
string
$className TraversableContainsOnly
count(): int
int
countOf(int $count): Count
int
$count Count
createConfiguredMock(string $originalClassName, array $configuration): MockObject
Returns a configured mock object for the specified class.
string
$originalClassName array
$configuration MockObject
createMock(string $originalClassName): MockObject
Returns a mock object for the specified class.
string
$originalClassName MockObject
createPartialMock(string $originalClassName, string[] $methods): MockObject
Returns a partial mock object for the specified class.
string
$originalClassName string[]
$methods MockObject
createResult(): TestResult
Creates a default TestResult object.
TestResult
createStub(string $originalClassName): Stub
Makes configurable stub for the specified class.
string
$originalClassName Stub
createTestProxy(string $originalClassName, array $constructorArguments = []): MockObject
Returns a test proxy for the specified class.
string
$originalClassName array
$constructorArguments optional MockObject
dataName(): int|string
int|string
deprecated(callable $callable): void
Helper method for check deprecation methods
callable
$callable callable function that will receive asserts
void
directoryExists(): DirectoryExists
DirectoryExists
doesNotPerformAssertions(): bool
bool
doubledTypes(): string[]
string[]
equalTo(mixed $value): IsEqual
IsEqual
equalToCanonicalizing(mixed $value): IsEqualCanonicalizing
IsEqualCanonicalizing
equalToIgnoringCase(mixed $value): IsEqualIgnoringCase
IsEqualIgnoringCase
equalToWithDelta(mixed $value, float $delta): IsEqualWithDelta
float
$delta IsEqualWithDelta
exactly(int $count): InvokedCountMatcher
Returns a matcher that matches when the method is executed exactly $count times.
int
$count InvokedCountMatcher
expectDeprecation(): void
void
expectDeprecationMessage(string $message): void
string
$message void
expectDeprecationMessageMatches(string $regularExpression): void
string
$regularExpression void
expectError(): void
void
expectErrorMessage(string $message): void
string
$message void
expectErrorMessageMatches(string $regularExpression): void
string
$regularExpression void
expectException(string $exception): void
string
$exception void
expectExceptionCode(int|string $code): void
int|string
$code void
expectExceptionMessage(string $message): void
string
$message void
expectExceptionMessageMatches(string $regularExpression): void
string
$regularExpression void
expectExceptionObject(Exception $exception): void
Sets up an expectation for an exception to be raised by the code under test. Information for expected exception class, expected exception message, and expected exception code are retrieved from a given Exception object.
Exception
$exception void
expectNotToPerformAssertions(): void
void
expectNotice(): void
void
expectNoticeMessage(string $message): void
string
$message void
expectNoticeMessageMatches(string $regularExpression): void
string
$regularExpression void
expectOutputRegex(string $expectedRegex): void
string
$expectedRegex void
expectOutputString(string $expectedString): void
string
$expectedString void
expectWarning(): void
void
expectWarningMessage(string $message): void
string
$message void
expectWarningMessageMatches(string $regularExpression): void
string
$regularExpression void
fail(string $message = ''): void
Fails a test with the given message.
string
$message optional void
AssertionFailedError
fetchTable(string|null $alias = null, array<string, mixed> $options = []): Cake\ORM\Table
Convenience method to get a table instance.
string|null
$alias optional The alias name you want to get. Should be in CamelCase format. If null
then the value of $defaultTable property is used.
array<string, mixed>
$options optional The options you want to build the table with. If a table has already been loaded the registry options will be ignored.
Cake\ORM\Table
Cake\Core\Exception\CakeException
fileExists(): FileExists
FileExists
getActualOutput(): string
string
getActualOutputForAssertion(): string
string
getCount(): int
Return the current assertion count.
int
getDataSetAsString(bool $includeData = true): string
bool
$includeData optional string
getExpectedException(): ?string
?string
getExpectedExceptionCode(): null|int|string
null|int|string
getExpectedExceptionMessage(): ?string
?string
getExpectedExceptionMessageRegExp(): ?string
?string
getFixtureStrategy(): Cake\TestSuite\Fixture\FixtureStrategyInterface
Returns fixture strategy used by these tests.
Cake\TestSuite\Fixture\FixtureStrategyInterface
getFixtures(): array<string>
Get the fixtures this test should use.
array<string>
getGroups(): array
array
getMockBuilder(string $className): MockBuilder
Returns a builder object to create mock objects using a fluent interface.
string
$className MockBuilder
getMockClass(string $originalClassName, null|array $methods = [], array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = false, bool $callOriginalClone = true, bool $callAutoload = true, bool $cloneArguments = false): string
Mocks the specified class and returns the name of the mocked class.
string
$originalClassName null|array
$methods optional $methods
array
$arguments optional string
$mockClassName optional bool
$callOriginalConstructor optional bool
$callOriginalClone optional bool
$callAutoload optional bool
$cloneArguments optional string
getMockForAbstractClass(string $originalClassName, array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, array $mockedMethods = [], bool $cloneArguments = false): MockObject
Returns a mock object for the specified abstract class with all abstract methods of the class mocked. Concrete methods are not mocked by default. To mock concrete methods, use the 7th parameter ($mockedMethods).
string
$originalClassName array
$arguments optional string
$mockClassName optional bool
$callOriginalConstructor optional bool
$callOriginalClone optional bool
$callAutoload optional array
$mockedMethods optional bool
$cloneArguments optional MockObject
getMockForModel(string $alias, array<string> $methods = [], array<string, mixed> $options = []): Cake\ORM\TablePHPUnit\Framework\MockObject\MockObject
Mock a model, maintain fixtures and table association
string
$alias The model to get a mock for.
array<string>
$methods optional The list of methods to mock
array<string, mixed>
$options optional The config data for the mock's constructor.
Cake\ORM\TablePHPUnit\Framework\MockObject\MockObject
Cake\ORM\Exception\MissingTableClassException
getMockForTrait(string $traitName, array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, array $mockedMethods = [], bool $cloneArguments = false): MockObject
Returns a mock object for the specified trait with all abstract methods of the trait mocked. Concrete methods to mock can be specified with the $mockedMethods
parameter.
string
$traitName array
$arguments optional string
$mockClassName optional bool
$callOriginalConstructor optional bool
$callOriginalClone optional bool
$callAutoload optional array
$mockedMethods optional bool
$cloneArguments optional MockObject
getMockFromWsdl(string $wsdlFile, string $originalClassName = '', string $mockClassName = '', array $methods = [], bool $callOriginalConstructor = true, array $options = []): MockObject
Returns a mock object based on the given WSDL file.
string
$wsdlFile string
$originalClassName optional string
$mockClassName optional array
$methods optional bool
$callOriginalConstructor optional array
$options optional MockObject
getName(bool $withDataSet = true): string
bool
$withDataSet optional string
SebastianBergmann\RecursionContext\InvalidArgumentException
getNumAssertions(): int
Returns the number of assertions performed by this test.
int
getObjectForTrait(string $traitName, array $arguments = [], string $traitClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true): object
Returns an object for the specified trait.
string
$traitName array
$arguments optional string
$traitClassName optional bool
$callOriginalConstructor optional bool
$callOriginalClone optional bool
$callAutoload optional object
getProvidedData(): array
Gets the data set of a TestCase.
array
getResult()
getSize(): int
Returns the size of the test.
int
SebastianBergmann\RecursionContext\InvalidArgumentException
getStatus(): int
int
getStatusMessage(): string
string
getTableLocator(): Cake\ORM\Locator\LocatorInterface
Gets the table locator.
Cake\ORM\Locator\LocatorInterface
getTestResultObject(): ?TestResult
?TestResult
greaterThan(mixed $value): GreaterThan
GreaterThan
greaterThanOrEqual(mixed $value): LogicalOr
LogicalOr
hasExpectationOnOutput(): bool
bool
hasFailed(): bool
bool
hasOutput(): bool
bool
hasSize(): bool
bool
SebastianBergmann\RecursionContext\InvalidArgumentException
identicalTo(mixed $value): IsIdentical
IsIdentical
iniSet(string $varName, string $newValue): void
This method is a wrapper for the ini_set() function that automatically resets the modified php.ini setting to its original value after the test is run.
string
$varName string
$newValue void
Exception
isEmpty(): IsEmpty
IsEmpty
isFalse(): IsFalse
IsFalse
isFinite(): IsFinite
IsFinite
isInIsolation(): bool
bool
isInfinite(): IsInfinite
IsInfinite
isInstanceOf(string $className): IsInstanceOf
string
$className IsInstanceOf
isJson(): IsJson
IsJson
isLarge(): bool
bool
SebastianBergmann\RecursionContext\InvalidArgumentException
isMedium(): bool
bool
SebastianBergmann\RecursionContext\InvalidArgumentException
isNan(): IsNan
IsNan
isNull(): IsNull
IsNull
isReadable(): IsReadable
IsReadable
isSmall(): bool
bool
SebastianBergmann\RecursionContext\InvalidArgumentException
isTrue(): IsTrue
IsTrue
isType(string $type): IsType
string
$type IsType
isWritable(): IsWritable
IsWritable
lessThan(mixed $value): LessThan
LessThan
lessThanOrEqual(mixed $value): LogicalOr
LogicalOr
loadFixtures(): void
Chooses which fixtures to load for a given test
Each parameter is a model name that corresponds to a fixture, i.e. 'Posts', 'Authors', etc. Passing no parameters will cause all fixtures on the test case to load.
void
RuntimeException
loadPlugins(array<string, mixed> $plugins = []): Cake\Http\BaseApplication
Load plugins into a simulated application.
Useful to test how plugins being loaded/not loaded interact with other elements in CakePHP or applications.
array<string, mixed>
$plugins optional List of Plugins to load.
Cake\Http\BaseApplication
loadRoutes(array|null $appArgs = null): void
Load routes for the application.
If no application class can be found an exception will be raised. Routes for plugins will not be loaded. Use loadPlugins()
or use Cake\TestSuite\IntegrationTestCaseTrait
to better simulate all routes and plugins being loaded.
array|null
$appArgs optional Constructor parameters for the application class.
void
logicalAnd(): LogicalAnd
LogicalAnd
Exception
logicalNot(Constraint $constraint): LogicalNot
Constraint
$constraint LogicalNot
logicalOr(): LogicalOr
LogicalOr
logicalXor(): LogicalXor
LogicalXor
markAsRisky(): void
void
markTestIncomplete(string $message = ''): void
Mark the test as incomplete.
string
$message optional void
IncompleteTestError
markTestSkipped(string $message = ''): void
Mark the test as skipped.
string
$message optional void
SkippedTestError
SyntheticSkippedError
matches(string $string): StringMatchesFormatDescription
string
$string StringMatchesFormatDescription
matchesRegularExpression(string $pattern): RegularExpression
string
$pattern RegularExpression
never(): InvokedCountMatcher
Returns a matcher that matches when the method is never executed.
InvokedCountMatcher
objectEquals(object $object, string $method = 'equals'): ObjectEquals
object
$object string
$method optional ObjectEquals
objectHasAttribute(mixed $attributeName): ObjectHasAttribute
ObjectHasAttribute
onConsecutiveCalls(mixed ...$args): ConsecutiveCallsStub
ConsecutiveCallsStub
onNotSuccessfulTest(Throwable $t): void
This method is called when a test method did not execute successfully.
Throwable
$t void
Throwable
once(): InvokedCountMatcher
Returns a matcher that matches when the method is executed exactly once.
InvokedCountMatcher
prophesize(?string $classOrInterface = null): ObjectProphecy
?string
$classOrInterface optional ObjectProphecy
Prophecy\Exception\Doubler\ClassNotFoundException
Prophecy\Exception\Doubler\DoubleException
Prophecy\Exception\Doubler\InterfaceNotFoundException
provides(): list<ExecutionOrderDependency>
Returns the normalized test name as class::method.
list<ExecutionOrderDependency>
recordDoubledType(string $originalClassName): void
string
$originalClassName void
registerComparator(Comparator $comparator): void
Comparator
$comparator void
registerMockObject(MockObject $mockObject): void
MockObject
$mockObject void
removePlugins(array<string> $names = []): void
Remove plugins from the global plugin collection.
Useful in test case teardown methods.
array<string>
$names optional A list of plugins you want to remove.
void
requires(): list<ExecutionOrderDependency>
Returns a list of normalized dependency names, class::method.
This list can differ from the raw dependencies as the resolver has no need for the [!][shallow]clone prefix that is filtered out during normalization.
list<ExecutionOrderDependency>
resetCount(): void
Reset the assertion counter.
void
returnArgument(int $argumentIndex): ReturnArgumentStub
int
$argumentIndex ReturnArgumentStub
returnCallback(mixed $callback): ReturnCallbackStub
ReturnCallbackStub
returnSelf(): ReturnSelfStub
Returns the current object.
This method is useful when mocking a fluent interface.
ReturnSelfStub
returnValue(mixed $value): ReturnStub
ReturnStub
returnValueMap(array $valueMap): ReturnValueMapStub
array
$valueMap ReturnValueMapStub
run(TestResult $result = null): TestResult
Runs the test case and collects the results in a TestResult object. If no TestResult object is passed a new one will be created.
TestResult
$result optional TestResult
SebastianBergmann\CodeCoverage\InvalidArgumentException
SebastianBergmann\CodeCoverage\UnintentionallyCoveredCodeException
SebastianBergmann\RecursionContext\InvalidArgumentException
CodeCoverageException
UtilException
runBare(): void
void
Throwable
runTest()
Override to run the test and assert its state.
SebastianBergmann\ObjectEnumerator\InvalidArgumentException
AssertionFailedError
Exception
ExpectationFailedException
Throwable
setAppNamespace(string $appNamespace = 'TestApp'): string|null
Set the app namespace
string
$appNamespace optional The app namespace, defaults to "TestApp".
string|null
setBackupGlobals(?bool $backupGlobals): void
?bool
$backupGlobals void
setBackupStaticAttributes(?bool $backupStaticAttributes): void
?bool
$backupStaticAttributes void
setBeStrictAboutChangesToGlobalState(?bool $beStrictAboutChangesToGlobalState): void
?bool
$beStrictAboutChangesToGlobalState void
setDependencies(list<ExecutionOrderDependency> $dependencies): void
list<ExecutionOrderDependency>
$dependencies void
setDependencyInput(array $dependencyInput): void
array
$dependencyInput void
setGroups(array $groups): void
array
$groups void
setInIsolation(bool $inIsolation): void
bool
$inIsolation void
setLocale(mixed ...$args): void
This method is a wrapper for the setlocale() function that automatically resets the locale to its original value after the test is run.
void
Exception
setName(string $name): void
string
$name void
setOutputCallback(callable $callback): void
callable
$callback void
setPreserveGlobalState(bool $preserveGlobalState): void
bool
$preserveGlobalState void
setRegisterMockObjectsFromTestArgumentsRecursively(bool $flag): void
bool
$flag void
setResult(mixed $result): void
void
setRunClassInSeparateProcess(bool $runClassInSeparateProcess): void
bool
$runClassInSeparateProcess void
setRunTestInSeparateProcess(bool $runTestInSeparateProcess): void
bool
$runTestInSeparateProcess void
setTableLocator(Cake\ORM\Locator\LocatorInterface $tableLocator): $this
Sets the table locator.
Cake\ORM\Locator\LocatorInterface
$tableLocator LocatorInterface instance.
$this
setTestResultObject(TestResult $result): void
TestResult
$result void
setUp(): void
Setup the test case, backup the static object values so they can be restored. Specifically backs up the contents of Configure and paths in App if they have not already been backed up.
void
setUpBeforeClass(): void
This method is called before the first test of this test class is run.
void
setupFixtures(): void
Initialized and loads any use fixtures.
void
skipIf(bool $shouldSkip, string $message = ''): bool
Overrides SimpleTestCase::skipIf to provide a boolean return value
bool
$shouldSkip Whether the test should be skipped.
string
$message optional The message to display.
bool
skipUnless(bool $condition, string $message = ''): bool
Compatibility function for skipping.
bool
$condition Condition to trigger skipping
string
$message optional Message for skip
bool
sortId(): string
string
stringContains(string $string, bool $case = true): StringContains
string
$string bool
$case optional StringContains
stringEndsWith(string $suffix): StringEndsWith
string
$suffix StringEndsWith
stringStartsWith(mixed $prefix): StringStartsWith
StringStartsWith
tearDown(): void
teardown any static object changes and restore them.
void
tearDownAfterClass(): void
This method is called after the last test of this test class is run.
void
teardownFixtures(): void
Unloads any use fixtures.
void
throwException(Throwable $exception): ExceptionStub
Throwable
$exception ExceptionStub
toString(): string
Returns a string representation of the test case.
string
SebastianBergmann\RecursionContext\InvalidArgumentException
Exception
usesDataProvider(): bool
bool
withErrorReporting(int $errorLevel, callable $callable): void
Helper method for tests that needs to use error_reporting()
int
$errorLevel value of error_reporting() that needs to use
callable
$callable callable function that will receive asserts
void
Configure values to restore at end of test.
array
Table locator instance
Cake\ORM\Locator\LocatorInterface|null
By default, all fixtures attached to this class will be truncated and reloaded after each test. Set this to false to handle manually
bool
?bool
string[]
string[]
bool
array<string, array<int, string>>
array<string, array<int, string>>
This object's default table alias.
string|null
Control table create/drops on each test method.
If true, tables will still be dropped at the end of each test runner execution.
bool
The class responsible for managing the creation, loading and removing of fixtures
Cake\TestSuite\Fixture\FixtureManager|null
Cake\TestSuite\Fixture\FixtureStrategyInterface|null
Fixtures used by this test case.
array<string>
bool
list<ExecutionOrderDependency>
bool
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/class-Cake.TestSuite.TestCase.html