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

C CakePHP 5.0 Chiffon API

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

Namespaces

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

Class TestCase

Cake TestCase class

Abstract
Namespace: Cake\TestSuite

Property Summary

  • $_configure protected
    array

    Configure values to restore at end of test.

  • $_tableLocator protected
    Cake\ORM\Locator\LocatorInterface|null

    Table locator instance

  • $defaultTable protected
    string|null

    This object's default table alias.

  • $fixtureStrategy protected
    Cake\TestSuite\Fixture\FixtureStrategyInterface|null
  • $fixtures protected
    array<string>

    Fixtures used by this test case.

Method Summary

  • __construct() public
  • _assertAttributes() protected

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

  • _getTableClassName() protected

    Gets the class name for the table.

  • _normalizePath() protected

    Normalize a path for comparison.

  • addFixture() protected

    Adds a fixture to this test case.

  • addToAssertionCount() public
  • any() public static

    Returns a matcher that matches when the method is executed zero or more times.

  • anything() public static
  • arrayHasKey() public static
  • assertArrayHasKey() public static

    Asserts that an array has a specified key.

  • assertArrayNotHasKey() public static

    Asserts that an array does not have a specified key.

  • assertContains() public static

    Asserts that a haystack contains a needle.

  • assertContainsEquals() public static
  • assertContainsOnly() public static

    Asserts that a haystack contains only values of a given type.

  • assertContainsOnlyInstancesOf() public static

    Asserts that a haystack contains only instances of a given class name.

  • assertCount() public static

    Asserts the number of elements of an array, Countable or Traversable.

  • assertDirectoryDoesNotExist() public static

    Asserts that a directory does not exist.

  • assertDirectoryExists() public static

    Asserts that a directory exists.

  • assertDirectoryIsNotReadable() public static

    Asserts that a directory exists and is not readable.

  • assertDirectoryIsNotWritable() public static

    Asserts that a directory exists and is not writable.

  • assertDirectoryIsReadable() public static

    Asserts that a directory exists and is readable.

  • assertDirectoryIsWritable() public static

    Asserts that a directory exists and is writable.

  • assertDoesNotMatchRegularExpression() public static

    Asserts that a string does not match a given regular expression.

  • assertEmpty() public static

    Asserts that a variable is empty.

  • assertEquals() public static

    Asserts that two variables are equal.

  • assertEqualsCanonicalizing() public static

    Asserts that two variables are equal (canonicalizing).

  • assertEqualsIgnoringCase() public static

    Asserts that two variables are equal (ignoring case).

  • assertEqualsSql() public

    Assert that a string matches SQL with db-specific characters like quotes removed.

  • assertEqualsWithDelta() public static

    Asserts that two variables are equal (with delta).

  • assertEventFired() public

    Asserts that a global event was fired. You must track events in your event manager for this assertion to work

  • assertEventFiredWith() public

    Asserts an event was fired with data

  • assertFalse() public static

    Asserts that a condition is false.

  • assertFileDoesNotExist() public static

    Asserts that a file does not exist.

  • assertFileEquals() public static

    Asserts that the contents of one file is equal to the contents of another file.

  • assertFileEqualsCanonicalizing() public static

    Asserts that the contents of one file is equal to the contents of another file (canonicalizing).

  • assertFileEqualsIgnoringCase() public static

    Asserts that the contents of one file is equal to the contents of another file (ignoring case).

  • assertFileExists() public static

    Asserts that a file exists.

  • assertFileIsNotReadable() public static

    Asserts that a file exists and is not readable.

  • assertFileIsNotWritable() public static

    Asserts that a file exists and is not writable.

  • assertFileIsReadable() public static

    Asserts that a file exists and is readable.

  • assertFileIsWritable() public static

    Asserts that a file exists and is writable.

  • assertFileMatchesFormat() public static

    Asserts that a string matches a given format string.

  • assertFileMatchesFormatFile() public static

    Asserts that a string matches a given format string.

  • assertFileNotEquals() public static

    Asserts that the contents of one file is not equal to the contents of another file.

  • assertFileNotEqualsCanonicalizing() public static

    Asserts that the contents of one file is not equal to the contents of another file (canonicalizing).

  • assertFileNotEqualsIgnoringCase() public static

    Asserts that the contents of one file is not equal to the contents of another file (ignoring case).

  • assertFinite() public static

    Asserts that a variable is finite.

  • assertGreaterThan() public static

    Asserts that a value is greater than another value.

  • assertGreaterThanOrEqual() public static

    Asserts that a value is greater than or equal to another value.

  • assertHtml() public

    Asserts HTML tags.

  • assertInfinite() public static

    Asserts that a variable is infinite.

  • assertInstanceOf() public static

    Asserts that a variable is of a given type.

  • assertIsArray() public static

    Asserts that a variable is of type array.

  • assertIsBool() public static

    Asserts that a variable is of type bool.

  • assertIsCallable() public static

    Asserts that a variable is of type callable.

  • assertIsClosedResource() public static

    Asserts that a variable is of type resource and is closed.

  • assertIsFloat() public static

    Asserts that a variable is of type float.

  • assertIsInt() public static

    Asserts that a variable is of type int.

  • assertIsIterable() public static

    Asserts that a variable is of type iterable.

  • assertIsList() public static
  • assertIsNotArray() public static

    Asserts that a variable is not of type array.

  • assertIsNotBool() public static

    Asserts that a variable is not of type bool.

  • assertIsNotCallable() public static

    Asserts that a variable is not of type callable.

  • assertIsNotClosedResource() public static

    Asserts that a variable is not of type resource.

  • assertIsNotFloat() public static

    Asserts that a variable is not of type float.

  • assertIsNotInt() public static

    Asserts that a variable is not of type int.

  • assertIsNotIterable() public static

    Asserts that a variable is not of type iterable.

  • assertIsNotNumeric() public static

    Asserts that a variable is not of type numeric.

  • assertIsNotObject() public static

    Asserts that a variable is not of type object.

  • assertIsNotReadable() public static

    Asserts that a file/dir exists and is not readable.

  • assertIsNotResource() public static

    Asserts that a variable is not of type resource.

  • assertIsNotScalar() public static

    Asserts that a variable is not of type scalar.

  • assertIsNotString() public static

    Asserts that a variable is not of type string.

  • assertIsNotWritable() public static

    Asserts that a file/dir exists and is not writable.

  • assertIsNumeric() public static

    Asserts that a variable is of type numeric.

  • assertIsObject() public static

    Asserts that a variable is of type object.

  • assertIsReadable() public static

    Asserts that a file/dir is readable.

  • assertIsResource() public static

    Asserts that a variable is of type resource.

  • assertIsScalar() public static

    Asserts that a variable is of type scalar.

  • assertIsString() public static

    Asserts that a variable is of type string.

  • assertIsWritable() public static

    Asserts that a file/dir exists and is writable.

  • assertJson() public static

    Asserts that a string is a valid JSON string.

  • assertJsonFileEqualsJsonFile() public static

    Asserts that two JSON files are equal.

  • assertJsonFileNotEqualsJsonFile() public static

    Asserts that two JSON files are not equal.

  • assertJsonStringEqualsJsonFile() public static

    Asserts that the generated JSON encoded object and the content of the given file are equal.

  • assertJsonStringEqualsJsonString() public static

    Asserts that two given JSON encoded objects or arrays are equal.

  • assertJsonStringNotEqualsJsonFile() public static

    Asserts that the generated JSON encoded object and the content of the given file are not equal.

  • assertJsonStringNotEqualsJsonString() public static

    Asserts that two given JSON encoded objects or arrays are not equal.

  • assertLessThan() public static

    Asserts that a value is smaller than another value.

  • assertLessThanOrEqual() public static

    Asserts that a value is smaller than or equal to another value.

  • assertMatchesRegularExpression() public static

    Asserts that a string matches a given regular expression.

  • assertNan() public static

    Asserts that a variable is nan.

  • assertNotContains() public static

    Asserts that a haystack does not contain a needle.

  • assertNotContainsEquals() public static
  • assertNotContainsOnly() public static

    Asserts that a haystack does not contain only values of a given type.

  • assertNotCount() public static

    Asserts the number of elements of an array, Countable or Traversable.

  • assertNotEmpty() public static

    Asserts that a variable is not empty.

  • assertNotEquals() public static

    Asserts that two variables are not equal.

  • assertNotEqualsCanonicalizing() public static

    Asserts that two variables are not equal (canonicalizing).

  • assertNotEqualsIgnoringCase() public static

    Asserts that two variables are not equal (ignoring case).

  • assertNotEqualsWithDelta() public static

    Asserts that two variables are not equal (with delta).

  • assertNotFalse() public static

    Asserts that a condition is not false.

  • assertNotInstanceOf() public static

    Asserts that a variable is not of a given type.

  • assertNotNull() public static

    Asserts that a variable is not null.

  • assertNotSame() public static

    Asserts that two variables do not have the same type and value. Used on objects, it asserts that two variables do not reference the same object.

  • assertNotSameSize() public static

    Assert that the size of two arrays (or Countable or Traversable objects) is not the same.

  • assertNotTrue() public static

    Asserts that a condition is not true.

  • assertNotWithinRange() protected static

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

  • assertNull() public static

    Asserts that a variable is null.

  • assertObjectEquals() public static
  • assertObjectHasProperty() public static

    Asserts that an object has a specified property.

  • assertObjectNotHasProperty() public static

    Asserts that an object does not have a specified property.

  • assertPathEquals() protected static

    Compatibility function to test paths.

  • assertPostConditions() protected

    Performs assertions shared by all tests of a test case.

  • assertPreConditions() protected

    Performs assertions shared by all tests of a test case.

  • assertRegExpSql() public

    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

  • assertSame() public static

    Asserts that two variables have the same type and value. Used on objects, it asserts that two variables reference the same object.

  • assertSameSize() public static

    Assert that the size of two arrays (or Countable or Traversable objects) is the same.

  • assertStringContainsString() public static
  • assertStringContainsStringIgnoringCase() public static
  • assertStringContainsStringIgnoringLineEndings() public static
  • assertStringEndsNotWith() public static

    Asserts that a string ends not with a given suffix.

  • assertStringEndsWith() public static

    Asserts that a string ends with a given suffix.

  • assertStringEqualsFile() public static

    Asserts that the contents of a string is equal to the contents of a file.

  • assertStringEqualsFileCanonicalizing() public static

    Asserts that the contents of a string is equal to the contents of a file (canonicalizing).

  • assertStringEqualsFileIgnoringCase() public static

    Asserts that the contents of a string is equal to the contents of a file (ignoring case).

  • assertStringEqualsStringIgnoringLineEndings() public static

    Asserts that two strings are equal except for line endings.

  • assertStringMatchesFormat() public static

    Asserts that a string matches a given format string.

  • assertStringMatchesFormatFile() public static

    Asserts that a string matches a given format file.

  • assertStringNotContainsString() public static
  • assertStringNotContainsStringIgnoringCase() public static
  • assertStringNotEqualsFile() public static

    Asserts that the contents of a string is not equal to the contents of a file.

  • assertStringNotEqualsFileCanonicalizing() public static

    Asserts that the contents of a string is not equal to the contents of a file (canonicalizing).

  • assertStringNotEqualsFileIgnoringCase() public static

    Asserts that the contents of a string is not equal to the contents of a file (ignoring case).

  • assertStringNotMatchesFormat() public static deprecated

    Asserts that a string does not match a given format string.

  • assertStringNotMatchesFormatFile() public static deprecated

    Asserts that a string does not match a given format string.

  • assertStringStartsNotWith() public static

    Asserts that a string starts not with a given prefix.

  • assertStringStartsWith() public static

    Asserts that a string starts with a given prefix.

  • assertTextContains() public

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

  • assertTextEndsNotWith() public

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

  • assertTextEndsWith() public

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

  • assertTextEquals() public

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

  • assertTextNotContains() public

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

  • assertTextNotEquals() public

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

  • assertTextStartsNotWith() public

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

  • assertTextStartsWith() public

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

  • assertThat() public static

    Evaluates a PHPUnit\Framework\Constraint matcher object.

  • assertTrue() public static

    Asserts that a condition is true.

  • assertWithinRange() protected static

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

  • assertXmlFileEqualsXmlFile() public static

    Asserts that two XML files are equal.

  • assertXmlFileNotEqualsXmlFile() public static

    Asserts that two XML files are not equal.

  • assertXmlStringEqualsXmlFile() public static

    Asserts that two XML documents are equal.

  • assertXmlStringEqualsXmlString() public static

    Asserts that two XML documents are equal.

  • assertXmlStringNotEqualsXmlFile() public static

    Asserts that two XML documents are not equal.

  • assertXmlStringNotEqualsXmlString() public static

    Asserts that two XML documents are not equal.

  • atLeast() public static

    Returns a matcher that matches when the method is executed at least N times.

  • atLeastOnce() public static

    Returns a matcher that matches when the method is executed at least once.

  • atMost() public static

    Returns a matcher that matches when the method is executed at most N times.

  • callback() public static
  • captureError() public

    Capture errors from $callable so that you can do assertions on the error.

  • clearPlugins() public

    Clear all plugins from the global plugin collection.

  • containsEqual() public static
  • containsIdentical() public static
  • containsOnly() public static
  • containsOnlyInstancesOf() public static
  • count() public
  • countOf() public static
  • createConfiguredMock() protected

    Creates (and configures) a mock object for the specified interface or class.

  • createConfiguredStub() protected static

    Creates (and configures) a test stub for the specified interface or class.

  • createMock() protected

    Creates a mock object for the specified interface or class.

  • createMockForIntersectionOfInterfaces() protected
  • createPartialMock() protected

    Creates a partial mock object for the specified interface or class.

  • createStub() protected static

    Creates a test stub for the specified interface or class.

  • createStubForIntersectionOfInterfaces() protected static
  • createTestProxy() protected deprecated

    Creates a test proxy for the specified class.

  • dataName() public
  • dataSetAsString() public
  • dataSetAsStringWithData() public
  • dependencyInput() public
  • deprecated() public

    Helper method for check deprecation methods

  • directoryExists() public static
  • doesNotPerformAssertions() public
  • equalTo() public static
  • equalToCanonicalizing() public static
  • equalToIgnoringCase() public static
  • equalToWithDelta() public static
  • exactly() public static

    Returns a matcher that matches when the method is executed exactly $count times.

  • expectDeprecationMessageMatches() public
  • expectErrorHandlerMessageMatches() protected
  • expectErrorMessageMatches() public
  • expectException() public
  • expectExceptionCode() public
  • expectExceptionMessage() public
  • expectExceptionMessageMatches() public
  • expectExceptionObject() public

    Sets up an expectation for an exception to be raised by the code under test. Information for expected exception class, expected exception message, and expected exception code are retrieved from a given Exception object.

  • expectNotToPerformAssertions() public
  • expectNoticeMessageMatches() public
  • expectOutputRegex() public
  • expectOutputString() public
  • expectWarningMessageMatches() public
  • expectsOutput() public
  • fail() public static

    Fails a test with the given message.

  • fetchTable() public

    Convenience method to get a table instance.

  • fileExists() public static
  • getActualOutputForAssertion() public
  • getCount() public static

    Return the current assertion count.

  • getFixtureStrategy() protected

    Returns fixture strategy used by these tests.

  • getFixtures() public

    Get the fixtures this test should use.

  • getMockBuilder() public

    Returns a builder object to create mock objects using a fluent interface.

  • getMockForAbstractClass() protected deprecated

    Creates a mock object for the specified abstract class with all abstract methods of the class mocked. Concrete methods are not mocked by default. To mock concrete methods, use the 7th parameter ($mockedMethods).

  • getMockForModel() public

    Mock a model, maintain fixtures and table association

  • getMockForTrait() protected deprecated

    Creates a mock object for the specified trait with all abstract methods of the trait mocked. Concrete methods to mock can be specified with the $mockedMethods parameter.

  • getMockFromWsdl() protected deprecated

    Creates a mock object based on the given WSDL file.

  • getObjectForTrait() protected deprecated

    Creates an object that uses the specified trait.

  • getTableLocator() public

    Gets the table locator.

  • greaterThan() public static
  • greaterThanOrEqual() public static
  • groups() public
  • hasDependencyInput() public
  • hasUnexpectedOutput() public
  • identicalTo() public static
  • iniSet() protected deprecated

    This method is a wrapper for the ini_set() function that automatically resets the modified php.ini setting to its original value after the test is run.

  • isEmpty() public static
  • isFalse() public static
  • isFinite() public static
  • isInIsolation() public
  • isInfinite() public static
  • isInstanceOf() public static
  • isJson() public static
  • isList() public static
  • isNan() public static
  • isNull() public static
  • isReadable() public static
  • isTrue() public static
  • isType() public static
  • isWritable() public static
  • lessThan() public static
  • lessThanOrEqual() public static
  • loadPlugins() public

    Load plugins into a simulated application.

  • loadRoutes() public

    Load routes for the application.

  • logicalAnd() public static
  • logicalNot() public static
  • logicalOr() public static
  • logicalXor() public static
  • markTestIncomplete() public static

    Mark the test as incomplete.

  • markTestSkipped() public static

    Mark the test as skipped.

  • matches() public static
  • matchesRegularExpression() public static
  • name() public
  • nameWithDataSet() public
  • never() public static

    Returns a matcher that matches when the method is never executed.

  • numberOfAssertionsPerformed() public
  • objectEquals() public static
  • onConsecutiveCalls() public static deprecated
  • onNotSuccessfulTest() protected

    This method is called when a test method did not execute successfully.

  • once() public static

    Returns a matcher that matches when the method is executed exactly once.

  • output() public
  • providedData() public
  • provides() public
  • registerComparator() protected
  • registerFailureType() protected
  • registerMockObject() public
  • registerMockObjectsFromTestArgumentsRecursively() public deprecated
  • removePlugins() public

    Remove plugins from the global plugin collection.

  • requires() public
  • resetCount() public static

    Reset the assertion counter.

  • result() public
  • returnArgument() public static deprecated
  • returnCallback() public static deprecated
  • returnSelf() public static deprecated
  • returnValue() public static deprecated
  • returnValueMap() public static deprecated
  • run() public
  • runBare() public
  • runTest() protected
  • setAppNamespace() public static

    Set the app namespace

  • setBackupGlobals() public
  • setBackupGlobalsExcludeList() public
  • setBackupStaticProperties() public
  • setBackupStaticPropertiesExcludeList() public
  • setData() public
  • setDependencies() public
  • setDependencyInput() public
  • setGroups() public
  • setInIsolation() public
  • setLocale() protected deprecated

    This method is a wrapper for the setlocale() function that automatically resets the locale to its original value after the test is run.

  • setName() public
  • setPreserveGlobalState() public
  • setResult() public
  • setRunClassInSeparateProcess() public
  • setRunTestInSeparateProcess() public
  • setTableLocator() public

    Sets the table locator.

  • setUp() protected

    Setup the test case, backup the static object values so they can be restored. Specifically backs up the contents of Configure and paths in App if they have not already been backed up.

  • setUpBeforeClass() public static

    This method is called before the first test of this test class is run.

  • setupFixtures() protected

    Initialized and loads any use fixtures.

  • size() public
  • skipIf() public

    Overrides SimpleTestCase::skipIf to provide a boolean return value

  • skipUnless() protected

    Compatibility function for skipping.

  • sortId() public
  • status() public
  • stringContains() public static
  • stringEndsWith() public static
  • stringEqualsStringIgnoringLineEndings() public static
  • stringStartsWith() public static
  • tearDown() protected

    teardown any static object changes and restore them.

  • tearDownAfterClass() public static

    This method is called after the last test of this test class is run.

  • teardownFixtures() protected

    Unloads any use fixtures.

  • throwException() public static
  • toString() public

    Returns a string representation of the test case.

  • transformException() protected
  • usesDataProvider() public
  • valueObjectForEvents() public
  • wasPrepared() public
  • withConsecutive() public static
  • withErrorReporting() public

    Helper method for tests that needs to use error_reporting()

