Class TestCase
Cake TestCase class
Properties summary
- $_configure protected
array
Configure values to restore at end of test.
- $_tableLocator protected
\Cake\ORM\Locator\LocatorInterface
Table locator instance
- $autoFixtures public
bool
By default, all fixtures attached to this class will be truncated and reloaded after each test.
- $backupGlobals protected
bool
Enable or disable the backup and restoration of the $GLOBALS array.
- $backupGlobalsBlacklist protected
array
- $backupStaticAttributes protected
bool
Enable or disable the backup and restoration of static attributes.
- $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
- 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.
- assertAttributeGreaterThanOrEqual() public static
Asserts that an attribute is greater than or equal to 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.
- 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.
- 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.
- assertContainsOnlyInstancesOf() public static
Asserts that a haystack contains only instances of a given classname
- assertEventFired() public
Asserts that a global event was fired. You must track events in your event manager for this assertion to work
- assertFileEquals() public static
Asserts that the contents of one file is equal to the contents of another file.
- assertFileNotEquals() public static
Asserts that the contents of one file is not equal to the contents of another file.
- assertGreaterThanOrEqual() public static
Asserts that a value is greater than or equal to another value.
- 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.
- assertLessThanOrEqual() public static
Asserts that a value is smaller than or equal to another value.
- 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.
- assertNotSameSize() public static
Assert that the size of two arrays (or
Countable
orTraversable
objects) is not the same. - assertNotWithinRange() protected static
Compatibility function to test if a value is not between an acceptable range.
- assertObjectNotHasAttribute() public static
Asserts that an object does not have a specified attribute.
- assertSameSize() public static
Assert that the size of two arrays (or
Countable
orTraversable
objects) is the same. - assertStringEqualsFile() public static
Asserts that the contents of a string is equal to the contents of a 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.
- assertTextContains() public
Assert that a string contains another string, ignoring differences in newlines.
- assertTextEndsNotWith() public
Asserts that a string ends not with a given prefix, ignoring differences in newlines.
- assertTextEndsWith() public
Asserts that a string ends with a given prefix, ignoring differences in newlines.
- assertTextNotContains() public
Assert that a text doesn't contain another text, ignoring differences in newlines.
- assertTextStartsNotWith() public
Asserts that a string starts not with a given prefix, ignoring differences in newlines.
- assertTextStartsWith() public
Asserts that a string starts with a given prefix, ignoring differences in newlines.
- assertWithinRange() protected static
Compatibility function to test if a value is between an acceptable range.
- 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.
- checkRequirements() protected
- dataDescription() public
- dataName() public
- doesNotPerformAssertions() public
- exactly() public static
Returns a matcher that matches when the method is executed exactly $count times.
- expectException() public
- expectExceptionCode() public
- expectExceptionMessage() public
- expectExceptionObject() public
Sets up an expectation for an exception to be raised by the code under test.
- expectOutputRegex() public
- expectOutputString() public
- getActualOutput() public
- getExpectedException() public
- getExpectedExceptionCode() public
- getGroups() public
- 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.
- 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. - getResult() public
- getTestResultObject() public
- handleDependencies() protected
- hasExpectationOnOutput() public
- hasOutput() public
- hasSize() public
- 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.
- isInIsolation() public
- isLarge() public
- isMedium() public
- isSmall() public
- markAsRisky() public
- onNotSuccessfulTest() protected
This method is called when a test method did not execute successfully.
- prophesize() protected
- registerComparator() public
- registerMockObject() public
- 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.
- setOutputCallback() public
- setPreserveGlobalState() public
- setResult() public
- setTestResultObject() public
- setUpBeforeClass() public static
This method is called before the first test of this test class is run.
- setUseErrorHandler() public
- setUseErrorHandlerFromAnnotation() protected
- tearDownAfterClass() public static
This method is called after the last test of this test class is run.
- usesDataProvider() public
Method Detail
__construct() public
__construct(mixed $name, array $data, mixed $dataName)
Constructs a test case with the given name.
Parameters
-
string
$name optional -
array
$data optional -
string
$dataName optional
_assertAttributes() protected
_assertAttributes(mixed $assertions, mixed $string, mixed $fullDebug, mixed $regex)
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
_getTableClassName() protected
_getTableClassName(mixed $alias, array $options)
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
_normalizePath() protected
_normalizePath(mixed $path)
Normalize a path for comparison.
Parameters
-
string
$path Path separated by "/" slash.
Returns
string
Normalized path separated by DIRECTORY_SEPARATOR.
addFixture() protected
addFixture(mixed $fixture)
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(mixed $count)
Adds a value to the assertion counter.
Parameters
-
int
$count
any() public static
any()
Returns a matcher that matches when the method is executed zero or more times.
Returns
\PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount
anything() public static
anything()
Returns
\PHPUnit\Framework\Constraint\IsAnything
arrayHasKey() public static
arrayHasKey(mixed $key)
Parameters
-
mixed
$key
Returns
\PHPUnit\Framework\Constraint\ArrayHasKey
assertArrayHasKey() public static
assertArrayHasKey(mixed $key, mixed $array, mixed $message)
Asserts that an array has a specified key.
Parameters
-
mixed
$key -
array|\ArrayAccess
$array -
string
$message optional
assertArrayNotHasKey() public static
assertArrayNotHasKey(mixed $key, mixed $array, mixed $message)
Asserts that an array does not have a specified key.
Parameters
-
mixed
$key -
array|\ArrayAccess
$array -
string
$message optional
assertArraySubset() public static
assertArraySubset(mixed $subset, mixed $array, mixed $strict, mixed $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, mixed $haystackAttributeName, mixed $haystackClassOrObject, mixed $message, mixed $ignoreCase, mixed $checkForObjectIdentity, mixed $checkForNonObjectIdentity)
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(mixed $type, mixed $haystackAttributeName, mixed $haystackClassOrObject, mixed $isNativeType, mixed $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(mixed $expectedCount, mixed $haystackAttributeName, mixed $haystackClassOrObject, mixed $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(mixed $haystackAttributeName, mixed $haystackClassOrObject, mixed $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, mixed $actualAttributeName, mixed $actualClassOrObject, mixed $message, mixed $delta, mixed $maxDepth, mixed $canonicalize, mixed $ignoreCase)
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, mixed $actualAttributeName, mixed $actualClassOrObject, mixed $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, mixed $actualAttributeName, mixed $actualClassOrObject, mixed $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(mixed $expected, mixed $attributeName, mixed $classOrObject, mixed $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(mixed $expected, mixed $attributeName, mixed $classOrObject, mixed $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, mixed $actualAttributeName, mixed $actualClassOrObject, mixed $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, mixed $actualAttributeName, mixed $actualClassOrObject, mixed $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, mixed $haystackAttributeName, mixed $haystackClassOrObject, mixed $message, mixed $ignoreCase, mixed $checkForObjectIdentity, mixed $checkForNonObjectIdentity)
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(mixed $type, mixed $haystackAttributeName, mixed $haystackClassOrObject, mixed $isNativeType, mixed $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(mixed $expectedCount, mixed $haystackAttributeName, mixed $haystackClassOrObject, mixed $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(mixed $haystackAttributeName, mixed $haystackClassOrObject, mixed $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, mixed $actualAttributeName, mixed $actualClassOrObject, mixed $message, mixed $delta, mixed $maxDepth, mixed $canonicalize, mixed $ignoreCase)
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(mixed $expected, mixed $attributeName, mixed $classOrObject, mixed $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(mixed $expected, mixed $attributeName, mixed $classOrObject, mixed $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, mixed $actualAttributeName, mixed $actualClassOrObject, mixed $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, mixed $actualAttributeName, mixed $actualClassOrObject, mixed $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(mixed $attributeName, mixed $className, mixed $message)
Asserts that a class has a specified attribute.
Parameters
-
string
$attributeName -
string
$className -
string
$message optional
assertClassHasStaticAttribute() public static
assertClassHasStaticAttribute(mixed $attributeName, mixed $className, mixed $message)
Asserts that a class has a specified static attribute.
Parameters
-
string
$attributeName -
string
$className -
string
$message optional
assertClassNotHasAttribute() public static
assertClassNotHasAttribute(mixed $attributeName, mixed $className, mixed $message)
Asserts that a class does not have a specified attribute.
Parameters
-
string
$attributeName -
string
$className -
string
$message optional
assertClassNotHasStaticAttribute() public static
assertClassNotHasStaticAttribute(mixed $attributeName, mixed $className, mixed $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, mixed $message, mixed $ignoreCase, mixed $checkForObjectIdentity, mixed $checkForNonObjectIdentity)
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(mixed $type, mixed $haystack, mixed $isNativeType, mixed $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(mixed $classname, mixed $haystack, mixed $message)
Asserts that a haystack contains only instances of a given classname
Parameters
-
string
$classname -
array|\Traversable
$haystack -
string
$message optional
assertCount() public static
assertCount(mixed $expectedCount, mixed $haystack, mixed $message)
Asserts the number of elements of an array, Countable or Traversable.
Parameters
-
int
$expectedCount -
mixed
$haystack -
string
$message optional
assertDirectoryExists() public static
assertDirectoryExists(mixed $directory, mixed $message)
Asserts that a directory exists.
Parameters
-
string
$directory -
string
$message optional
assertDirectoryIsReadable() public static
assertDirectoryIsReadable(mixed $directory, mixed $message)
Asserts that a directory exists and is readable.
Parameters
-
string
$directory -
string
$message optional
assertDirectoryIsWritable() public static
assertDirectoryIsWritable(mixed $directory, mixed $message)
Asserts that a directory exists and is writable.
Parameters
-
string
$directory -
string
$message optional
assertDirectoryNotExists() public static
assertDirectoryNotExists(mixed $directory, mixed $message)
Asserts that a directory does not exist.
Parameters
-
string
$directory -
string
$message optional
assertDirectoryNotIsReadable() public static
assertDirectoryNotIsReadable(mixed $directory, mixed $message)
Asserts that a directory exists and is not readable.
Parameters
-
string
$directory -
string
$message optional
assertDirectoryNotIsWritable() public static
assertDirectoryNotIsWritable(mixed $directory, mixed $message)
Asserts that a directory exists and is not writable.
Parameters
-
string
$directory -
string
$message optional
assertEmpty() public static
assertEmpty(mixed $actual, mixed $message)
Asserts that a variable is empty.
Parameters
-
mixed
$actual -
string
$message optional
Throws
PHPUnit\Framework\AssertionFailedError
assertEqualXMLStructure() public static
assertEqualXMLStructure(\DOMElement $expectedElement, \DOMElement $actualElement, mixed $checkAttributes, mixed $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, mixed $message, mixed $delta, mixed $maxDepth, mixed $canonicalize, mixed $ignoreCase)
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(mixed $name, mixed $eventManager, mixed $message)
Asserts that a global event was fired. You must track events in your event manager for this assertion to work
Parameters
-
string
$name Event name
-
\Cake\Event\EventManager|null
$eventManager optional Event manager to check, defaults to global event manager
-
string
$message optional Assertion failure message
assertEventFiredWith() public
assertEventFiredWith(mixed $name, mixed $dataKey, mixed $dataValue, mixed $eventManager, mixed $message)
Asserts an event was fired with data
If a third argument is passed, that value is used to compare with the value in $dataKey
Parameters
-
string
$name Event name
-
string
$dataKey Data key
-
string
$dataValue Data value
-
\Cake\Event\EventManager|null
$eventManager optional Event manager to check, defaults to global event manager
-
string
$message optional Assertion failure message
assertFalse() public static
assertFalse(mixed $condition, mixed $message)
Asserts that a condition is false.
Parameters
-
bool
$condition -
string
$message optional
Throws
PHPUnit\Framework\AssertionFailedError
assertFileEquals() public static
assertFileEquals(mixed $expected, mixed $actual, mixed $message, mixed $canonicalize, mixed $ignoreCase)
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(mixed $filename, mixed $message)
Asserts that a file exists.
Parameters
-
string
$filename -
string
$message optional
assertFileIsReadable() public static
assertFileIsReadable(mixed $file, mixed $message)
Asserts that a file exists and is readable.
Parameters
-
string
$file -
string
$message optional
assertFileIsWritable() public static
assertFileIsWritable(mixed $file, mixed $message)
Asserts that a file exists and is writable.
Parameters
-
string
$file -
string
$message optional
assertFileNotEquals() public static
assertFileNotEquals(mixed $expected, mixed $actual, mixed $message, mixed $canonicalize, mixed $ignoreCase)
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(mixed $filename, mixed $message)
Asserts that a file does not exist.
Parameters
-
string
$filename -
string
$message optional
assertFileNotIsReadable() public static
assertFileNotIsReadable(mixed $file, mixed $message)
Asserts that a file exists and is not readable.
Parameters
-
string
$file -
string
$message optional
assertFileNotIsWritable() public static
assertFileNotIsWritable(mixed $file, mixed $message)
Asserts that a file exists and is not writable.
Parameters
-
string
$file -
string
$message optional
assertFinite() public static
assertFinite(mixed $actual, mixed $message)
Asserts that a variable is finite.
Parameters
-
mixed
$actual -
string
$message optional
assertGreaterThan() public static
assertGreaterThan(mixed $expected, mixed $actual, mixed $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, mixed $message)
Asserts that a value is greater than or equal to another value.
Parameters
-
mixed
$expected -
mixed
$actual -
string
$message optional
assertHtml() public
assertHtml(mixed $expected, mixed $string, mixed $fullDebug)
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, mixed $message)
Asserts that a variable is infinite.
Parameters
-
mixed
$actual -
string
$message optional
assertInstanceOf() public static
assertInstanceOf(mixed $expected, mixed $actual, mixed $message)
Asserts that a variable is of a given type.
Parameters
-
string
$expected -
mixed
$actual -
string
$message optional
assertInternalType() public static
assertInternalType(mixed $expected, mixed $actual, mixed $message)
Asserts that a variable is of a given type.
Parameters
-
string
$expected -
mixed
$actual -
string
$message optional
assertIsReadable() public static
assertIsReadable(mixed $filename, mixed $message)
Asserts that a file/dir is readable.
Parameters
-
string
$filename -
string
$message optional
assertIsWritable() public static
assertIsWritable(mixed $filename, mixed $message)
Asserts that a file/dir exists and is writable.
Parameters
-
string
$filename -
string
$message optional
assertJson() public static
assertJson(mixed $actualJson, mixed $message)
Asserts that a string is a valid JSON string.
Parameters
-
string
$actualJson -
string
$message optional
assertJsonFileEqualsJsonFile() public static
assertJsonFileEqualsJsonFile(mixed $expectedFile, mixed $actualFile, mixed $message)
Asserts that two JSON files are equal.
Parameters
-
string
$expectedFile -
string
$actualFile -
string
$message optional
assertJsonFileNotEqualsJsonFile() public static
assertJsonFileNotEqualsJsonFile(mixed $expectedFile, mixed $actualFile, mixed $message)
Asserts that two JSON files are not equal.
Parameters
-
string
$expectedFile -
string
$actualFile -
string
$message optional
assertJsonStringEqualsJsonFile() public static
assertJsonStringEqualsJsonFile(mixed $expectedFile, mixed $actualJson, mixed $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(mixed $expectedJson, mixed $actualJson, mixed $message)
Asserts that two given JSON encoded objects or arrays are equal.
Parameters
-
string
$expectedJson -
string
$actualJson -
string
$message optional
assertJsonStringNotEqualsJsonFile() public static
assertJsonStringNotEqualsJsonFile(mixed $expectedFile, mixed $actualJson, mixed $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(mixed $expectedJson, mixed $actualJson, mixed $message)
Asserts that two given JSON encoded objects or arrays are not equal.
Parameters
-
string
$expectedJson -
string
$actualJson -
string
$message optional
assertLessThan() public static
assertLessThan(mixed $expected, mixed $actual, mixed $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, mixed $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, mixed $message)
Asserts that a variable is nan.
Parameters
-
mixed
$actual -
string
$message optional
assertNotContains() public static
assertNotContains(mixed $needle, mixed $haystack, mixed $message, mixed $ignoreCase, mixed $checkForObjectIdentity, mixed $checkForNonObjectIdentity)
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(mixed $type, mixed $haystack, mixed $isNativeType, mixed $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(mixed $expectedCount, mixed $haystack, mixed $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, mixed $message)
Asserts that a variable is not empty.
Parameters
-
mixed
$actual -
string
$message optional
Throws
PHPUnit\Framework\AssertionFailedError
assertNotEquals() public static
assertNotEquals(mixed $expected, mixed $actual, mixed $message, mixed $delta, mixed $maxDepth, mixed $canonicalize, mixed $ignoreCase)
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(mixed $condition, mixed $message)
Asserts that a condition is not false.
Parameters
-
bool
$condition -
string
$message optional
Throws
PHPUnit\Framework\AssertionFailedError
assertNotInstanceOf() public static
assertNotInstanceOf(mixed $expected, mixed $actual, mixed $message)
Asserts that a variable is not of a given type.
Parameters
-
string
$expected -
mixed
$actual -
string
$message optional
assertNotInternalType() public static
assertNotInternalType(mixed $expected, mixed $actual, mixed $message)
Asserts that a variable is not of a given type.
Parameters
-
string
$expected -
mixed
$actual -
string
$message optional
assertNotIsReadable() public static
assertNotIsReadable(mixed $filename, mixed $message)
Asserts that a file/dir exists and is not readable.
Parameters
-
string
$filename -
string
$message optional
assertNotIsWritable() public static
assertNotIsWritable(mixed $filename, mixed $message)
Asserts that a file/dir exists and is not writable.
Parameters
-
string
$filename -
string
$message optional
assertNotNull() public static
assertNotNull(mixed $actual, mixed $message)
Asserts that a variable is not null.
Parameters
-
mixed
$actual -
string
$message optional
assertNotRegExp() public static
assertNotRegExp(mixed $pattern, mixed $string, mixed $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, mixed $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(mixed $expected, mixed $actual, mixed $message)
Assert that the size of two arrays (or Countable
or Traversable
objects) is not the same.
Parameters
-
array|\Countable|\Traversable
$expected -
array|\Countable|\Traversable
$actual -
string
$message optional
assertNotTrue() public static
assertNotTrue(mixed $condition, mixed $message)
Asserts that a condition is not true.
Parameters
-
bool
$condition -
string
$message optional
Throws
PHPUnit\Framework\AssertionFailedError
assertNotWithinRange() protected static
assertNotWithinRange(mixed $expected, mixed $result, mixed $margin, mixed $message)
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
assertNull() public static
assertNull(mixed $actual, mixed $message)
Asserts that a variable is null.
Parameters
-
mixed
$actual -
string
$message optional
assertObjectHasAttribute() public static
assertObjectHasAttribute(mixed $attributeName, mixed $object, mixed $message)
Asserts that an object has a specified attribute.
Parameters
-
string
$attributeName -
object
$object -
string
$message optional
assertObjectNotHasAttribute() public static
assertObjectNotHasAttribute(mixed $attributeName, mixed $object, mixed $message)
Asserts that an object does not have a specified attribute.
Parameters
-
string
$attributeName -
object
$object -
string
$message optional
assertPathEquals() protected static
assertPathEquals(mixed $expected, mixed $result, mixed $message)
Compatibility function to test paths.
Parameters
-
string
$expected -
string
$result -
string
$message optional the text to display if the assertion is not correct
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.
assertRegExp() public static
assertRegExp(mixed $pattern, mixed $string, mixed $message)
Asserts that a string matches a given regular expression.
Parameters
-
string
$pattern -
string
$string -
string
$message optional
assertSame() public static
assertSame(mixed $expected, mixed $actual, mixed $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(mixed $expected, mixed $actual, mixed $message)
Assert that the size of two arrays (or Countable
or Traversable
objects) is the same.
Parameters
-
array|\Countable|\Traversable
$expected -
array|\Countable|\Traversable
$actual -
string
$message optional
assertStringEndsNotWith() public static
assertStringEndsNotWith(mixed $suffix, mixed $string, mixed $message)
Asserts that a string ends not with a given suffix.
Parameters
-
string
$suffix -
string
$string -
string
$message optional
assertStringEndsWith() public static
assertStringEndsWith(mixed $suffix, mixed $string, mixed $message)
Asserts that a string ends with a given suffix.
Parameters
-
string
$suffix -
string
$string -
string
$message optional
assertStringEqualsFile() public static
assertStringEqualsFile(mixed $expectedFile, mixed $actualString, mixed $message, mixed $canonicalize, mixed $ignoreCase)
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(mixed $format, mixed $string, mixed $message)
Asserts that a string matches a given format string.
Parameters
-
string
$format -
string
$string -
string
$message optional
assertStringMatchesFormatFile() public static
assertStringMatchesFormatFile(mixed $formatFile, mixed $string, mixed $message)
Asserts that a string matches a given format file.
Parameters
-
string
$formatFile -
string
$string -
string
$message optional
assertStringNotEqualsFile() public static
assertStringNotEqualsFile(mixed $expectedFile, mixed $actualString, mixed $message, mixed $canonicalize, mixed $ignoreCase)
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(mixed $format, mixed $string, mixed $message)
Asserts that a string does not match a given format string.
Parameters
-
string
$format -
string
$string -
string
$message optional
assertStringNotMatchesFormatFile() public static
assertStringNotMatchesFormatFile(mixed $formatFile, mixed $string, mixed $message)
Asserts that a string does not match a given format string.
Parameters
-
string
$formatFile -
string
$string -
string
$message optional
assertStringStartsNotWith() public static
assertStringStartsNotWith(mixed $prefix, mixed $string, mixed $message)
Asserts that a string starts not with a given prefix.
Parameters
-
string
$prefix -
string
$string -
string
$message optional
assertStringStartsWith() public static
assertStringStartsWith(mixed $prefix, mixed $string, mixed $message)
Asserts that a string starts with a given prefix.
Parameters
-
string
$prefix -
string
$string -
string
$message optional
assertTags() public
assertTags(mixed $string, mixed $expected, mixed $fullDebug)
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.
assertTextContains() public
assertTextContains(mixed $needle, mixed $haystack, mixed $message, mixed $ignoreCase)
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.
assertTextEndsNotWith() public
assertTextEndsNotWith(mixed $suffix, mixed $string, mixed $message)
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.
assertTextEndsWith() public
assertTextEndsWith(mixed $suffix, mixed $string, mixed $message)
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.
assertTextEquals() public
assertTextEquals(mixed $expected, mixed $result, mixed $message)
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.
assertTextNotContains() public
assertTextNotContains(mixed $needle, mixed $haystack, mixed $message, mixed $ignoreCase)
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.
assertTextNotEquals() public
assertTextNotEquals(mixed $expected, mixed $result, mixed $message)
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.
assertTextStartsNotWith() public
assertTextStartsNotWith(mixed $prefix, mixed $string, mixed $message)
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.
assertTextStartsWith() public
assertTextStartsWith(mixed $prefix, mixed $string, mixed $message)
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.
assertThat() public static
assertThat(mixed $value, \PHPUnit\Framework\Constraint\Constraint $constraint, mixed $message)
Evaluates a PHPUnit\Framework\Constraint matcher object.
Parameters
-
mixed
$value -
\PHPUnit\Framework\Constraint\Constraint
$constraint -
string
$message optional
assertTrue() public static
assertTrue(mixed $condition, mixed $message)
Asserts that a condition is true.
Parameters
-
bool
$condition -
string
$message optional
Throws
PHPUnit\Framework\AssertionFailedError
assertWithinRange() protected static
assertWithinRange(mixed $expected, mixed $result, mixed $margin, mixed $message)
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
assertXmlFileEqualsXmlFile() public static
assertXmlFileEqualsXmlFile(mixed $expectedFile, mixed $actualFile, mixed $message)
Asserts that two XML files are equal.
Parameters
-
string
$expectedFile -
string
$actualFile -
string
$message optional
assertXmlFileNotEqualsXmlFile() public static
assertXmlFileNotEqualsXmlFile(mixed $expectedFile, mixed $actualFile, mixed $message)
Asserts that two XML files are not equal.
Parameters
-
string
$expectedFile -
string
$actualFile -
string
$message optional
assertXmlStringEqualsXmlFile() public static
assertXmlStringEqualsXmlFile(mixed $expectedFile, mixed $actualXml, mixed $message)
Asserts that two XML documents are equal.
Parameters
-
string
$expectedFile -
string|\DOMDocument
$actualXml -
string
$message optional
assertXmlStringEqualsXmlString() public static
assertXmlStringEqualsXmlString(mixed $expectedXml, mixed $actualXml, mixed $message)
Asserts that two XML documents are equal.
Parameters
-
string|\DOMDocument
$expectedXml -
string|\DOMDocument
$actualXml -
string
$message optional
assertXmlStringNotEqualsXmlFile() public static
assertXmlStringNotEqualsXmlFile(mixed $expectedFile, mixed $actualXml, mixed $message)
Asserts that two XML documents are not equal.
Parameters
-
string
$expectedFile -
string|\DOMDocument
$actualXml -
string
$message optional
assertXmlStringNotEqualsXmlString() public static
assertXmlStringNotEqualsXmlString(mixed $expectedXml, mixed $actualXml, mixed $message)
Asserts that two XML documents are not equal.
Parameters
-
string|\DOMDocument
$expectedXml -
string|\DOMDocument
$actualXml -
string
$message optional
at() public static
at(mixed $index)
Returns a matcher that matches when the method is executed at the given index.
Parameters
-
int
$index
Returns
\PHPUnit\Framework\MockObject\Matcher\InvokedAtIndex
atLeast() public static
atLeast(mixed $requiredInvocations)
Returns a matcher that matches when the method is executed at least N times.
Parameters
-
int
$requiredInvocations
Returns
\PHPUnit\Framework\MockObject\Matcher\InvokedAtLeastCount
atLeastOnce() public static
atLeastOnce()
Returns a matcher that matches when the method is executed at least once.
Returns
\PHPUnit\Framework\MockObject\Matcher\InvokedAtLeastOnce
atMost() public static
atMost(mixed $allowedInvocations)
Returns a matcher that matches when the method is executed at most N times.
Parameters
-
int
$allowedInvocations
Returns
\PHPUnit\Framework\MockObject\Matcher\InvokedAtMostCount
attribute() public static
attribute(\PHPUnit\Framework\Constraint\Constraint $constraint, mixed $attributeName)
Parameters
-
\PHPUnit\Framework\Constraint\Constraint
$constraint -
string
$attributeName
Returns
\PHPUnit\Framework\Constraint\Attribute
attributeEqualTo() public static
attributeEqualTo(mixed $attributeName, mixed $value, mixed $delta, mixed $maxDepth, mixed $canonicalize, mixed $ignoreCase)
Parameters
-
string
$attributeName -
mixed
$value -
float
$delta optional -
int
$maxDepth optional -
bool
$canonicalize optional -
bool
$ignoreCase optional
Returns
\PHPUnit\Framework\Constraint\Attribute
callback() public static
callback(mixed $callback)
Parameters
-
callable
$callback
Returns
callable
checkRequirements() protected
checkRequirements()
classHasAttribute() public static
classHasAttribute(mixed $attributeName)
Parameters
-
string
$attributeName
Returns
\PHPUnit\Framework\Constraint\ClassHasAttribute
classHasStaticAttribute() public static
classHasStaticAttribute(mixed $attributeName)
Parameters
-
string
$attributeName
Returns
\PHPUnit\Framework\Constraint\ClassHasStaticAttribute
clearPlugins() public
clearPlugins()
Clear all plugins from the global plugin collection.
Useful in test case teardown methods.
contains() public static
contains(mixed $value, mixed $checkForObjectIdentity, mixed $checkForNonObjectIdentity)
Parameters
-
mixed
$value -
bool
$checkForObjectIdentity optional -
bool
$checkForNonObjectIdentity optional
Returns
\PHPUnit\Framework\Constraint\TraversableContains
containsOnly() public static
containsOnly(mixed $type)
Parameters
-
string
$type
Returns
\PHPUnit\Framework\Constraint\TraversableContainsOnly
containsOnlyInstancesOf() public static
containsOnlyInstancesOf(mixed $classname)
Parameters
-
string
$classname
Returns
\PHPUnit\Framework\Constraint\TraversableContainsOnly
count() public
count()
Counts the number of test cases executed by run(TestResult result).
Returns
int
countOf() public static
countOf(mixed $count)
Parameters
-
int
$count
Returns
\PHPUnit\Framework\Constraint\Count
createConfiguredMock() protected
createConfiguredMock(mixed $originalClassName, array $configuration)
Returns a configured test double for the specified class.
Parameters
-
string
$originalClassName -
array
$configuration
Returns
\PHPUnit\Framework\MockObject\MockObject
Throws
PHPUnit\Framework\Exception
createMock() protected
createMock(mixed $originalClassName)
Returns a test double for the specified class.
Parameters
-
string
$originalClassName
Returns
\PHPUnit\Framework\MockObject\MockObject
Throws
PHPUnit\Framework\Exception
createPartialMock() protected
createPartialMock(mixed $originalClassName, array $methods)
Returns a partial test double for the specified class.
Parameters
-
string
$originalClassName -
string[]
$methods
Returns
\PHPUnit\Framework\MockObject\MockObject
Throws
PHPUnit\Framework\Exception
createResult() protected
createResult()
Creates a default TestResult object.
Returns
\PHPUnit\Framework\TestResult
createTestProxy() protected
createTestProxy(mixed $originalClassName, array $constructorArguments)
Returns a test proxy for the specified class.
Parameters
-
string
$originalClassName -
array
$constructorArguments optional
Returns
\PHPUnit\Framework\MockObject\MockObject
Throws
PHPUnit\Framework\Exception
dataDescription() public
dataDescription()
Returns
string
dataName() public
dataName()
Returns
int|string
deprecated() public
deprecated(mixed $callable)
Helper method for check deprecation methods
Parameters
-
callable
$callable callable function that will receive asserts
directoryExists() public static
directoryExists()
Returns
\PHPUnit\Framework\Constraint\DirectoryExists
doesNotPerformAssertions() public
doesNotPerformAssertions()
Returns
bool
equalTo() public static
equalTo(mixed $value, mixed $delta, mixed $maxDepth, mixed $canonicalize, mixed $ignoreCase)
Parameters
-
mixed
$value -
float
$delta optional -
int
$maxDepth optional -
bool
$canonicalize optional -
bool
$ignoreCase optional
Returns
\PHPUnit\Framework\Constraint\IsEqual
exactly() public static
exactly(mixed $count)
Returns a matcher that matches when the method is executed exactly $count times.
Parameters
-
int
$count
Returns
\PHPUnit\Framework\MockObject\Matcher\InvokedCount
expectException() public
expectException(mixed $exception)
Parameters
-
string
$exception
expectExceptionCode() public
expectExceptionCode(mixed $code)
Parameters
-
int|string
$code
Throws
PHPUnit\Framework\Exception
expectExceptionMessage() public
expectExceptionMessage(mixed $message)
Parameters
-
string
$message
Throws
PHPUnit\Framework\Exception
expectExceptionMessageRegExp() public
expectExceptionMessageRegExp(mixed $messageRegExp)
Parameters
-
string
$messageRegExp
Throws
PHPUnit\Framework\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(mixed $expectedRegex)
Parameters
-
string
$expectedRegex
Throws
PHPUnit\Framework\Exception
expectOutputString() public
expectOutputString(mixed $expectedString)
Parameters
-
string
$expectedString
fail() public static
fail(mixed $message)
Fails a test with the given message.
Parameters
-
string
$message optional
Throws
PHPUnit\Framework\AssertionFailedError
fileExists() public static
fileExists()
Returns
\PHPUnit\Framework\Constraint\FileExists
getActualOutput() public
getActualOutput()
Returns
string
getAnnotations() public
getAnnotations()
Returns the annotations for this test.
Returns
array
getCount() public static
getCount()
Return the current assertion count.
Returns
int
getDataSetAsString() public
getDataSetAsString(mixed $includeData)
Gets the data set description of a TestCase.
Parameters
-
bool
$includeData optional
Returns
string
getExpectedException() public
getExpectedException()
Returns
null|string
getExpectedExceptionCode() public
getExpectedExceptionCode()
Returns
null|int|string
getExpectedExceptionMessage() public
getExpectedExceptionMessage()
Returns
string
getExpectedExceptionMessageRegExp() public
getExpectedExceptionMessageRegExp()
Returns
string
getFixtures() public
getFixtures()
Gets fixtures.
Returns
array
getGroups() public
getGroups()
getMockBuilder() public
getMockBuilder(mixed $className)
Returns a builder object to create mock objects using a fluent interface.
Parameters
-
string|string[]
$className
Returns
\PHPUnit\Framework\MockObject\MockBuilder
getMockClass() protected
getMockClass(mixed $originalClassName, mixed $methods, array $arguments, mixed $mockClassName, mixed $callOriginalConstructor, mixed $callOriginalClone, mixed $callAutoload, mixed $cloneArguments)
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
Throws
PHPUnit\Framework\Exception
getMockForAbstractClass() protected
getMockForAbstractClass(mixed $originalClassName, array $arguments, mixed $mockClassName, mixed $callOriginalConstructor, mixed $callOriginalClone, mixed $callAutoload, mixed $mockedMethods, mixed $cloneArguments)
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
\PHPUnit\Framework\MockObject\MockObject
Throws
PHPUnit\Framework\Exception
getMockForModel() public
getMockForModel(mixed $alias, mixed $methods, array $options)
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\Table|\PHPUnit_Framework_MockObject_MockObject
Throws
Cake\ORM\Exception\MissingTableClassException
getMockForTrait() protected
getMockForTrait(mixed $traitName, array $arguments, mixed $mockClassName, mixed $callOriginalConstructor, mixed $callOriginalClone, mixed $callAutoload, mixed $mockedMethods, mixed $cloneArguments)
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
\PHPUnit\Framework\MockObject\MockObject
Throws
PHPUnit\Framework\Exception
getMockFromWsdl() protected
getMockFromWsdl(mixed $wsdlFile, mixed $originalClassName, mixed $mockClassName, array $methods, mixed $callOriginalConstructor, array $options)
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
\PHPUnit\Framework\MockObject\MockObject
getName() public
getName(mixed $withDataSet)
Gets the name of a TestCase.
Parameters
-
bool
$withDataSet optional
Returns
string
getNumAssertions() public
getNumAssertions()
Returns the number of assertions performed by this test.
Returns
int
getObjectAttribute() public static
getObjectAttribute(mixed $object, mixed $attributeName)
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
PHPUnit\Framework\Exception
getObjectForTrait() protected
getObjectForTrait(mixed $traitName, array $arguments, mixed $traitClassName, mixed $callOriginalConstructor, mixed $callOriginalClone, mixed $callAutoload)
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
PHPUnit\Framework\Exception
getProvidedData() protected
getProvidedData()
Gets the data set of a TestCase.
Returns
array
getResult() public
getResult()
Returns
mixed
getSize() public
getSize()
Returns the size of the test.
Returns
int
getStaticAttribute() public static
getStaticAttribute(mixed $className, mixed $attributeName)
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
PHPUnit\Framework\Exception
getStatus() public
getStatus()
Returns the status of this test.
Returns
int
getStatusMessage() public
getStatusMessage()
Returns the status message of this test.
Returns
string
getTableLocator() public
getTableLocator()
Gets the table locator.
Returns
\Cake\ORM\Locator\LocatorInterface
getTestResultObject() public
getTestResultObject()
Returns
\PHPUnit\Framework\TestResult
greaterThan() public static
greaterThan(mixed $value)
Parameters
-
mixed
$value
Returns
\PHPUnit\Framework\Constraint\GreaterThan
greaterThanOrEqual() public static
greaterThanOrEqual(mixed $value)
Parameters
-
mixed
$value
Returns
\PHPUnit\Framework\Constraint\LogicalOr
handleDependencies() protected
handleDependencies()
hasDependencies() public
hasDependencies()
Returns true if the tests has dependencies
Returns
bool
hasExpectationOnOutput() public
hasExpectationOnOutput()
Returns
bool
hasFailed() public
hasFailed()
Returns whether or not this test has failed.
Returns
bool
hasOutput() public
hasOutput()
Returns
bool
hasSize() public
hasSize()
Returns
bool
identicalTo() public static
identicalTo(mixed $value)
Parameters
-
mixed
$value
Returns
\PHPUnit\Framework\Constraint\IsIdentical
iniSet() protected
iniSet(mixed $varName, mixed $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
PHPUnit\Framework\Exception
isEmpty() public static
isEmpty()
Returns
\PHPUnit\Framework\Constraint\IsEmpty
isFalse() public static
isFalse()
Returns
\PHPUnit\Framework\Constraint\IsFalse
isFinite() public static
isFinite()
Returns
\PHPUnit\Framework\Constraint\IsFinite
isInIsolation() public
isInIsolation()
Returns
bool
isInfinite() public static
isInfinite()
Returns
\PHPUnit\Framework\Constraint\IsInfinite
isInstanceOf() public static
isInstanceOf(mixed $className)
Parameters
-
string
$className
Returns
\PHPUnit\Framework\Constraint\IsInstanceOf
isJson() public static
isJson()
Returns
\PHPUnit\Framework\Constraint\IsJson
isLarge() public
isLarge()
Returns
bool
isMedium() public
isMedium()
Returns
bool
isNan() public static
isNan()
Returns
\PHPUnit\Framework\Constraint\IsNan
isNull() public static
isNull()
Returns
\PHPUnit\Framework\Constraint\IsNull
isReadable() public static
isReadable()
Returns
\PHPUnit\Framework\Constraint\IsReadable
isSmall() public
isSmall()
Returns
bool
isTrue() public static
isTrue()
Returns
\PHPUnit\Framework\Constraint\IsTrue
isType() public static
isType(mixed $type)
Parameters
-
string
$type
Returns
\PHPUnit\Framework\Constraint\IsType
isWritable() public static
isWritable()
Returns
\PHPUnit\Framework\Constraint\IsWritable
lessThan() public static
lessThan(mixed $value)
Parameters
-
mixed
$value
Returns
\PHPUnit\Framework\Constraint\LessThan
lessThanOrEqual() public static
lessThanOrEqual(mixed $value)
Parameters
-
mixed
$value
Returns
\PHPUnit\Framework\Constraint\LogicalOr
loadFixtures() public
loadFixtures()
Chooses which fixtures to load for a given test
Each parameter is a model name that corresponds to a fixture, i.e. 'Posts', 'Authors', etc. Passing no parameters will cause all fixtures on the test case to load.
Throws
Exception
when no fixture manager is available.
See Also
loadPlugins() public
loadPlugins(array $plugins)
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
logicalAnd() public static
logicalAnd()
Returns
\PHPUnit\Framework\Constraint\LogicalAnd
logicalNot() public static
logicalNot(\PHPUnit\Framework\Constraint\Constraint $constraint)
Parameters
-
\PHPUnit\Framework\Constraint\Constraint
$constraint
Returns
\PHPUnit\Framework\Constraint\LogicalNot
logicalOr() public static
logicalOr()
Returns
\PHPUnit\Framework\Constraint\LogicalOr
logicalXor() public static
logicalXor()
Returns
\PHPUnit\Framework\Constraint\LogicalXor
markAsRisky() public
markAsRisky()
markTestIncomplete() public static
markTestIncomplete(mixed $message)
Mark the test as incomplete.
Parameters
-
string
$message optional
Throws
PHPUnit\Framework\IncompleteTestError
markTestSkipped() public static
markTestSkipped(mixed $message)
Mark the test as skipped.
Parameters
-
string
$message optional
Throws
PHPUnit\Framework\SkippedTestError
matches() public static
matches(mixed $string)
Parameters
-
string
$string
Returns
\PHPUnit\Framework\Constraint\StringMatchesFormatDescription
matchesRegularExpression() public static
matchesRegularExpression(mixed $pattern)
Parameters
-
string
$pattern
Returns
\PHPUnit\Framework\Constraint\RegularExpression
never() public static
never()
Returns a matcher that matches when the method is never executed.
Returns
\PHPUnit\Framework\MockObject\Matcher\InvokedCount
objectHasAttribute() public static
objectHasAttribute(mixed $attributeName)
Parameters
-
string
$attributeName
Returns
\PHPUnit\Framework\Constraint\ObjectHasAttribute
onConsecutiveCalls() public static
onConsecutiveCalls()
Returns
\PHPUnit\Framework\MockObject\Stub\ConsecutiveCalls
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()
Returns a matcher that matches when the method is executed exactly once.
Returns
\PHPUnit\Framework\MockObject\Matcher\InvokedCount
prepareTemplate() protected
prepareTemplate(\Text_Template $template)
Performs custom preparations on the process isolation template.
Parameters
-
\Text_Template
$template
prophesize() protected
prophesize(mixed $classOrInterface)
Parameters
-
string|null
$classOrInterface optional
Returns
\Prophecy\Prophecy\ObjectProphecy
Throws
LogicException
readAttribute() public static
readAttribute(mixed $classOrObject, mixed $attributeName)
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
PHPUnit\Framework\Exception
registerComparator() public
registerComparator(\SebastianBergmann\Comparator\Comparator $comparator)
Parameters
-
\SebastianBergmann\Comparator\Comparator
$comparator
registerMockObject() public
registerMockObject(\PHPUnit\Framework\MockObject\MockObject $mockObject)
Parameters
-
\PHPUnit\Framework\MockObject\MockObject
$mockObject
removePlugins() public
removePlugins(array $names)
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.
resetCount() public static
resetCount()
Reset the assertion counter.
returnArgument() public static
returnArgument(mixed $argumentIndex)
Parameters
-
int
$argumentIndex
Returns
\PHPUnit\Framework\MockObject\Stub\ReturnArgument
returnCallback() public static
returnCallback(mixed $callback)
Parameters
-
mixed
$callback
Returns
\PHPUnit\Framework\MockObject\Stub\ReturnCallback
returnSelf() public static
returnSelf()
Returns the current object.
This method is useful when mocking a fluent interface.
Returns
\PHPUnit\Framework\MockObject\Stub\ReturnSelf
returnValue() public static
returnValue(mixed $value)
Parameters
-
mixed
$value
Returns
\PHPUnit\Framework\MockObject\Stub\ReturnStub
returnValueMap() public static
returnValueMap(array $valueMap)
Parameters
-
array
$valueMap
Returns
\PHPUnit\Framework\MockObject\Stub\ReturnValueMap
run() public
run(\PHPUnit\Framework\TestResult $result)
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
-
\PHPUnit\Framework\TestResult
$result optional
Returns
\PHPUnit\Framework\TestResult
Throws
PHPUnit\Framework\Exception
runBare() public
runBare()
Runs the bare test sequence.
runTest() protected
runTest()
Override to run the test and assert its state.
Returns
mixed
Throws
PHPUnit\Framework\Exception
PHPUnit\Framework\Exception
setAppNamespace() public static
setAppNamespace(mixed $appNamespace)
Set the app namespace
Parameters
-
string
$appNamespace optional The app namespace, defaults to "TestApp".
setBackupGlobals() public
setBackupGlobals(mixed $backupGlobals)
Calling this method in setUp() has no effect!
Parameters
-
bool
$backupGlobals
setBackupStaticAttributes() public
setBackupStaticAttributes(mixed $backupStaticAttributes)
Calling this method in setUp() has no effect!
Parameters
-
bool
$backupStaticAttributes
setBeStrictAboutChangesToGlobalState() public
setBeStrictAboutChangesToGlobalState(mixed $beStrictAboutChangesToGlobalState)
Parameters
-
bool
$beStrictAboutChangesToGlobalState
setDependencies() public
setDependencies(array $dependencies)
Sets the dependencies of a TestCase.
Parameters
-
string[]
$dependencies
setDependencyInput() public
setDependencyInput(array $dependencyInput)
Sets
Parameters
-
array
$dependencyInput
setExpectedExceptionFromAnnotation() protected
setExpectedExceptionFromAnnotation()
setGroups() public
setGroups(array $groups)
Parameters
-
array
$groups
setInIsolation() public
setInIsolation(mixed $inIsolation)
Parameters
-
bool
$inIsolation
Throws
PHPUnit\Framework\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
PHPUnit\Framework\Exception
setName() public
setName(mixed $name)
Sets the name of a TestCase.
Parameters
-
mixed
$name
setOutputCallback() public
setOutputCallback(mixed $callback)
Parameters
-
callable
$callback
Throws
PHPUnit\Framework\Exception
setPreserveGlobalState() public
setPreserveGlobalState(mixed $preserveGlobalState)
Parameters
-
bool
$preserveGlobalState
Throws
PHPUnit\Framework\Exception
setRegisterMockObjectsFromTestArgumentsRecursively() public
setRegisterMockObjectsFromTestArgumentsRecursively(mixed $flag)
Parameters
-
bool
$flag
setResult() public
setResult(mixed $result)
Parameters
-
mixed
$result
setRunClassInSeparateProcess() public
setRunClassInSeparateProcess(mixed $runClassInSeparateProcess)
Parameters
-
bool
$runClassInSeparateProcess
Throws
PHPUnit\Framework\Exception
setRunTestInSeparateProcess() public
setRunTestInSeparateProcess(mixed $runTestInSeparateProcess)
Parameters
-
bool
$runTestInSeparateProcess
Throws
PHPUnit\Framework\Exception
setTableLocator() public
setTableLocator(\Cake\ORM\Locator\LocatorInterface $tableLocator)
Sets the table locator.
Parameters
-
\Cake\ORM\Locator\LocatorInterface
$tableLocator LocatorInterface instance.
Returns
$this
setTestResultObject() public
setTestResultObject(\PHPUnit\Framework\TestResult $result)
Parameters
-
\PHPUnit\Framework\TestResult
$result
setUp() public
setUp()
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
setUpBeforeClass()
This method is called before the first test of this test class is run.
setUseErrorHandler() public
setUseErrorHandler(mixed $useErrorHandler)
Parameters
-
bool
$useErrorHandler
setUseErrorHandlerFromAnnotation() protected
setUseErrorHandlerFromAnnotation()
skipIf() public
skipIf(mixed $shouldSkip, mixed $message)
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(mixed $condition, mixed $message)
Compatibility function for skipping.
Parameters
-
bool
$condition Condition to trigger skipping
-
string
$message optional Message for skip
Returns
bool
stringContains() public static
stringContains(mixed $string, mixed $case)
Parameters
-
string
$string -
bool
$case optional
Returns
\PHPUnit\Framework\Constraint\StringContains
stringEndsWith() public static
stringEndsWith(mixed $suffix)
Parameters
-
mixed
$suffix
Returns
\PHPUnit\Framework\Constraint\StringEndsWith
stringStartsWith() public static
stringStartsWith(mixed $prefix)
Parameters
-
mixed
$prefix
Returns
\PHPUnit\Framework\Constraint\StringStartsWith
tableLocator() public
tableLocator(\Cake\ORM\Locator\LocatorInterface $tableLocator)
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()
teardown any static object changes and restore them.
tearDownAfterClass() public static
tearDownAfterClass()
This method is called after the last test of this test class is run.
throwException() public static
throwException(\Throwable $exception)
Parameters
-
\Throwable
$exception
Returns
\PHPUnit\Framework\MockObject\Stub\Exception
toString() public
toString()
Returns a string representation of the test case.
Returns
string
usesDataProvider() public
usesDataProvider()
Returns
bool
verifyMockObjects() protected
verifyMockObjects()
Verifies the mock object expectations.
withErrorReporting() public
withErrorReporting(mixed $errorLevel, mixed $callable)
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
Property Detail
$_configure protected
Configure values to restore at end of test.
Type
array
$_tableLocator protected
Table locator instance
Type
\Cake\ORM\Locator\LocatorInterface
$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
$backupGlobalsBlacklist protected
Type
array
$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
$backupStaticAttributesBlacklist protected
Type
array
$dropTables public
Control table create/drops on each test method.
If true, tables will still be dropped at the end of each test runner execution.
Type
bool
$fixtureManager public
The class responsible for managing the creation, loading and removing of fixtures
Type
\Cake\TestSuite\Fixture\FixtureManager|null
$fixtures public
Fixtures used by this test case.
Type
string[]|string|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
© 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/3.9/class-Cake.TestSuite.TestCase.html