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
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.9 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.9
      • 4.2
      • 4.1
      • 4.0
      • 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

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper
  • None

Classes

  • CakeTestCase
  • CakeTestLoader
  • CakeTestRunner
  • CakeTestSuite
  • CakeTestSuiteCommand
  • CakeTestSuiteDispatcher
  • ControllerTestCase
  • ControllerTestDispatcher
  • InterceptContentHelper

Class CakeTestCase

CakeTestCase class

PHPUnit_Framework_TestCase
Extended by CakeTestCase
Direct Subclasses
  • ControllerTestCase
Abstract
Package: Cake\TestSuite
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/TestSuite/CakeTestCase.php

Properties summary

  • $_configure protected
    array
    Configure values to restore at end of test.
  • $_pathRestore protected
    array
    Path settings to restore at the end of the test.
  • $autoFixtures 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

  • $dropTables public
    boolean
    Control table create/drops on each test method.
  • $fixtureManager public
    CakeFixtureManager
    The class responsible for managing the creation, loading and removing of fixtures

Method Summary

  • _assertAttributes() protected
    Check the attributes as part of an assertTags() check.
  • assertEqual() protected static deprecated
    Compatibility wrapper function for assertEquals
  • assertIdentical() protected static deprecated
    Compatibility wrapper function for assertEquals
  • assertIsA() protected static deprecated
    Compatibility wrapper for assertIsA
  • assertNoErrors() protected deprecated
    assert no errors
  • assertNoPattern() protected static deprecated
    Compatibility wrapper function for assertNotRegExp
  • assertNotEqual() protected static deprecated
    Compatibility wrapper function for assertNotEquals
  • assertNotIdentical() protected static deprecated
    Compatibility wrapper function for assertNotEquals
  • assertPattern() protected static deprecated
    Compatibility wrapper function for assertRegexp
  • assertPostConditions() protected
    Announces the end of a test.
  • assertPreConditions() protected
    Announces the start of a test.
  • assertReference() protected static deprecated
    Compatibility wrapper function for assertSame
  • assertTags() public

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

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

  • assertWithinMargin() protected static
    Compatibility function to test if value is between an acceptable range
  • date() public static
    See CakeTestSuiteDispatcher::date()
  • endTest() public
    Called when a test case method has been executed (to be overridden when needed.)
  • expectError() protected deprecated
    Compatibility wrapper function for setExpectedException
  • expectException() protected deprecated
    Compatibility wrapper function for setExpectedException
  • getMockForModel() public
    Mock a model, maintain fixtures and table association
  • loadFixtures() public
    Chooses which fixtures to load for a given test
  • run() public

    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

  • setUp() public

    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() public
    Overrides SimpleTestCase::skipIf to provide a boolean return value
  • skipUnless() protected
    Compatibility function for skipping.
  • startTest() public
    Called when a test case method is about to start (to be overridden when needed.)
  • tearDown() public
    teardown any static object changes and restore them.

Method Detail

_assertAttributes() protected ¶

_assertAttributes( array $assertions , string $string )

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

Parameters
array $assertions
Assertions to run.
string $string
The HTML string to check.

assertEqual() protected static deprecated ¶

assertEqual( mixed $result , mixed $expected , string $message = '' )

Compatibility wrapper function for assertEquals

Deprecated
3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
Parameters
mixed $result
mixed $expected
string $message optional ''
the text to display if the assertion is not correct

assertIdentical() protected static deprecated ¶

assertIdentical( mixed $actual , mixed $expected , string $message = '' )

Compatibility wrapper function for assertEquals

Deprecated
3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
Parameters
mixed $actual
mixed $expected
string $message optional ''
the text to display if the assertion is not correct

assertIsA() protected static deprecated ¶

assertIsA( string $object , string $type , string $message = '' )

Compatibility wrapper for assertIsA

Deprecated
3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
Parameters
string $object
string $type
string $message optional ''

assertNoErrors() protected deprecated ¶

assertNoErrors( )

assert no errors

Deprecated
3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0

assertNoPattern() protected static deprecated ¶

assertNoPattern( mixed $pattern , string $string , string $message = '' )

Compatibility wrapper function for assertNotRegExp

Deprecated
3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
Parameters
mixed $pattern
a regular expression
string $string
the text to be matched
string $message optional ''
the text to display if the assertion is not correct

assertNotEqual() protected static deprecated ¶

assertNotEqual( mixed $result , mixed $expected , string $message = '' )

Compatibility wrapper function for assertNotEquals