Method Detail

__construct() ¶ public

__construct(string $name)
Parameters
string $name

_assertAttributes() ¶ protected

_assertAttributes(array<string, mixed> $assertions, string $string, bool $fullDebug = false, array|string $regex = ''): string|false

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

Parameters
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

Returns
string|false

_getTableClassName() ¶ protected

_getTableClassName(string $alias, array<string, mixed> $options): class-string<Cake\ORM\Table>

Gets the class name for the table.

Parameters
string $alias

The model to get a mock for.

array<string, mixed> $options

The config data for the mock's constructor.

Returns
class-string<Cake\ORM\Table>
Throws
Cake\ORM\Exception\MissingTableClassException

_normalizePath() ¶ protected

_normalizePath(string $path): string

Normalize a path for comparison.

Parameters
string $path

Path separated by "/" slash.

Returns
string

addFixture() ¶ protected

addFixture(string $fixture): $this

Adds a fixture to this test case.

Examples:

  • core.Tags
  • app.MyRecords
  • plugin.MyPluginName.MyModelName

Use this method inside your test cases' {@link getFixtures()} method to build up the fixture list.

Parameters
string $fixture

Fixture

Returns
$this

addToAssertionCount() ¶ public

addToAssertionCount(int $count): void
Parameters
int $count
Returns
void

