Class TestCase
Cake TestCase class
- PHPUnit_Framework_TestCase
- Cake\TestSuite\TestCase
Direct known subclasses
Cake\TestSuite\IntegrationTestCaseMethod Detail
_assertAttributessource protected
_assertAttributes( array $assertions , string $string , boolean $fullDebug false , array $regex '' )
Check the attributes as part of an assertTags() check.
Parameters
- array
$assertions
- Assertions to run.
- string
$string
- The HTML string to check.
- boolean
$fullDebug
optional false - Whether or not more verbose output should be used.
- array
$regex
optional '' - Full regexp from
assertHtml
Returns
string
string
_normalizePathsource protected
_normalizePath( string $path )
Normalize a path for comparison.
Parameters
- string
$path
- Path separated by "/" slash.
Returns
string
Normalized path separated by DS.
assertHtmlsource 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
$fullDebug
optional false - Whether or not more verbose output should be used.
Returns
boolean
bool
assertNotWithinRangesource 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
$message
optional '' - the text to display if the assertion is not correct
assertPathEqualssource protected static
assertPathEquals( string $expected , string $result , string $message '' )
Compatibility function to test paths.
Parameters
- string
$expected
- string
$result
- string
$message
optional '' - the text to display if the assertion is not correct
assertTagssource public
assertTags( string $string , array $expected , boolean $fullDebug false )
Asserts HTML tags.
Deprecated
3.0. Use assertHtml() instead.Parameters
- string
$string
- An HTML/XHTML/XML string
- array
$expected
- An array, see above
- boolean
$fullDebug
optional false - Whether or not more verbose output should be used.
assertTextContainssource 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
$message
optional '' - The message to display on failure.
- boolean
$ignoreCase
optional false - Whether or not the search should be case-sensitive.
assertTextEndsNotWithsource 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
$message
optional '' - The message to use for failure.
assertTextEndsWithsource 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
$message
optional '' - The message to use for failure.
assertTextEqualssource 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
$message
optional '' - The message to use for failure.
assertTextNotContainssource 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
$message
optional '' - The message to display on failure.
- boolean
$ignoreCase
optional false - Whether or not the search should be case-sensitive.
assertTextNotEqualssource 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
$message
optional '' - The message to use for failure.
assertTextStartsNotWithsource 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
$message
optional '' - The message to use for failure.
assertTextStartsWithsource 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
$message
optional '' - The message to use for failure.
assertWithinRangesource 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
$message
optional '' - the text to display if the assertion is not correct
getMockForModelsource public
getMockForModel( string $alias , array $methods [] , array $options [] )
Mock a model, maintain fixtures and table association
Parameters
- string
$alias
- The model to get a mock for.
- array
$methods
optional [] - The list of methods to mock
- array
$options
optional [] - The config data for the mock's constructor.
Returns
Cake\ORM\Table|PHPUnit_Framework_MockObject_MockObject
\Cake\ORM\Table|\PHPUnit_Framework_MockObject_MockObject
Throws
Cake\ORM\Exception\MissingTableClassException
\Cake\ORM\Exception\MissingTableClassException
loadFixturessource 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.
Throws
Exception
when no fixture manager is available.
See
Cake\TestSuite\TestCase::$autoFixtures
setUpsource 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.
skipIfsource 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
$message
optional '' - The message to display.
Returns
boolean
bool
skipUnlesssource protected
skipUnless( boolean $condition , string $message '' )
Compatibility function for skipping.
Parameters
- boolean
$condition
- Condition to trigger skipping
- string
$message
optional '' - Message for skip
Returns
boolean
bool
Properties summary
© 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/3.1/class-Cake.TestSuite.TestCase.html