ControllerTestCase class
CakeTestCase
ControllerTestCase __call( string $name , array $arguments )
Used to enable calling ControllerTestCase::testAction() without the testing framework thinking that it's a test case
$name $arguments mixedBadMethodCallException_testAction( string|array $url , array $options array() )
Lets you do functional tests of a controller action.
data Will be used as the request data. If the method is GET, data will be used a GET params. If the method is POST, it will be used as POST data. By setting $options['data'] to a string, you can simulate XML or JSON payloads to your controllers allowing you to test REST webservices.method POST or GET. Defaults to POST.return Specify the return type you want. Choose from: - vars Get the set view variables. - view Get the rendered view, without a layout. - contents Get the rendered view including the layout. - result Get the return value of the controller action. Useful for testing requestAction methods.$url $options optional array() mixedgenerate( string $controller , array $mocks array() )
Generates a mocked controller and mocks any classes passed to $mocks. By default, _stop() is stubbed as is sending the response headers, so to not interfere with testing.
methods Methods to mock on the controller. _stop() is mocked by defaultmodels Models to mock. Models are added to the ClassRegistry so any time they are instantiated the mock will be created. Pass as key value pairs with the value being specific methods on the model to mock. If true or no value is passed, the entire model will be mocked.components Components to mock. Components are only mocked on this controller and not within each other (i.e., components on components)$controller $mocks optional array() ControllerMissingControllerExceptionMissingComponentException_assertAttributes( array $assertions , string $string )
Check the attributes as part of an assertTags() check.
$assertions $string assertEqual( mixed $result , mixed $expected , string $message '' )
Compatibility wrapper function for assertEquals
$result $expected $message optional '' assertIdentical( mixed $actual , mixed $expected , string $message '' )
Compatibility wrapper function for assertEquals
$actual $expected $message optional '' assertIsA( string $object , string $type , string $message '' )
Compatibility wrapper for assertIsA
$object $type $message optional '' assertNoErrors( )
assert no errors
assertNoPattern( mixed $pattern , string $string , string $message '' )
Compatibility wrapper function for assertNotRegExp
$pattern $string $message optional '' assertNotEqual( mixed $result , mixed $expected , string $message '' )
Compatibility wrapper function for assertNotEquals
$result $expected $message optional '' assertNotIdentical( mixed $actual , mixed $expected , string $message '' )
Compatibility wrapper function for assertNotEquals
$actual $expected $message optional '' assertPattern( mixed $pattern , string $string , string $message '' )
Compatibility wrapper function for assertRegexp
$pattern $string $message optional '' assertReference( mixed $first , mixed $second , string $message '' )
Compatibility wrapper function for assertSame
$first $second $message optional '' assertTags( string $string , array $expected , string $fullDebug false )
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':
array('input' => array('name', 'id' => 'my-input'))
Checks for two p elements with some text in them:
array( array('p' => true), 'textA', '/p', array('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:
array( array('input' => array('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.
$string $expected $fullDebug optional false booleanassertTextContains( 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 booleanassertTextEndsNotWith( 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 '' booleanassertTextEndsWith( 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 '' booleanassertTextEquals( 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 '' booleanassertTextNotContains( 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 booleanassertTextNotEquals( 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 '' booleanassertTextStartsNotWith( 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 '' booleanassertTextStartsWith( 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 '' booleanassertWithinMargin( mixed $result , mixed $expected , mixed $margin , string $message '' )
Compatibility function to test if value is between an acceptable range
$result $expected $margin $message optional '' date( string $format 'Y-m-d H:i:s' )
See CakeTestSuiteDispatcher::date()
$format optional 'Y-m-d H:i:s' stringendTest( string $method )
Called when a test case method has been executed (to be overridden when needed.)
$method expectError( mixed $expected false , string $message '' )
Compatibility wrapper function for setExpectedException
$expected optional false $message optional '' expectException( mixed $name 'Exception' , string $message '' )
Compatibility wrapper function for setExpectedException
$name optional 'Exception' $message optional '' getMockForModel( string $model , mixed $methods array() , array $config array() )
Mock a model, maintain fixtures and table association
$model $methods optional array() $config optional array() ModelMissingModelExceptionloadFixtures( )
Chooses which fixtures to load for a given test
Each parameter is a model name that corresponds to a fixture, i.e. 'Post', 'Author', etc.
ExceptionCakeTestCase::$autoFixturesrun( PHPUnit_Framework_TestResult $result null )
Runs the test case and collects the results in a TestResult object. If no TestResult object is passed a new one will be created. This method is run for each test method in this class
$result optional null PHPUnit_Framework_TestResultInvalidArgumentExceptionsetUp( )
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 '' booleanskipUnless( boolean $condition , string $message '' )
Compatibility function for skipping.
$condition $message optional '' booleanstartTest( string $method )
Called when a test case method is about to start (to be overridden when needed.)
$method public array
By default, all fixtures attached to this class will be truncated and reloaded after each test. Set this to false to handle manually
true public boolean
Control table create/drops on each test method.
Set this to false to avoid tables to be dropped if they already exist between each test method. Tables will still be dropped at the end of each test runner execution.
true public CakeFixtureManager
The class responsible for managing the creation, loading and removing of fixtures
null
© 2005–2016 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.
http://api.cakephp.org/2.7/class-ControllerTestCase.html