any() ¶ public static

any(): AnyInvokedCountMatcher

Returns a matcher that matches when the method is executed zero or more times.

Returns
AnyInvokedCountMatcher

anything() ¶ public static

anything(): IsAnything
Returns
IsAnything

arrayHasKey() ¶ public static

arrayHasKey(int|string $key): ArrayHasKey
Parameters
int|string $key
Returns
ArrayHasKey

assertArrayHasKey() ¶ public static

assertArrayHasKey(int|string $key, array|ArrayAccess $array, string $message = ''): void

Asserts that an array has a specified key.

Parameters
int|string $key
array|ArrayAccess $array
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertArrayNotHasKey() ¶ public static

assertArrayNotHasKey(int|string $key, array|ArrayAccess $array, string $message = ''): void

Asserts that an array does not have a specified key.

Parameters
int|string $key
array|ArrayAccess $array
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertContains() ¶ public static

assertContains(mixed $needle, iterable $haystack, string $message = ''): void

Asserts that a haystack contains a needle.

Parameters
mixed $needle
iterable $haystack
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertContainsEquals() ¶ public static

assertContainsEquals(mixed $needle, iterable $haystack, string $message = ''): void
Parameters
mixed $needle
iterable $haystack
string $message optional
Returns
void
Throws
ExpectationFailedException

assertContainsOnly() ¶ public static

assertContainsOnly(string $type, iterable $haystack, ?bool $isNativeType = null, string $message = ''): void

Asserts that a haystack contains only values of a given type.

Parameters
string $type
iterable $haystack
?bool $isNativeType optional
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertContainsOnlyInstancesOf() ¶ public static

assertContainsOnlyInstancesOf(string $className, iterable $haystack, string $message = ''): void

Asserts that a haystack contains only instances of a given class name.

Parameters
string $className
iterable $haystack
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertCount() ¶ public static

assertCount(int $expectedCount, Countable|iterable $haystack, string $message = ''): void

Asserts the number of elements of an array, Countable or Traversable.

Parameters
int $expectedCount
Countable|iterable $haystack
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

GeneratorNotSupportedException

assertDirectoryDoesNotExist() ¶ public static

assertDirectoryDoesNotExist(string $directory, string $message = ''): void

Asserts that a directory does not exist.

Parameters
string $directory
string $message optional
Returns
void
Throws
ExpectationFailedException

assertDirectoryExists() ¶ public static

assertDirectoryExists(string $directory, string $message = ''): void

Asserts that a directory exists.

Parameters
string $directory
string $message optional
Returns
void
Throws
ExpectationFailedException

assertDirectoryIsNotReadable() ¶ public static

assertDirectoryIsNotReadable(string $directory, string $message = ''): void

Asserts that a directory exists and is not readable.

Parameters
string $directory
string $message optional
Returns
void
Throws
ExpectationFailedException

assertDirectoryIsNotWritable() ¶ public static

assertDirectoryIsNotWritable(string $directory, string $message = ''): void

Asserts that a directory exists and is not writable.

Parameters
string $directory
string $message optional
Returns
void
Throws
ExpectationFailedException

assertDirectoryIsReadable() ¶ public static

assertDirectoryIsReadable(string $directory, string $message = ''): void

Asserts that a directory exists and is readable.

Parameters
string $directory
string $message optional
Returns
void
Throws
ExpectationFailedException

assertDirectoryIsWritable() ¶ public static

assertDirectoryIsWritable(string $directory, string $message = ''): void

Asserts that a directory exists and is writable.

Parameters
string $directory
string $message optional
Returns
void
Throws
ExpectationFailedException

assertDoesNotMatchRegularExpression() ¶ public static

assertDoesNotMatchRegularExpression(string $pattern, string $string, string $message = ''): void

Asserts that a string does not match a given regular expression.

Parameters
string $pattern
string $string
string $message optional
Returns
void
Throws
ExpectationFailedException

assertEmpty() ¶ public static

assertEmpty(mixed $actual, string $message = ''): void

Asserts that a variable is empty.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

GeneratorNotSupportedException

assertEquals() ¶ public static

assertEquals(mixed $expected, mixed $actual, string $message = ''): void

Asserts that two variables are equal.

Parameters
mixed $expected
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertEqualsCanonicalizing() ¶ public static

assertEqualsCanonicalizing(mixed $expected, mixed $actual, string $message = ''): void

Asserts that two variables are equal (canonicalizing).

Parameters
mixed $expected
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertEqualsIgnoringCase() ¶ public static

assertEqualsIgnoringCase(mixed $expected, mixed $actual, string $message = ''): void

Asserts that two variables are equal (ignoring case).

Parameters
mixed $expected
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertEqualsSql() ¶ public

assertEqualsSql(string $expected, string $actual, string $message = ''): void

Assert that a string matches SQL with db-specific characters like quotes removed.

Parameters
string $expected

The expected sql

string $actual

The sql to compare

string $message optional

The message to display on failure

Returns
void

assertEqualsWithDelta() ¶ public static

assertEqualsWithDelta(mixed $expected, mixed $actual, float $delta, string $message = ''): void

Asserts that two variables are equal (with delta).

Parameters
mixed $expected
mixed $actual
float $delta
string $message optional
Returns
void
Throws
ExpectationFailedException

assertEventFired() ¶ public

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

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

Returns
void

assertEventFiredWith() ¶ public

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

Parameters
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

Returns
void

assertFalse() ¶ public static

assertFalse(mixed $condition, string $message = ''): void

Asserts that a condition is false.

Parameters
mixed $condition
string $message optional
Returns
void
Throws
ExpectationFailedException

assertFileDoesNotExist() ¶ public static

assertFileDoesNotExist(string $filename, string $message = ''): void

Asserts that a file does not exist.

Parameters
string $filename
string $message optional
Returns
void
Throws
ExpectationFailedException

assertFileEquals() ¶ public static

assertFileEquals(string $expected, string $actual, string $message = ''): void

Asserts that the contents of one file is equal to the contents of another file.

Parameters
string $expected
string $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertFileEqualsCanonicalizing() ¶ public static

assertFileEqualsCanonicalizing(string $expected, string $actual, string $message = ''): void

Asserts that the contents of one file is equal to the contents of another file (canonicalizing).

Parameters
string $expected
string $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertFileEqualsIgnoringCase() ¶ public static

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

Parameters
string $expected
string $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertFileExists() ¶ public static

assertFileExists(string $filename, string $message = ''): void

Asserts that a file exists.

Parameters
string $filename
string $message optional
Returns
void
Throws
ExpectationFailedException

assertFileIsNotReadable() ¶ public static

assertFileIsNotReadable(string $file, string $message = ''): void

Asserts that a file exists and is not readable.

Parameters
string $file
string $message optional
Returns
void
Throws
ExpectationFailedException

assertFileIsNotWritable() ¶ public static

assertFileIsNotWritable(string $file, string $message = ''): void

Asserts that a file exists and is not writable.

Parameters
string $file
string $message optional
Returns
void
Throws
ExpectationFailedException

assertFileIsReadable() ¶ public static

assertFileIsReadable(string $file, string $message = ''): void

Asserts that a file exists and is readable.

Parameters
string $file
string $message optional
Returns
void
Throws
ExpectationFailedException

assertFileIsWritable() ¶ public static

assertFileIsWritable(string $file, string $message = ''): void

Asserts that a file exists and is writable.

Parameters
string $file
string $message optional
Returns
void
Throws
ExpectationFailedException

assertFileMatchesFormat() ¶ public static

assertFileMatchesFormat(string $format, string $actualFile, string $message = ''): void

Asserts that a string matches a given format string.

Parameters
string $format
string $actualFile
string $message optional
Returns
void
Throws
ExpectationFailedException

assertFileMatchesFormatFile() ¶ public static

assertFileMatchesFormatFile(string $formatFile, string $actualFile, string $message = ''): void

Asserts that a string matches a given format string.

Parameters
string $formatFile
string $actualFile
string $message optional
Returns
void
Throws
ExpectationFailedException

assertFileNotEquals() ¶ public static

assertFileNotEquals(string $expected, string $actual, string $message = ''): void

Asserts that the contents of one file is not equal to the contents of another file.

Parameters
string $expected
string $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertFileNotEqualsCanonicalizing() ¶ public static

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

Parameters
string $expected
string $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertFileNotEqualsIgnoringCase() ¶ public static

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

Parameters
string $expected
string $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertFinite() ¶ public static

assertFinite(mixed $actual, string $message = ''): void

Asserts that a variable is finite.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertGreaterThan() ¶ public static

assertGreaterThan(mixed $expected, mixed $actual, string $message = ''): void

