A test case class intended to make integration tests of cake console commands easier.
_configure, _pathRestore, autoFixtures, dropTables, fixtureManager _tableLocator _err, _exitCode, _in, _out, _useCommandRunner _assertAttributes( array $assertions , string $string , boolean $fullDebug = false , array|string $regex = '' )
Check the attributes as part of an assertTags() check.
$assertions $string $fullDebug optional false $regex optional '' assertHtml
_getTableClassName( string $alias , array $options )
Gets the class name for the table.
$alias $options Cake\ORM\Exception\MissingTableClassException_normalizePath( string $path )
Normalize a path for comparison.
$path assertEventFired( string $name , Cake\Event\EventManager|null $eventManager = null , string $message = '' )
Asserts that a global event was fired. You must track events in your event manager for this assertion to work
$name Cake\Event\EventManager|null $eventManager optional null $message optional '' assertEventFiredWith( string $name , string $dataKey , string $dataValue , Cake\Event\EventManager|null $eventManager = null , string $message = '' )
Asserts an event was fired with data
If a third argument is passed, that value is used to compare with the value in $dataKey
$name $dataKey $dataValue Cake\Event\EventManager|null $eventManager optional null $message optional '' assertHtml( array $expected , string $string , boolean $fullDebug = false )
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.
$expected $string $fullDebug optional false assertNotWithinRange( float $expected , float $result , float $margin , string $message = '' )
Compatibility function to test if a value is not between an acceptable range.
$expected $result $margin $message optional '' assertPathEquals( string $expected , string $result , string $message = '' )
Compatibility function to test paths.
$expected $result $message optional '' assertTags( string $string , array $expected , boolean $fullDebug = false )
Asserts HTML tags.
$string $expected $fullDebug optional false assertTextContains( string $needle , string $haystack , string $message = '' , boolean $ignoreCase = false )
Assert that a string contains another string, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
$needle $haystack $message optional '' $ignoreCase optional false assertTextEndsNotWith( string $suffix , string $string , string $message = '' )
Asserts that a string ends not with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
$suffix $string $message optional '' assertTextEndsWith( string $suffix , string $string , string $message = '' )
Asserts that a string ends with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
$suffix $string $message optional '' assertTextEquals( string $expected , string $result , string $message = '' )
Assert text equality, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
$expected $result $message optional '' assertTextNotContains( string $needle , string $haystack , string $message = '' , boolean $ignoreCase = false )
Assert that a text doesn't contain another text, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
$needle $haystack $message optional '' $ignoreCase optional false assertTextNotEquals( string $expected , string $result , string $message = '' )
Assert text equality, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
$expected $result $message optional '' assertTextStartsNotWith( string $prefix , string $string , string $message = '' )
Asserts that a string starts not with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
$prefix $string $message optional '' assertTextStartsWith( string $prefix , string $string , string $message = '' )
Asserts that a string starts with a given prefix, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
$prefix $string $message optional '' assertWithinRange( float $expected , float $result , float $margin , string $message = '' )
Compatibility function to test if a value is between an acceptable range.
$expected $result $margin $message optional '' clearPlugins( )
Clear all plugins from the global plugin collection.
Useful in test case teardown methods.
deprecated( callable $callable )
Helper method for check deprecation methods
$callable getMockForModel( string $alias , array|null $methods = [] , array $options = [] )
Mock a model, maintain fixtures and table association
$alias $methods optional [] $options optional [] Cake\ORM\Table|PHPUnit_Framework_MockObject_MockObjectCake\ORM\Exception\MissingTableClassExceptionloadFixtures( )
Chooses which fixtures to load for a given test
Each parameter is a model name that corresponds to a fixture, i.e. 'Posts', 'Authors', etc. Passing no parameters will cause all fixtures on the test case to load.
loadPlugins( array $plugins = [] )
Load plugins into a simulated application.
Useful to test how plugins being loaded/not loaded interact with other elements in CakePHP or applications.
$plugins optional [] Cake\Http\BaseApplicationremovePlugins( array $plugins = [] )
Remove plugins from the global plugin collection.
Useful in test case teardown methods.
$plugins optional [] setAppNamespace( string $appNamespace = 'TestApp' )
Set the app namespace
$appNamespace optional 'TestApp' setUp( )
Setup the test case, backup the static object values so they can be restored. Specifically backs up the contents of Configure and paths in App if they have not already been backed up.
skipIf( boolean $shouldSkip , string $message = '' )
Overrides SimpleTestCase::skipIf to provide a boolean return value
$shouldSkip $message optional '' skipUnless( boolean $condition , string $message = '' )
Compatibility function for skipping.
$condition $message optional '' withErrorReporting( integer $errorLevel , callable $callable )
Helper method for tests that needs to use error_reporting()
$errorLevel $callable assertErrorContains( string $expected , string $message = '' )
Asserts stderr contains expected output
$expected $message optional '' assertErrorEmpty( string $message = '' )
Asserts that stderr is empty
$message optional '' assertErrorRegExp( string $pattern , string $message = '' )
Asserts stderr contains expected regexp
$pattern $message optional '' assertExitCode( integer $expected , string $message = '' )
Asserts shell exited with the expected code
$expected $message optional '' assertExitError( string $message = '' )
Asserts shell exited with Command::CODE_ERROR
$message optional '' assertExitSuccess( string $message = '' )
Asserts shell exited with the Command::CODE_SUCCESS
$message optional '' assertOutputContains( string $expected , string $message = '' )
Asserts stdout contains expected output
$expected $message optional '' assertOutputContainsRow( array $row , string $message = '' )
Check that a row of cells exists in the output.
$row $message optional '' assertOutputEmpty( string $message = '' )
Asserts that stdout is empty
$message optional '' assertOutputNotContains( string $expected , string $message = '' )
Asserts stdout does not contain expected output
$expected $message optional '' assertOutputRegExp( string $pattern , string $message = '' )
Asserts stdout contains expected regexp
$pattern $message optional '' cleanupConsoleTrait( )
Cleans state to get ready for the next test
commandStringToArgs( string $command )
Creates an $argv array from a command string
$command exec( string $command , array $input = [] )
Runs cli integration test
$command $input optional [] makeRunner( )
Builds the appropriate command dispatcher
Cake\Console\CommandRunner|Cake\TestSuite\LegacyCommandRunneruseCommandRunner( )
Set this test case to use the CommandRunner rather than the legacy ShellDispatcher
getTableLocator( )
Gets the table locator.
Cake\ORM\Locator\LocatorInterfacesetTableLocator( Cake\ORM\Locator\LocatorInterface $tableLocator )
Sets the table locator.
Cake\ORM\Locator\LocatorInterface $tableLocator tableLocator( Cake\ORM\Locator\LocatorInterface $tableLocator = null )
Sets the table locator. If no parameters are passed, it will return the currently used locator.
Cake\ORM\Locator\LocatorInterface $tableLocator optional null Cake\ORM\Locator\LocatorInterface
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.8/class-Cake.TestSuite.ConsoleIntegrationTestCase.html