On this page
Class ConsoleIntegrationTestCase
A test case class intended to make integration tests of cake console commands easier.
- PHPUnit\Framework\TestCase
Cake\TestSuite\TestCase uses Cake\ORM\Locator\LocatorAwareTrait
Cake\TestSuite\ConsoleIntegrationTestCase uses Cake\TestSuite\ConsoleIntegrationTestTrait
Namespace: Cake\TestSuite
Deprecated: 3.7.0 Use Cake\TestSuite\ConsoleIntegrationTestTrait instead
Location: TestSuite/ConsoleIntegrationTestCase.php
Inherited Properties
_configure,_pathRestore,autoFixtures,dropTables,fixtureManager_tableLocator_err,_exitCode,_in,_out,_useCommandRunner
Methods inherited from Cake\TestSuite\TestCase
_assertAttributes()source protected
_assertAttributes( array $assertions , string $string , boolean $fullDebug = false , array|string $regex = '' )
Check the attributes as part of an assertTags() check.
Parameters
-
array
$assertions - Assertions to run.
-
string
$string - The HTML string to check.
-
boolean
$fullDebugoptional false - Whether or not more verbose output should be used.
-
array|string
$regexoptional '' -
Full regexp from
assertHtml
Returns
string|boolean_getTableClassName()source protected
_getTableClassName( string $alias , array $options )
Gets the class name for the table.
Parameters
-
string
$alias - The model to get a mock for.
-
array
$options - The config data for the mock's constructor.
Returns
stringThrows
Cake\ORM\Exception\MissingTableClassException_normalizePath()source protected
_normalizePath( string $path )
Normalize a path for comparison.
Parameters
-
string
$path - Path separated by "/" slash.
Returns
stringNormalized path separated by DIRECTORY_SEPARATOR.
assertEventFired()source public
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
Parameters
-
string
$name - Event name
Cake\Event\EventManager|null$eventManageroptional null- Event manager to check, defaults to global event manager
-
string
$messageoptional '' - Assertion failure message
assertEventFiredWith()source public
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
Parameters
-
string
$name - Event name
-
string
$dataKey - Data key
-
string
$dataValue - Data value
Cake\Event\EventManager|null$eventManageroptional null- Event manager to check, defaults to global event manager
-
string
$messageoptional '' - Assertion failure message
assertHtml()source public
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.
Parameters
-
array
$expected - An array, see above
-
string
$string - An HTML/XHTML/XML string
-
boolean
$fullDebugoptional false - Whether or not more verbose output should be used.
Returns
booleanassertNotWithinRange()source protected static
assertNotWithinRange( float $expected , float $result , float $margin , string $message = '' )
Compatibility function to test if a value is not between an acceptable range.
Parameters
-
float
$expected -
float
$result -
float
$margin - the rage of acceptation
-
string
$messageoptional '' - the text to display if the assertion is not correct
assertPathEquals()source protected static
assertPathEquals( string $expected , string $result , string $message = '' )
Compatibility function to test paths.
Parameters
-
string
$expected -
string
$result -
string
$messageoptional '' - the text to display if the assertion is not correct
assertTags()source public deprecated
assertTags( string $string , array $expected , boolean $fullDebug = false )
Asserts HTML tags.
Parameters
-
string
$string - An HTML/XHTML/XML string
-
array
$expected - An array, see above
-
boolean
$fullDebugoptional false - Whether or not more verbose output should be used.
assertTextContains()source public
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.
Parameters
-
string
$needle - The string to search for.
-
string
$haystack - The string to search through.
-
string
$messageoptional '' - The message to display on failure.
-
boolean
$ignoreCaseoptional false - Whether or not the search should be case-sensitive.
assertTextEndsNotWith()source public
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.
Parameters
-
string
$suffix - The suffix to not find.
-
string
$string - The string to search.
-
string
$messageoptional '' - The message to use for failure.
assertTextEndsWith()source public
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.
Parameters
-
string
$suffix - The suffix to find.
-
string
$string - The string to search.
-
string
$messageoptional '' - The message to use for failure.
assertTextEquals()source public
assertTextEquals( string $expected , string $result , string $message = '' )
Assert text equality, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Parameters
-
string
$expected - The expected value.
-
string
$result - The actual value.
-
string
$messageoptional '' - The message to use for failure.
assertTextNotContains()source public
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.
Parameters
-
string
$needle - The string to search for.
-
string
$haystack - The string to search through.
-
string
$messageoptional '' - The message to display on failure.
-
boolean
$ignoreCaseoptional false - Whether or not the search should be case-sensitive.
assertTextNotEquals()source public
assertTextNotEquals( string $expected , string $result , string $message = '' )
Assert text equality, ignoring differences in newlines. Helpful for doing cross platform tests of blocks of text.
Parameters
-
string
$expected - The expected value.
-
string
$result - The actual value.
-
string
$messageoptional '' - The message to use for failure.
assertTextStartsNotWith()source public
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.
Parameters
-
string
$prefix - The prefix to not find.
-
string
$string - The string to search.
-
string
$messageoptional '' - The message to use for failure.
assertTextStartsWith()source public
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.
Parameters
-
string
$prefix - The prefix to check for.
-
string
$string - The string to search in.
-
string
$messageoptional '' - The message to use for failure.
assertWithinRange()source protected static
assertWithinRange( float $expected , float $result , float $margin , string $message = '' )
Compatibility function to test if a value is between an acceptable range.
Parameters
-
float
$expected -
float
$result -
float
$margin - the rage of acceptation
-
string
$messageoptional '' - the text to display if the assertion is not correct
clearPlugins()source public
clearPlugins( )
Clear all plugins from the global plugin collection.
Useful in test case teardown methods.
deprecated()source public
deprecated( callable $callable )
Helper method for check deprecation methods
Parameters
-
callable
$callable - callable function that will receive asserts
getMockForModel()source public
getMockForModel( string $alias , array|null $methods = [] , array $options = [] )
Mock a model, maintain fixtures and table association
Parameters
-
string
$alias - The model to get a mock for.
-
array|null
$methodsoptional [] - The list of methods to mock
-
array
$optionsoptional [] - The config data for the mock's constructor.
Returns
Cake\ORM\Table|PHPUnit_Framework_MockObject_MockObjectThrows
Cake\ORM\Exception\MissingTableClassExceptionloadFixtures()source public
loadFixtures( )
Chooses which fixtures to load for a given test
Each parameter is a model name that corresponds to a fixture, i.e. 'Posts', 'Authors', etc. Passing no parameters will cause all fixtures on the test case to load.
Throws
Exceptionwhen no fixture manager is available.
See
\Cake\TestSuite\TestCase::$autoFixturesloadPlugins()source public
loadPlugins( array $plugins = [] )
Load plugins into a simulated application.
Useful to test how plugins being loaded/not loaded interact with other elements in CakePHP or applications.
Parameters
-
array
$pluginsoptional [] - List of Plugins to load.
Returns
Cake\Http\BaseApplicationremovePlugins()source public
removePlugins( array $plugins = [] )
Remove plugins from the global plugin collection.
Useful in test case teardown methods.
Parameters
-
array
$pluginsoptional [] - A list of plugins you want to remove.
setAppNamespace()source public static
setAppNamespace( string $appNamespace = 'TestApp' )
Set the app namespace
Parameters
-
string
$appNamespaceoptional 'TestApp' - The app namespace, defaults to "TestApp".
setUp()source public
setUp( )
Setup the test case, backup the static object values so they can be restored. Specifically backs up the contents of Configure and paths in App if they have not already been backed up.
skipIf()source public
skipIf( boolean $shouldSkip , string $message = '' )
Overrides SimpleTestCase::skipIf to provide a boolean return value
Parameters
-
boolean
$shouldSkip - Whether or not the test should be skipped.
-
string
$messageoptional '' - The message to display.
Returns
booleanskipUnless()source protected
skipUnless( boolean $condition , string $message = '' )
Compatibility function for skipping.
Parameters
-
boolean
$condition - Condition to trigger skipping
-
string
$messageoptional '' - Message for skip
Returns
booleanwithErrorReporting()source public
withErrorReporting( integer $errorLevel , callable $callable )
Helper method for tests that needs to use error_reporting()
Parameters
-
integer
$errorLevel - value of error_reporting() that needs to use
-
callable
$callable - callable function that will receive asserts
Methods used from Cake\TestSuite\ConsoleIntegrationTestTrait
assertErrorContains()source public
assertErrorContains( string $expected , string $message = '' )
Asserts stderr contains expected output
Parameters
-
string
$expected - Expected output
-
string
$messageoptional '' - Failure message
assertErrorEmpty()source public
assertErrorEmpty( string $message = '' )
Asserts that stderr is empty
Parameters
-
string
$messageoptional '' - The message to output when the assertion fails.
assertErrorRegExp()source public
assertErrorRegExp( string $pattern , string $message = '' )
Asserts stderr contains expected regexp
Parameters
-
string
$pattern - Expected pattern
-
string
$messageoptional '' - Failure message
assertExitCode()source public
assertExitCode( integer $expected , string $message = '' )
Asserts shell exited with the expected code
Parameters
-
integer
$expected - Expected exit code
-
string
$messageoptional '' - Failure message
assertOutputContains()source public
assertOutputContains( string $expected , string $message = '' )
Asserts stdout contains expected output
Parameters
-
string
$expected - Expected output
-
string
$messageoptional '' - Failure message
assertOutputContainsRow()source protected
assertOutputContainsRow( array $row , string $message = '' )
Check that a row of cells exists in the output.
Parameters
-
array
$row - Row of cells to ensure exist in the output.
-
string
$messageoptional '' - Failure message.
assertOutputEmpty()source public
assertOutputEmpty( string $message = '' )
Asserts that stdout is empty
Parameters
-
string
$messageoptional '' - The message to output when the assertion fails.
assertOutputNotContains()source public
assertOutputNotContains( string $expected , string $message = '' )
Asserts stdout does not contain expected output
Parameters
-
string
$expected - Expected output
-
string
$messageoptional '' - Failure message
assertOutputRegExp()source public
assertOutputRegExp( string $pattern , string $message = '' )
Asserts stdout contains expected regexp
Parameters
-
string
$pattern - Expected pattern
-
string
$messageoptional '' - Failure message
cleanupConsoleTrait()source public
cleanupConsoleTrait( )
Cleans state to get ready for the next test
After
commandStringToArgs()source protected
commandStringToArgs( string $command )
Creates an $argv array from a command string
Parameters
-
string
$command - Command string
Returns
arrayexec()source public
exec( string $command , array $input = [] )
Runs cli integration test
Parameters
-
string
$command - Command to run
-
array
$inputoptional [] - Input values to pass to an interactive shell
makeRunner()source protected
makeRunner( )
Builds the appropriate command dispatcher
Returns
Cake\Console\CommandRunner|Cake\TestSuite\LegacyCommandRunneruseCommandRunner()source public
useCommandRunner( )
Set this test case to use the CommandRunner rather than the legacy ShellDispatcher
Methods used from Cake\ORM\Locator\LocatorAwareTrait
getTableLocator()source public
getTableLocator( )
Gets the table locator.
Returns
Cake\ORM\Locator\LocatorInterfacesetTableLocator()source public
setTableLocator( Cake\ORM\Locator\LocatorInterface $tableLocator )
Sets the table locator.
Parameters
Cake\ORM\Locator\LocatorInterface$tableLocator- LocatorInterface instance.
Returns
$this
tableLocator()source public deprecated
tableLocator( Cake\ORM\Locator\LocatorInterface $tableLocator = null )
Sets the table locator. If no parameters are passed, it will return the currently used locator.
Parameters
Cake\ORM\Locator\LocatorInterface$tableLocatoroptional null- LocatorInterface instance.
Returns
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.7/class-Cake.TestSuite.ConsoleIntegrationTestCase.html