Asserts that a value is greater than another value.

Parameters
mixed $expected
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertGreaterThanOrEqual() ¶ public static

assertGreaterThanOrEqual(mixed $expected, mixed $actual, string $message = ''): void

Asserts that a value is greater than or equal to another value.

Parameters
mixed $expected
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertHtml() ¶ public

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

Asserts HTML tags.

Takes an array $expected and generates a regex from it to match the provided $string. Samples for $expected:

Checks for an input tag with a name attribute (contains any non-empty value) and an id attribute that contains 'my-input':

['input' => ['name', 'id' => 'my-input']]

Checks for two p elements with some text in them:

[
  ['p' => true],
  'textA',
  '/p',
  ['p' => true],
  'textB',
  '/p'
]

You can also specify a pattern expression as part of the attribute values, or the tag being defined, if you prepend the value with preg: and enclose it with slashes, like so:

[
  ['input' => ['name', 'id' => 'preg:/FieldName\d+/']],
  'preg:/My\s+field/'
]

Important: This function is very forgiving about whitespace and also accepts any permutation of attribute order. It will also allow whitespace between specified tags.

Parameters
array $expected

An array, see above

string $string

An HTML/XHTML/XML string

bool $fullDebug optional

Whether more verbose output should be used.

Returns
bool

assertInfinite() ¶ public static

assertInfinite(mixed $actual, string $message = ''): void

Asserts that a variable is infinite.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertInstanceOf() ¶ public static

assertInstanceOf(string $expected, mixed $actual, string $message = ''): void

Asserts that a variable is of a given type.

Parameters
string $expected
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

UnknownClassOrInterfaceException

assertIsArray() ¶ public static

assertIsArray(mixed $actual, string $message = ''): void

Asserts that a variable is of type array.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsBool() ¶ public static

assertIsBool(mixed $actual, string $message = ''): void

Asserts that a variable is of type bool.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsCallable() ¶ public static

assertIsCallable(mixed $actual, string $message = ''): void

Asserts that a variable is of type callable.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsClosedResource() ¶ public static

assertIsClosedResource(mixed $actual, string $message = ''): void

Asserts that a variable is of type resource and is closed.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsFloat() ¶ public static

assertIsFloat(mixed $actual, string $message = ''): void

Asserts that a variable is of type float.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsInt() ¶ public static

assertIsInt(mixed $actual, string $message = ''): void

Asserts that a variable is of type int.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsIterable() ¶ public static

assertIsIterable(mixed $actual, string $message = ''): void

Asserts that a variable is of type iterable.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsList() ¶ public static

assertIsList(mixed $array, string $message = ''): void
Parameters
mixed $array
string $message optional
Returns
void
Throws
ExpectationFailedException

assertIsNotArray() ¶ public static

assertIsNotArray(mixed $actual, string $message = ''): void

Asserts that a variable is not of type array.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsNotBool() ¶ public static

assertIsNotBool(mixed $actual, string $message = ''): void

Asserts that a variable is not of type bool.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsNotCallable() ¶ public static

assertIsNotCallable(mixed $actual, string $message = ''): void

Asserts that a variable is not of type callable.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsNotClosedResource() ¶ public static

assertIsNotClosedResource(mixed $actual, string $message = ''): void

Asserts that a variable is not of type resource.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsNotFloat() ¶ public static

assertIsNotFloat(mixed $actual, string $message = ''): void

Asserts that a variable is not of type float.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsNotInt() ¶ public static

assertIsNotInt(mixed $actual, string $message = ''): void

Asserts that a variable is not of type int.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsNotIterable() ¶ public static

assertIsNotIterable(mixed $actual, string $message = ''): void

Asserts that a variable is not of type iterable.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsNotNumeric() ¶ public static

assertIsNotNumeric(mixed $actual, string $message = ''): void

Asserts that a variable is not of type numeric.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsNotObject() ¶ public static

assertIsNotObject(mixed $actual, string $message = ''): void

Asserts that a variable is not of type object.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsNotReadable() ¶ public static

assertIsNotReadable(string $filename, string $message = ''): void

Asserts that a file/dir exists and is not readable.

Parameters
string $filename
string $message optional
Returns
void
Throws
ExpectationFailedException

assertIsNotResource() ¶ public static

assertIsNotResource(mixed $actual, string $message = ''): void

Asserts that a variable is not of type resource.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsNotScalar() ¶ public static

assertIsNotScalar(mixed $actual, string $message = ''): void

Asserts that a variable is not of type scalar.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsNotString() ¶ public static

assertIsNotString(mixed $actual, string $message = ''): void

Asserts that a variable is not of type string.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsNotWritable() ¶ public static

assertIsNotWritable(string $filename, string $message = ''): void

Asserts that a file/dir exists and is not writable.

Parameters
string $filename
string $message optional
Returns
void
Throws
ExpectationFailedException

assertIsNumeric() ¶ public static

assertIsNumeric(mixed $actual, string $message = ''): void

Asserts that a variable is of type numeric.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsObject() ¶ public static

assertIsObject(mixed $actual, string $message = ''): void

Asserts that a variable is of type object.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsReadable() ¶ public static

assertIsReadable(string $filename, string $message = ''): void

Asserts that a file/dir is readable.

Parameters
string $filename
string $message optional
Returns
void
Throws
ExpectationFailedException

assertIsResource() ¶ public static

assertIsResource(mixed $actual, string $message = ''): void

Asserts that a variable is of type resource.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsScalar() ¶ public static

assertIsScalar(mixed $actual, string $message = ''): void

Asserts that a variable is of type scalar.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsString() ¶ public static

assertIsString(mixed $actual, string $message = ''): void

Asserts that a variable is of type string.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertIsWritable() ¶ public static

assertIsWritable(string $filename, string $message = ''): void

Asserts that a file/dir exists and is writable.

Parameters
string $filename
string $message optional
Returns
void
Throws
ExpectationFailedException

assertJson() ¶ public static

assertJson(string $actual, string $message = ''): void

Asserts that a string is a valid JSON string.

Parameters
string $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertJsonFileEqualsJsonFile() ¶ public static

assertJsonFileEqualsJsonFile(string $expectedFile, string $actualFile, string $message = ''): void

Asserts that two JSON files are equal.

Parameters
string $expectedFile
string $actualFile
string $message optional
Returns
void
Throws
ExpectationFailedException

assertJsonFileNotEqualsJsonFile() ¶ public static

assertJsonFileNotEqualsJsonFile(string $expectedFile, string $actualFile, string $message = ''): void

Asserts that two JSON files are not equal.

Parameters
string $expectedFile
string $actualFile
string $message optional
Returns
void
Throws
ExpectationFailedException

assertJsonStringEqualsJsonFile() ¶ public static

assertJsonStringEqualsJsonFile(string $expectedFile, string $actualJson, string $message = ''): void

Asserts that the generated JSON encoded object and the content of the given file are equal.

Parameters
string $expectedFile
string $actualJson
string $message optional
Returns
void
Throws
ExpectationFailedException

assertJsonStringEqualsJsonString() ¶ public static

assertJsonStringEqualsJsonString(string $expectedJson, string $actualJson, string $message = ''): void

Asserts that two given JSON encoded objects or arrays are equal.

Parameters
string $expectedJson
string $actualJson
string $message optional
Returns
void
Throws
ExpectationFailedException

assertJsonStringNotEqualsJsonFile() ¶ public static

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.

Parameters
string $expectedFile
string $actualJson
string $message optional
Returns
void
Throws
ExpectationFailedException

assertJsonStringNotEqualsJsonString() ¶ public static

assertJsonStringNotEqualsJsonString(string $expectedJson, string $actualJson, string $message = ''): void

Asserts that two given JSON encoded objects or arrays are not equal.

Parameters
string $expectedJson
string $actualJson
string $message optional
Returns
void
Throws
ExpectationFailedException

assertLessThan() ¶ public static

assertLessThan(mixed $expected, mixed $actual, string $message = ''): void

Asserts that a value is smaller than another value.

Parameters
mixed $expected
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertLessThanOrEqual() ¶ public static

assertLessThanOrEqual(mixed $expected, mixed $actual, string $message = ''): void

Asserts that a value is smaller than or equal to another value.

Parameters
mixed $expected
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertMatchesRegularExpression() ¶ public static

assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void

Asserts that a string matches a given regular expression.

Parameters
string $pattern
string $string
string $message optional
Returns
void
Throws
ExpectationFailedException

assertNan() ¶ public static

assertNan(mixed $actual, string $message = ''): void

Asserts that a variable is nan.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertNotContains() ¶ public static

assertNotContains(mixed $needle, iterable $haystack, string $message = ''): void

Asserts that a haystack does not contain a needle.

Parameters
mixed $needle
iterable $haystack
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertNotContainsEquals() ¶ public static

assertNotContainsEquals(mixed $needle, iterable $haystack, string $message = ''): void
Parameters
mixed $needle
iterable $haystack
string $message optional
Returns
void
Throws
ExpectationFailedException

assertNotContainsOnly() ¶ public static

assertNotContainsOnly(string $type, iterable $haystack, ?bool $isNativeType = null, string $message = ''): void

Asserts that a haystack does not contain only values of a given type.

Parameters
string $type
iterable $haystack
?bool $isNativeType optional
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertNotCount() ¶ public static

assertNotCount(int $expectedCount, Countable|iterable $haystack, string $message = ''): void

Asserts the number of elements of an array, Countable or Traversable.

Parameters
int $expectedCount
Countable|iterable $haystack
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

GeneratorNotSupportedException

assertNotEmpty() ¶ public static

assertNotEmpty(mixed $actual, string $message = ''): void

Asserts that a variable is not empty.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

GeneratorNotSupportedException

assertNotEquals() ¶ public static

assertNotEquals(mixed $expected, mixed $actual, string $message = ''): void

Asserts that two variables are not equal.

Parameters
mixed $expected
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertNotEqualsCanonicalizing() ¶ public static

assertNotEqualsCanonicalizing(mixed $expected, mixed $actual, string $message = ''): void