Deprecated
3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
Parameters
mixed $result
mixed $expected
string $message optional ''
the text to display if the assertion is not correct

assertNotIdentical() protected static deprecated ¶

assertNotIdentical( mixed $actual , mixed $expected , string $message = '' )

Compatibility wrapper function for assertNotEquals

Deprecated
3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
Parameters
mixed $actual
mixed $expected
string $message optional ''
the text to display if the assertion is not correct

assertPattern() protected static deprecated ¶

assertPattern( mixed $pattern , string $string , string $message = '' )

Compatibility wrapper function for assertRegexp

Deprecated
3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
Parameters
mixed $pattern
a regular expression
string $string
the text to be matched
string $message optional ''
the text to display if the assertion is not correct

assertPostConditions() protected ¶

assertPostConditions( )

Announces the end of a test.

assertPreConditions() protected ¶

assertPreConditions( )

Announces the start of a test.

assertReference() protected static deprecated ¶

assertReference( mixed $first , mixed $second , string $message = '' )

Compatibility wrapper function for assertSame

Deprecated
3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
Parameters
mixed $first
mixed $second
string $message optional ''
the text to display if the assertion is not correct

assertTags() public ¶

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.

Parameters
string $string
An HTML/XHTML/XML string
array $expected
An array, see above
string $fullDebug optional false
Whether or not more verbose output should be used.
Returns
boolean

assertTextContains() 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.
Returns
boolean

assertTextEndsNotWith() 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.
Returns
boolean

assertTextEndsWith() 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.
Returns
boolean

assertTextEquals() 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 ''
message The message to use for failure.
Returns
boolean

assertTextNotContains() 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.
Returns
boolean

assertTextNotEquals() 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.
Returns
boolean

assertTextStartsNotWith() 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.
Returns
boolean

assertTextStartsWith() 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.
Returns
boolean

assertWithinMargin() protected static ¶

assertWithinMargin( mixed $result , mixed $expected , mixed $margin , string $message = '' )

Compatibility function to test if value is between an acceptable range

Parameters
mixed $result
mixed $expected
mixed $margin
the rage of acceptation
string $message optional ''
the text to display if the assertion is not correct

date() public static ¶

date( string $format = 'Y-m-d H:i:s' )

See CakeTestSuiteDispatcher::date()

Parameters
string $format optional 'Y-m-d H:i:s'
format to be used.
Returns
string

endTest() public ¶

endTest( string $method )

Called when a test case method has been executed (to be overridden when needed.)

Parameters
string $method
Test method about that was executed.

expectError() protected deprecated ¶

expectError( mixed $expected = false , string $message = '' )

Compatibility wrapper function for setExpectedException

Deprecated
3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
Parameters
mixed $expected optional false
the name of the Exception or error
string $message optional ''
the text to display if the assertion is not correct

expectException() protected deprecated ¶

expectException( mixed $name = 'Exception' , string $message = '' )

Compatibility wrapper function for setExpectedException

Deprecated
3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0.
Parameters
mixed $name optional 'Exception'
The name of the expected Exception.
string $message optional ''
the text to display if the assertion is not correct

getMockForModel() public ¶

getMockForModel( string $model , mixed $methods = array() , array $config = array() )

Mock a model, maintain fixtures and table association

Parameters
string $model
The model to get a mock for.
mixed $methods optional array()
The list of methods to mock
array $config optional array()
The config data for the mock's constructor.
Returns
Model
Throws
MissingModelException

loadFixtures() public ¶

loadFixtures( )

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.

Throws
Exception
when no fixture manager is available.
See
CakeTestCase::$autoFixtures

run() public ¶

run( 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

Parameters
PHPUnit_Framework_TestResult $result optional null
The test result object
Returns
PHPUnit_Framework_TestResult
Throws
InvalidArgumentException

setUp() 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() 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

skipUnless() 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

startTest() public ¶

startTest( string $method )

Called when a test case method is about to start (to be overridden when needed.)

Parameters
string $method
Test method about to get executed.

tearDown() public ¶

tearDown( )

teardown any static object changes and restore them.

Properties detail

$_configure ¶

protected array

Configure values to restore at end of test.

array()

$_pathRestore ¶

protected array

Path settings to restore at the end of the test.

array()

$autoFixtures ¶

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

$dropTables ¶

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

$fixtureManager ¶

public CakeFixtureManager

The class responsible for managing the creation, loading and removing of fixtures

null
OpenHub
Rackspace
Rackspace
  • 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
  • Slack
  • Paid Support

Generated using CakePHP API Docs