Asserts that two variables are not equal (canonicalizing).

Parameters
mixed $expected
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertNotEqualsIgnoringCase() ¶ public static

assertNotEqualsIgnoringCase(mixed $expected, mixed $actual, string $message = ''): void

Asserts that two variables are not equal (ignoring case).

Parameters
mixed $expected
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertNotEqualsWithDelta() ¶ public static

assertNotEqualsWithDelta(mixed $expected, mixed $actual, float $delta, string $message = ''): void

Asserts that two variables are not equal (with delta).

Parameters
mixed $expected
mixed $actual
float $delta
string $message optional
Returns
void
Throws
ExpectationFailedException

assertNotFalse() ¶ public static

assertNotFalse(mixed $condition, string $message = ''): void

Asserts that a condition is not false.

Parameters
mixed $condition
string $message optional
Returns
void
Throws
ExpectationFailedException

assertNotInstanceOf() ¶ public static

assertNotInstanceOf(string $expected, mixed $actual, string $message = ''): void

Asserts that a variable is not of a given type.

Parameters
string $expected
mixed $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

assertNotNull() ¶ public static

assertNotNull(mixed $actual, string $message = ''): void

Asserts that a variable is not null.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertNotSame() ¶ public static

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.

Parameters
mixed $expected
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertNotSameSize() ¶ public static

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.

Parameters
Countable|iterable $expected
Countable|iterable $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

GeneratorNotSupportedException

assertNotTrue() ¶ public static

assertNotTrue(mixed $condition, string $message = ''): void

Asserts that a condition is not true.

Parameters
mixed $condition
string $message optional
Returns
void
Throws
ExpectationFailedException

assertNotWithinRange() ¶ protected static

assertNotWithinRange(float $expected, float $result, float $margin, string $message = ''): void

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

Parameters
float $expected
float $result
float $margin

the rage of acceptation

string $message optional

the text to display if the assertion is not correct

Returns
void

assertNull() ¶ public static

assertNull(mixed $actual, string $message = ''): void

Asserts that a variable is null.

Parameters
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertObjectEquals() ¶ public static

assertObjectEquals(object $expected, object $actual, string $method = 'equals', string $message = ''): void
Parameters
object $expected
object $actual
string $method optional
string $message optional
Returns
void
Throws
ExpectationFailedException

assertObjectHasProperty() ¶ public static

assertObjectHasProperty(string $propertyName, object $object, string $message = ''): void

Asserts that an object has a specified property.

Parameters
string $propertyName
object $object
string $message optional
Returns
void
Throws
ExpectationFailedException

assertObjectNotHasProperty() ¶ public static

assertObjectNotHasProperty(string $propertyName, object $object, string $message = ''): void

Asserts that an object does not have a specified property.

Parameters
string $propertyName
object $object
string $message optional
Returns
void
Throws
ExpectationFailedException

assertPathEquals() ¶ protected static

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

Compatibility function to test paths.

Parameters
string $expected
string $result
string $message optional

the text to display if the assertion is not correct

Returns
void

assertPostConditions() ¶ protected

assertPostConditions(): void

Performs assertions shared by all tests of a test case.

This method is called between test and tearDown().

Returns
void

assertPreConditions() ¶ protected

assertPreConditions(): void

Performs assertions shared by all tests of a test case.

This method is called between setUp() and test.

Returns
void

assertRegExpSql() ¶ public

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

Parameters
string $pattern

The expected sql pattern

string $actual

The sql to compare

bool $optional optional

Whether quote characters (marked with <>) are optional

Returns
void

assertSame() ¶ public static

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.

Parameters
mixed $expected
mixed $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertSameSize() ¶ public static

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.

Parameters
Countable|iterable $expected
Countable|iterable $actual
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

GeneratorNotSupportedException

assertStringContainsString() ¶ public static

assertStringContainsString(string $needle, string $haystack, string $message = ''): void
Parameters
string $needle
string $haystack
string $message optional
Returns
void
Throws
ExpectationFailedException

assertStringContainsStringIgnoringCase() ¶ public static

assertStringContainsStringIgnoringCase(string $needle, string $haystack, string $message = ''): void
Parameters
string $needle
string $haystack
string $message optional
Returns
void
Throws
ExpectationFailedException

assertStringContainsStringIgnoringLineEndings() ¶ public static

assertStringContainsStringIgnoringLineEndings(string $needle, string $haystack, string $message = ''): void
Parameters
string $needle
string $haystack
string $message optional
Returns
void
Throws
ExpectationFailedException

assertStringEndsNotWith() ¶ public static

assertStringEndsNotWith(string $suffix, string $string, string $message = ''): void

Asserts that a string ends not with a given suffix.

Parameters
string $suffix
string $string
string $message optional
Returns
void
Throws
ExpectationFailedException

InvalidArgumentException

assertStringEndsWith() ¶ public static

assertStringEndsWith(string $suffix, string $string, string $message = ''): void

Asserts that a string ends with a given suffix.

Parameters
string $suffix
string $string
string $message optional
Returns
void
Throws
ExpectationFailedException

InvalidArgumentException

assertStringEqualsFile() ¶ public static

assertStringEqualsFile(string $expectedFile, string $actualString, string $message = ''): void

Asserts that the contents of a string is equal to the contents of a file.

Parameters
string $expectedFile
string $actualString
string $message optional
Returns
void
Throws
ExpectationFailedException

assertStringEqualsFileCanonicalizing() ¶ public static

assertStringEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = ''): void

Asserts that the contents of a string is equal to the contents of a file (canonicalizing).

Parameters
string $expectedFile
string $actualString
string $message optional
Returns
void
Throws
ExpectationFailedException

assertStringEqualsFileIgnoringCase() ¶ public static

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

Parameters
string $expectedFile
string $actualString
string $message optional
Returns
void
Throws
ExpectationFailedException

assertStringEqualsStringIgnoringLineEndings() ¶ public static

assertStringEqualsStringIgnoringLineEndings(string $expected, string $actual, string $message = ''): void

Asserts that two strings are equal except for line endings.

Parameters
string $expected
string $actual
string $message optional
Returns
void
Throws
ExpectationFailedException

assertStringMatchesFormat() ¶ public static

assertStringMatchesFormat(string $format, string $string, string $message = ''): void

Asserts that a string matches a given format string.

Parameters
string $format
string $string
string $message optional
Returns
void
Throws
ExpectationFailedException

assertStringMatchesFormatFile() ¶ public static

assertStringMatchesFormatFile(string $formatFile, string $string, string $message = ''): void

Asserts that a string matches a given format file.

Parameters
string $formatFile
string $string
string $message optional
Returns
void
Throws
ExpectationFailedException

assertStringNotContainsString() ¶ public static

assertStringNotContainsString(string $needle, string $haystack, string $message = ''): void
Parameters
string $needle
string $haystack
string $message optional
Returns
void
Throws
ExpectationFailedException

assertStringNotContainsStringIgnoringCase() ¶ public static

assertStringNotContainsStringIgnoringCase(string $needle, string $haystack, string $message = ''): void
Parameters
string $needle
string $haystack
string $message optional
Returns
void
Throws
ExpectationFailedException

assertStringNotEqualsFile() ¶ public static

assertStringNotEqualsFile(string $expectedFile, string $actualString, string $message = ''): void

Asserts that the contents of a string is not equal to the contents of a file.

Parameters
string $expectedFile
string $actualString
string $message optional
Returns
void
Throws
ExpectationFailedException

assertStringNotEqualsFileCanonicalizing() ¶ public static

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

Parameters
string $expectedFile
string $actualString
string $message optional
Returns
void
Throws
ExpectationFailedException

assertStringNotEqualsFileIgnoringCase() ¶ public static

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

Parameters
string $expectedFile
string $actualString
string $message optional
Returns
void
Throws
ExpectationFailedException

assertStringNotMatchesFormat() ¶ public static

assertStringNotMatchesFormat(string $format, string $string, string $message = ''): void

Asserts that a string does not match a given format string.

Parameters
string $format
string $string
string $message optional
Returns
void
Throws
ExpectationFailedException

assertStringNotMatchesFormatFile() ¶ public static

assertStringNotMatchesFormatFile(string $formatFile, string $string, string $message = ''): void

Asserts that a string does not match a given format string.

Parameters
string $formatFile
string $string
string $message optional
Returns
void
Throws
ExpectationFailedException

assertStringStartsNotWith() ¶ public static

assertStringStartsNotWith(string $prefix, string $string, string $message = ''): void

Asserts that a string starts not with a given prefix.

Parameters
string $prefix
string $string
string $message optional
Returns
void
Throws
ExpectationFailedException

InvalidArgumentException

assertStringStartsWith() ¶ public static

assertStringStartsWith(string $prefix, string $string, string $message = ''): void

Asserts that a string starts with a given prefix.

Parameters
string $prefix
string $string
string $message optional
Returns
void
Throws
ExpectationFailedException

InvalidArgumentException

assertTextContains() ¶ public

assertTextContains(string $needle, string $haystack, string $message = '', bool $ignoreCase = false): void

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

Parameters
string $needle

The string to search for.

string $haystack

The string to search through.

string $message optional

The message to display on failure.

bool $ignoreCase optional

Whether the search should be case-sensitive.

Returns
void

assertTextEndsNotWith() ¶ public

assertTextEndsNotWith(string $suffix, string $string, string $message = ''): void

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

Parameters
string $suffix

The suffix to not find.

string $string

The string to search.

string $message optional

The message to use for failure.

Returns
void

assertTextEndsWith() ¶ public

assertTextEndsWith(string $suffix, string $string, string $message = ''): void

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

Parameters
string $suffix

The suffix to find.

string $string

The string to search.

string $message optional

The message to use for failure.

Returns
void

assertTextEquals() ¶ public

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

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

Parameters
string $expected

The expected value.

string $result

The actual value.

string $message optional

The message to use for failure.

Returns
void

assertTextNotContains() ¶ public

assertTextNotContains(string $needle, string $haystack, string $message = '', bool $ignoreCase = false): void

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

Parameters
string $needle

The string to search for.

string $haystack

The string to search through.

string $message optional

The message to display on failure.

bool $ignoreCase optional

Whether the search should be case-sensitive.

Returns
void

assertTextNotEquals() ¶ public

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

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

Parameters
string $expected

The expected value.

string $result

The actual value.

string $message optional

The message to use for failure.

Returns
void

assertTextStartsNotWith() ¶ public

assertTextStartsNotWith(string $prefix, string $string, string $message = ''): void

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

Parameters
string $prefix

The prefix to not find.

string $string

The string to search.

string $message optional

The message to use for failure.

Returns
void

assertTextStartsWith() ¶ public

assertTextStartsWith(string $prefix, string $string, string $message = ''): void

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

Parameters
string $prefix

The prefix to check for.

string $string

The string to search in.

string $message optional

The message to use for failure.

Returns
void

assertThat() ¶ public static

assertThat(mixed $value, Constraint $constraint, string $message = ''): void

Evaluates a PHPUnit\Framework\Constraint matcher object.

Parameters
mixed $value
Constraint $constraint
string $message optional
Returns
void
Throws
ExpectationFailedException

assertTrue() ¶ public static

assertTrue(mixed $condition, string $message = ''): void

Asserts that a condition is true.

Parameters
mixed $condition
string $message optional
Returns
void
Throws
ExpectationFailedException

assertWithinRange() ¶ protected static

assertWithinRange(float $expected, float $result, float $margin, string $message = ''): void

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

Parameters
float $expected
float $result
float $margin

the rage of acceptation

string $message optional

the text to display if the assertion is not correct

Returns
void

assertXmlFileEqualsXmlFile() ¶ public static

assertXmlFileEqualsXmlFile(string $expectedFile, string $actualFile, string $message = ''): void

Asserts that two XML files are equal.

Parameters
string $expectedFile
string $actualFile
string $message optional
Returns
void
Throws
Exception

ExpectationFailedException

XmlException

assertXmlFileNotEqualsXmlFile() ¶ public static

assertXmlFileNotEqualsXmlFile(string $expectedFile, string $actualFile, string $message = ''): void

Asserts that two XML files are not equal.

Parameters
string $expectedFile
string $actualFile
string $message optional
Returns
void
Throws
PHPUnit\Util\Exception

ExpectationFailedException

assertXmlStringEqualsXmlFile() ¶ public static

assertXmlStringEqualsXmlFile(string $expectedFile, string $actualXml, string $message = ''): void

Asserts that two XML documents are equal.

Parameters
string $expectedFile
string $actualXml
string $message optional
Returns
void
Throws
ExpectationFailedException

XmlException

assertXmlStringEqualsXmlString() ¶ public static

assertXmlStringEqualsXmlString(string $expectedXml, string $actualXml, string $message = ''): void

Asserts that two XML documents are equal.

Parameters
string $expectedXml
string $actualXml
string $message optional
Returns
void
Throws
ExpectationFailedException

XmlException

assertXmlStringNotEqualsXmlFile() ¶ public static

assertXmlStringNotEqualsXmlFile(string $expectedFile, string $actualXml, string $message = ''): void

Asserts that two XML documents are not equal.

Parameters
string $expectedFile
string $actualXml
string $message optional
Returns
void
Throws
ExpectationFailedException

XmlException

assertXmlStringNotEqualsXmlString() ¶ public static

assertXmlStringNotEqualsXmlString(string $expectedXml, string $actualXml, string $message = ''): void

Asserts that two XML documents are not equal.

Parameters
string $expectedXml
string $actualXml
string $message optional
Returns
void
Throws
ExpectationFailedException

XmlException

atLeast() ¶ public static

atLeast(int $requiredInvocations): InvokedAtLeastCountMatcher

Returns a matcher that matches when the method is executed at least N times.

Parameters
int $requiredInvocations
Returns
InvokedAtLeastCountMatcher

atLeastOnce() ¶ public static

atLeastOnce(): InvokedAtLeastOnceMatcher

Returns a matcher that matches when the method is executed at least once.

Returns
InvokedAtLeastOnceMatcher

atMost() ¶ public static

atMost(int $allowedInvocations): InvokedAtMostCountMatcher

Returns a matcher that matches when the method is executed at most N times.

Parameters
int $allowedInvocations
Returns
InvokedAtMostCountMatcher

callback() ¶ public static

callback(callable $callback): Callback
Parameters
callable $callback
Returns
Callback

captureError() ¶ public

captureError(int $errorLevel, Closure $callable): Cake\Error\PhpError

Capture errors from $callable so that you can do assertions on the error.

If no error is captured an assertion will fail.

Parameters
int $errorLevel

The value of error_reporting() to use.

Closure $callable

A closure to capture errors from.

Returns
Cake\Error\PhpError

clearPlugins() ¶ public

clearPlugins(): void

Clear all plugins from the global plugin collection.

Useful in test case teardown methods.

Returns
void

containsEqual() ¶ public static

containsEqual(mixed $value): TraversableContainsEqual
Parameters
mixed $value
Returns
TraversableContainsEqual

containsIdentical() ¶ public static

containsIdentical(mixed $value): TraversableContainsIdentical
Parameters
mixed $value
Returns
TraversableContainsIdentical

containsOnly() ¶ public static

containsOnly(string $type): TraversableContainsOnly
Parameters
string $type
Returns
TraversableContainsOnly
Throws
Exception

containsOnlyInstancesOf() ¶ public static

containsOnlyInstancesOf(string $className): TraversableContainsOnly
Parameters
string $className
Returns
TraversableContainsOnly
Throws
Exception

count() ¶ public

count(): int
Returns
int

countOf() ¶ public static

countOf(int $count): Count
Parameters
int $count
Returns
Count

createConfiguredMock() ¶ protected

createConfiguredMock(string $originalClassName, array $configuration): MockObject

Creates (and configures) a mock object for the specified interface or class.

Parameters
string $originalClassName
array $configuration
Returns
MockObject
Throws
PHPUnit\Framework\MockObject\Exception

InvalidArgumentException

NoPreviousThrowableException

createConfiguredStub() ¶ protected static

createConfiguredStub(string $originalClassName, array $configuration): Stub

Creates (and configures) a test stub for the specified interface or class.

Parameters
string $originalClassName
array $configuration
Returns
Stub
Throws
PHPUnit\Framework\MockObject\Exception

InvalidArgumentException

NoPreviousThrowableException

createMock() ¶ protected

createMock(string $originalClassName): MockObject

Creates a mock object for the specified interface or class.

Parameters
string $originalClassName
Returns
MockObject
Throws
PHPUnit\Framework\MockObject\Exception

InvalidArgumentException

NoPreviousThrowableException

createMockForIntersectionOfInterfaces() ¶ protected

createMockForIntersectionOfInterfaces(array $interfaces): MockObject
Parameters
array $interfaces
Returns
MockObject
Throws
PHPUnit\Framework\MockObject\Exception

createPartialMock() ¶ protected

createPartialMock(string $originalClassName, array $methods): MockObject

Creates a partial mock object for the specified interface or class.

Parameters
string $originalClassName
array $methods
Returns
MockObject
Throws
PHPUnit\Framework\MockObject\Exception

InvalidArgumentException

createStub() ¶ protected static

createStub(string $originalClassName): Stub

Creates a test stub for the specified interface or class.

Parameters
string $originalClassName
Returns
Stub
Throws
PHPUnit\Framework\MockObject\Exception

InvalidArgumentException

NoPreviousThrowableException

createStubForIntersectionOfInterfaces() ¶ protected static

createStubForIntersectionOfInterfaces(array $interfaces): Stub
Parameters
array $interfaces
Returns
Stub
Throws
PHPUnit\Framework\MockObject\Exception

createTestProxy() ¶ protected

createTestProxy(string $originalClassName, array $constructorArguments = []): MockObject

Creates a test proxy for the specified class.

Parameters
string $originalClassName
array $constructorArguments optional
Returns
MockObject
Throws
PHPUnit\Framework\MockObject\Exception

InvalidArgumentException

dataName() ¶ public

dataName(): int|string
Returns
int|string

dataSetAsString() ¶ public

dataSetAsString(): string
Returns
string

dataSetAsStringWithData() ¶ public

dataSetAsStringWithData(): string
Returns
string

dependencyInput() ¶ public

dependencyInput(): array
Returns
array

deprecated() ¶ public

deprecated(Closure $callable): void

Helper method for check deprecation methods

Parameters
Closure $callable

callable function that will receive asserts

Returns
void

directoryExists() ¶ public static

directoryExists(): DirectoryExists
Returns
DirectoryExists

doesNotPerformAssertions() ¶ public

doesNotPerformAssertions(): bool
Returns
bool

equalTo() ¶ public static

equalTo(mixed $value): IsEqual
Parameters
mixed $value
Returns
IsEqual

equalToCanonicalizing() ¶ public static

equalToCanonicalizing(mixed $value): IsEqualCanonicalizing
Parameters
mixed $value
Returns
IsEqualCanonicalizing

equalToIgnoringCase() ¶ public static

equalToIgnoringCase(mixed $value): IsEqualIgnoringCase
Parameters
mixed $value
Returns
IsEqualIgnoringCase

equalToWithDelta() ¶ public static

equalToWithDelta(mixed $value, float $delta): IsEqualWithDelta
Parameters
mixed $value
float $delta
Returns
IsEqualWithDelta

exactly() ¶ public static

exactly(int $count): InvokedCountMatcher

Returns a matcher that matches when the method is executed exactly $count times.

Parameters
int $count
Returns
InvokedCountMatcher

expectDeprecationMessageMatches() ¶ public

expectDeprecationMessageMatches(string $regex, Closure $callable): void
Parameters
string $regex

A regex to match against the deprecation message

Closure $callable

Callable which should trigger the warning

Returns
void
Throws
Exception

expectErrorHandlerMessageMatches() ¶ protected

expectErrorHandlerMessageMatches(string $regex, Closure $callable, int $errorLevel): void
Parameters
string $regex

A regex to match against the warning message

Closure $callable

Callable which should trigger the warning

int $errorLevel

The error level to listen to

Returns
void
Throws
Exception

expectErrorMessageMatches() ¶ public

expectErrorMessageMatches(string $regex, Closure $callable): void
Parameters
string $regex

A regex to match against the error message

Closure $callable

Callable which should trigger the warning

Returns
void
Throws
Exception

expectException() ¶ public

expectException(string $exception): void
Parameters
string $exception
Returns
void

expectExceptionCode() ¶ public

expectExceptionCode(int|string $code): void
Parameters
int|string $code
Returns
void

expectExceptionMessage() ¶ public

expectExceptionMessage(string $message): void
Parameters
string $message
Returns
void

expectExceptionMessageMatches() ¶ public

expectExceptionMessageMatches(string $regularExpression): void
Parameters
string $regularExpression
Returns
void

expectExceptionObject() ¶ public

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.

Parameters
Exception $exception
Returns
void

expectNotToPerformAssertions() ¶ public

expectNotToPerformAssertions(): void
Returns
void

expectNoticeMessageMatches() ¶ public

expectNoticeMessageMatches(string $regex, Closure $callable): void
Parameters
string $regex

A regex to match against the warning message

Closure $callable

Callable which should trigger the warning

Returns
void
Throws
Exception

expectOutputRegex() ¶ public

expectOutputRegex(string $expectedRegex): void
Parameters
string $expectedRegex
Returns
void

expectOutputString() ¶ public

expectOutputString(string $expectedString): void
Parameters
string $expectedString
Returns
void

expectWarningMessageMatches() ¶ public

expectWarningMessageMatches(string $regex, Closure $callable): void
Parameters
string $regex

A regex to match against the warning message

Closure $callable

Callable which should trigger the warning

Returns
void
Throws
Exception

expectsOutput() ¶ public

expectsOutput(): bool
Returns
bool

fail() ¶ public static

fail(string $message = ''): never

Fails a test with the given message.

Parameters
string $message optional
Returns
never
Throws
AssertionFailedError

fetchTable() ¶ public

fetchTable(string|null $alias = null, array<string, mixed> $options = []): Cake\ORM\Table

Convenience method to get a table instance.

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

Returns
Cake\ORM\Table
Throws
Cake\Core\Exception\CakeException
If `$alias` argument and `$defaultTable` property both are `null`.
See Also
\Cake\ORM\TableLocator::get()

fileExists() ¶ public static

fileExists(): FileExists
Returns
FileExists

getActualOutputForAssertion() ¶ public

getActualOutputForAssertion(): string
Returns
string

getCount() ¶ public static

getCount(): int

Return the current assertion count.

Returns
int

getFixtureStrategy() ¶ protected

getFixtureStrategy(): Cake\TestSuite\Fixture\FixtureStrategyInterface

Returns fixture strategy used by these tests.

Returns
Cake\TestSuite\Fixture\FixtureStrategyInterface

getFixtures() ¶ public

getFixtures(): array<string>

Get the fixtures this test should use.

Returns
array<string>

getMockBuilder() ¶ public

getMockBuilder(string $className): MockBuilder

Returns a builder object to create mock objects using a fluent interface.

Parameters
string $className
Returns
MockBuilder

getMockForAbstractClass() ¶ protected

getMockForAbstractClass(string $originalClassName, array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, array $mockedMethods = [], bool $cloneArguments = false): MockObject

Creates a mock object for the specified abstract class with all abstract methods of the class mocked. Concrete methods are not mocked by default. To mock concrete methods, use the 7th parameter ($mockedMethods).

Parameters
string $originalClassName
array $arguments optional
string $mockClassName optional
bool $callOriginalConstructor optional
bool $callOriginalClone optional
bool $callAutoload optional
array $mockedMethods optional
bool $cloneArguments optional
Returns
MockObject
Throws
PHPUnit\Framework\MockObject\Exception

InvalidArgumentException

getMockForModel() ¶ public

getMockForModel(string $alias, list<string> $methods = [], array<string, mixed> $options = []): Cake\ORM\Table|PHPUnit\Framework\MockObject\MockObject

Mock a model, maintain fixtures and table association

Parameters
string $alias

The model to get a mock for.

list<string> $methods optional

The list of methods to mock

array<string, mixed> $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(string $traitName, array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, array $mockedMethods = [], bool $cloneArguments = false): MockObject

Creates a mock object for the specified trait with all abstract methods of the trait mocked. Concrete methods to mock can be specified with the $mockedMethods parameter.

Parameters
string $traitName
array $arguments optional
string $mockClassName optional
bool $callOriginalConstructor optional
bool $callOriginalClone optional
bool $callAutoload optional
array $mockedMethods optional
bool $cloneArguments optional
Returns
MockObject
Throws
PHPUnit\Framework\MockObject\Exception

InvalidArgumentException

getMockFromWsdl() ¶ protected

getMockFromWsdl(string $wsdlFile, string $originalClassName = '', string $mockClassName = '', array $methods = [], bool $callOriginalConstructor = true, array $options = []): MockObject

Creates 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
Returns
MockObject
Throws
PHPUnit\Framework\MockObject\Exception

getObjectForTrait() ¶ protected

getObjectForTrait(string $traitName, array $arguments = [], string $traitClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true): object

Creates an object that uses 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\MockObject\Exception

getTableLocator() ¶ public

getTableLocator(): Cake\ORM\Locator\LocatorInterface

Gets the table locator.

Returns
Cake\ORM\Locator\LocatorInterface

greaterThan() ¶ public static

greaterThan(mixed $value): GreaterThan
Parameters
mixed $value
Returns
GreaterThan

greaterThanOrEqual() ¶ public static

greaterThanOrEqual(mixed $value): LogicalOr
Parameters
mixed $value
Returns
LogicalOr

groups() ¶ public

groups(): array
Returns
array

hasDependencyInput() ¶ public

hasDependencyInput(): bool
Returns
bool

hasUnexpectedOutput() ¶ public

hasUnexpectedOutput(): bool
Returns
bool

identicalTo() ¶ public static

identicalTo(mixed $value): IsIdentical
Parameters
mixed $value
Returns
IsIdentical

iniSet() ¶ protected

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.

Parameters
string $varName
string $newValue
Returns
void
Throws
Exception

isEmpty() ¶ public static

isEmpty(): IsEmpty
Returns
IsEmpty

isFalse() ¶ public static

isFalse(): IsFalse
Returns
IsFalse

isFinite() ¶ public static

isFinite(): IsFinite
Returns
IsFinite

isInIsolation() ¶ public

isInIsolation(): bool
Returns
bool

isInfinite() ¶ public static

isInfinite(): IsInfinite
Returns
IsInfinite

isInstanceOf() ¶ public static

isInstanceOf(string $className): IsInstanceOf
Parameters
string $className
Returns
IsInstanceOf
Throws
UnknownClassOrInterfaceException

isJson() ¶ public static

isJson(): IsJson
Returns
IsJson

isList() ¶ public static

isList(): IsList
Returns
IsList

isNan() ¶ public static

isNan(): IsNan
Returns
IsNan

isNull() ¶ public static

isNull(): IsNull
Returns
IsNull

isReadable() ¶ public static

isReadable(): IsReadable
Returns
IsReadable

isTrue() ¶ public static

isTrue(): IsTrue
Returns
IsTrue

isType() ¶ public static

isType(string $type): IsType
Parameters
string $type
Returns
IsType
Throws
Exception

isWritable() ¶ public static

isWritable(): IsWritable
Returns
IsWritable

lessThan() ¶ public static

lessThan(mixed $value): LessThan
Parameters
mixed $value
Returns
LessThan

lessThanOrEqual() ¶ public static

lessThanOrEqual(mixed $value): LogicalOr
Parameters
mixed $value
Returns
LogicalOr

loadPlugins() ¶ public

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.

Parameters
array<string, mixed> $plugins optional

List of Plugins to load.

Returns
Cake\Http\BaseApplication

loadRoutes() ¶ public

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.

Parameters
array|null $appArgs optional

Constructor parameters for the application class.

Returns
void

logicalAnd() ¶ public static

logicalAnd(mixed ...$constraints): LogicalAnd
Parameters
mixed ...$constraints
Returns
LogicalAnd
Throws
Exception

logicalNot() ¶ public static

logicalNot(Constraint $constraint): LogicalNot
Parameters
Constraint $constraint
Returns
LogicalNot

logicalOr() ¶ public static

logicalOr(mixed ...$constraints): LogicalOr
Parameters
mixed ...$constraints
Returns
LogicalOr

logicalXor() ¶ public static

logicalXor(mixed ...$constraints): LogicalXor
Parameters
mixed ...$constraints
Returns
LogicalXor

markTestIncomplete() ¶ public static

markTestIncomplete(string $message = ''): never

Mark the test as incomplete.

Parameters
string $message optional
Returns
never
Throws
IncompleteTestError

markTestSkipped() ¶ public static

markTestSkipped(string $message = ''): never

Mark the test as skipped.

Parameters
string $message optional
Returns
never
Throws
SkippedWithMessageException

matches() ¶ public static

matches(string $string): StringMatchesFormatDescription
Parameters
string $string
Returns
StringMatchesFormatDescription

matchesRegularExpression() ¶ public static

matchesRegularExpression(string $pattern): RegularExpression
Parameters
string $pattern
Returns
RegularExpression

name() ¶ public

name(): string
Returns
string

nameWithDataSet() ¶ public

nameWithDataSet(): string
Returns
string

never() ¶ public static

never(): InvokedCountMatcher

Returns a matcher that matches when the method is never executed.

Returns
InvokedCountMatcher

numberOfAssertionsPerformed() ¶ public

numberOfAssertionsPerformed(): int
Returns
int

objectEquals() ¶ public static

objectEquals(object $object, string $method = 'equals'): ObjectEquals
Parameters
object $object
string $method optional
Returns
ObjectEquals

onConsecutiveCalls() ¶ public static

onConsecutiveCalls(mixed ...$arguments): ConsecutiveCallsStub
Parameters
mixed ...$arguments
Returns
ConsecutiveCallsStub
See Also
https://github.com/sebastianbergmann/phpunit/issues/5423
https://github.com/sebastianbergmann/phpunit/issues/5425

onNotSuccessfulTest() ¶ protected

onNotSuccessfulTest(Throwable $t): never

This method is called when a test method did not execute successfully.

Parameters
Throwable $t
Returns
never
Throws
Throwable

once() ¶ public static

once(): InvokedCountMatcher

Returns a matcher that matches when the method is executed exactly once.

Returns
InvokedCountMatcher

output() ¶ public

output(): string
Returns
string

providedData() ¶ public

providedData(): array
Returns
array

provides() ¶ public

provides(): array
Returns
array

registerComparator() ¶ protected

registerComparator(Comparator $comparator): void
Parameters
Comparator $comparator
Returns
void

registerFailureType() ¶ protected

registerFailureType(string $classOrInterface): void
Parameters
string $classOrInterface
Returns
void

registerMockObject() ¶ public

registerMockObject(MockObject $mockObject): void
Parameters
MockObject $mockObject
Returns
void

registerMockObjectsFromTestArgumentsRecursively() ¶ public

registerMockObjectsFromTestArgumentsRecursively(): void
Returns
void

removePlugins() ¶ public

removePlugins(list<string> $names = []): void

Remove plugins from the global plugin collection.

Useful in test case teardown methods.

Parameters
list<string> $names optional

A list of plugins you want to remove.

Returns
void

requires() ¶ public

requires(): array
Returns
array

resetCount() ¶ public static

resetCount(): void

Reset the assertion counter.

Returns
void

result() ¶ public

result(): mixed
Returns
mixed

returnArgument() ¶ public static

returnArgument(int $argumentIndex): ReturnArgumentStub
Parameters
int $argumentIndex
Returns
ReturnArgumentStub
See Also
https://github.com/sebastianbergmann/phpunit/issues/5423

returnCallback() ¶ public static

returnCallback(callable $callback): ReturnCallbackStub
Parameters
callable $callback
Returns
ReturnCallbackStub
See Also
https://github.com/sebastianbergmann/phpunit/issues/5423

returnSelf() ¶ public static

returnSelf(): ReturnSelfStub
Returns
ReturnSelfStub
See Also
https://github.com/sebastianbergmann/phpunit/issues/5423

returnValue() ¶ public static

returnValue(mixed $value): ReturnStub
Parameters
mixed $value
Returns
ReturnStub
See Also
https://github.com/sebastianbergmann/phpunit/issues/5423

returnValueMap() ¶ public static

returnValueMap(array $valueMap): ReturnValueMapStub
Parameters
array $valueMap
Returns
ReturnValueMapStub
See Also
https://github.com/sebastianbergmann/phpunit/issues/5423

run() ¶ public

run(): void
Returns
void
Throws
PHPUnit\Runner\Exception

PHPUnit\Util\Exception

SebastianBergmann\CodeCoverage\InvalidArgumentException

SebastianBergmann\Template\InvalidArgumentException

CodeCoverageException

Exception

MoreThanOneDataSetFromDataProviderException

NoDataSetFromDataProviderException

NoPreviousThrowableException

ProcessIsolationException

StaticAnalysisCacheNotConfiguredException

UnintentionallyCoveredCodeException

runBare() ¶ public

runBare(): void
Returns
void
Throws
Throwable

runTest() ¶ protected

runTest(): mixed
Returns
mixed
Throws
AssertionFailedError

Exception

ExpectationFailedException

Throwable

setAppNamespace() ¶ public static

setAppNamespace(string $appNamespace = 'TestApp'): string|null

Set the app namespace

Parameters
string $appNamespace optional

The app namespace, defaults to "TestApp".

Returns
string|null

setBackupGlobals() ¶ public

setBackupGlobals(bool $backupGlobals): void
Parameters
bool $backupGlobals
Returns
void

setBackupGlobalsExcludeList() ¶ public

setBackupGlobalsExcludeList(array $backupGlobalsExcludeList): void
Parameters
array $backupGlobalsExcludeList
Returns
void

setBackupStaticProperties() ¶ public

setBackupStaticProperties(bool $backupStaticProperties): void
Parameters
bool $backupStaticProperties
Returns
void

setBackupStaticPropertiesExcludeList() ¶ public

setBackupStaticPropertiesExcludeList(array $backupStaticPropertiesExcludeList): void
Parameters
array $backupStaticPropertiesExcludeList
Returns
void

setData() ¶ public

setData(int|string $dataName, array $data): void
Parameters
int|string $dataName
array $data
Returns
void

setDependencies() ¶ public

setDependencies(array $dependencies): void
Parameters
array $dependencies
Returns
void

setDependencyInput() ¶ public

setDependencyInput(array $dependencyInput): void
Parameters
array $dependencyInput
Returns
void

setGroups() ¶ public

setGroups(array $groups): void
Parameters
array $groups
Returns
void

setInIsolation() ¶ public

setInIsolation(bool $inIsolation): void
Parameters
bool $inIsolation
Returns
void

setLocale() ¶ protected

setLocale(mixed ...$arguments): void

This method is a wrapper for the setlocale() function that automatically resets the locale to its original value after the test is run.

Parameters
mixed ...$arguments
Returns
void
Throws
Exception

setName() ¶ public

setName(string $name): void
Parameters
string $name
Returns
void

setPreserveGlobalState() ¶ public

setPreserveGlobalState(bool $preserveGlobalState): void
Parameters
bool $preserveGlobalState
Returns
void

setResult() ¶ public

setResult(mixed $result): void
Parameters
mixed $result
Returns
void

setRunClassInSeparateProcess() ¶ public

setRunClassInSeparateProcess(bool $runClassInSeparateProcess): void
Parameters
bool $runClassInSeparateProcess
Returns
void

setRunTestInSeparateProcess() ¶ public

setRunTestInSeparateProcess(bool $runTestInSeparateProcess): void
Parameters
bool $runTestInSeparateProcess
Returns
void

setTableLocator() ¶ public

setTableLocator(Cake\ORM\Locator\LocatorInterface $tableLocator): $this

Sets the table locator.

Parameters
Cake\ORM\Locator\LocatorInterface $tableLocator

LocatorInterface instance.

Returns
$this

setUp() ¶ protected

setUp(): void

Setup the test case, backup the static object values so they can be restored. Specifically backs up the contents of Configure and paths in App if they have not already been backed up.

Returns
void

setUpBeforeClass() ¶ public static

setUpBeforeClass(): void

This method is called before the first test of this test class is run.

Returns
void

setupFixtures() ¶ protected

setupFixtures(): void

Initialized and loads any use fixtures.

Returns
void

size() ¶ public

size(): TestSize
Returns
TestSize

skipIf() ¶ public

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

Overrides SimpleTestCase::skipIf to provide a boolean return value

Parameters
bool $shouldSkip

Whether the test should be skipped.

string $message optional

The message to display.

Returns
bool

skipUnless() ¶ protected

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

Compatibility function for skipping.

Parameters
bool $condition

Condition to trigger skipping

string $message optional

Message for skip

Returns
bool

sortId() ¶ public

sortId(): string
Returns
string

status() ¶ public

status(): TestStatus
Returns
TestStatus

stringContains() ¶ public static

stringContains(string $string, bool $case = true): StringContains
Parameters
string $string
bool $case optional
Returns
StringContains

stringEndsWith() ¶ public static

stringEndsWith(string $suffix): StringEndsWith
Parameters
string $suffix
Returns
StringEndsWith
Throws
InvalidArgumentException

stringEqualsStringIgnoringLineEndings() ¶ public static

stringEqualsStringIgnoringLineEndings(string $string): StringEqualsStringIgnoringLineEndings
Parameters
string $string
Returns
StringEqualsStringIgnoringLineEndings

stringStartsWith() ¶ public static

stringStartsWith(string $prefix): StringStartsWith
Parameters
string $prefix
Returns
StringStartsWith
Throws
InvalidArgumentException

tearDown() ¶ protected

tearDown(): void

teardown any static object changes and restore them.

Returns
void

tearDownAfterClass() ¶ public static

tearDownAfterClass(): void

This method is called after the last test of this test class is run.

Returns
void

teardownFixtures() ¶ protected

teardownFixtures(): void

Unloads any use fixtures.

Returns
void

throwException() ¶ public static

throwException(Throwable $exception): ExceptionStub
Parameters
Throwable $exception
Returns
ExceptionStub

toString() ¶ public

toString(): string

Returns a string representation of the test case.

Returns
string
Throws
Exception

transformException() ¶ protected

transformException(Throwable $t): Throwable
Parameters
Throwable $t
Returns
Throwable

usesDataProvider() ¶ public

usesDataProvider(): bool
Returns
bool

valueObjectForEvents() ¶ public

valueObjectForEvents(): Event\Code\TestMethod
Returns
Event\Code\TestMethod
Throws
MoreThanOneDataSetFromDataProviderException

wasPrepared() ¶ public

wasPrepared(): bool
Returns
bool

withConsecutive() ¶ public static

withConsecutive(array $firstCallArguments, array ...$consecutiveCallsArguments): iterable
Parameters
array $firstCallArguments

The call arguments

array ...$consecutiveCallsArguments

Additional arguments

Returns
iterable

withErrorReporting() ¶ public

withErrorReporting(int $errorLevel, callable $callable): void

Helper method for tests that needs to use error_reporting()

Parameters
int $errorLevel

value of error_reporting() that needs to use

callable $callable

callable function that will receive asserts

Returns
void

Property Detail

$_configure ¶ protected

Configure values to restore at end of test.

Type
array

$_tableLocator ¶ protected

Table locator instance

Type
Cake\ORM\Locator\LocatorInterface|null

$defaultTable ¶ protected

This object's default table alias.

Type
string|null

$fixtureStrategy ¶ protected

Type
Cake\TestSuite\Fixture\FixtureStrategyInterface|null

$fixtures ¶ protected

Fixtures used by this test case.

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

Generated using CakePHP API Docs