Test/PHPUnit/ControllerTestCase.php
Zend Framework
LICENSE
This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to [email protected] so we can send you a copy immediately.
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Package
- Zend_Test
- Version
- $Id: ControllerTestCase.php 24593 2012-01-05 20:35:02Z matthew $
\Zend_Test_PHPUnit_ControllerTestCase
Functional testing scaffold for MVC applications
- Parent(s)
- \PHPUnit_Framework_TestCase
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Uses
- \global\PHPUnit_Framework_TestCase
Properties
Methods


__get(mixed $name) : void
Overloading for common properties
Provides overloading for request, response, and frontController objects.
Name | Type | Description |
---|---|---|
$name | mixed |


__set(string $name, mixed $value) : void
Overloading: prevent overloading to special properties
Name | Type | Description |
---|---|---|
$name | string | |
$value | mixed |


assertAction(string $action, string $message = '') : void
Assert that the last handled request used the given action
Name | Type | Description |
---|---|---|
$action | string | |
$message | string |


assertController(string $controller, string $message = '') : void
Assert that the last handled request used the given controller
Name | Type | Description |
---|---|---|
$controller | string | |
$message | string |


assertHeader(string $header, string $message = '') : void
Assert response header exists
Name | Type | Description |
---|---|---|
$header | string | |
$message | string |


assertHeaderContains(string $header, string $match, string $message = '') : void
Assert response header exists and contains the given string
Name | Type | Description |
---|---|---|
$header | string | |
$match | string | |
$message | string |


assertHeaderRegex(string $header, string $pattern, string $message = '') : void
Assert response header exists and matches the given pattern
Name | Type | Description |
---|---|---|
$header | string | |
$pattern | string | |
$message | string |


assertModule(string $module, string $message = '') : void
Assert that the last handled request used the given module
Name | Type | Description |
---|---|---|
$module | string | |
$message | string |


assertNotAction(string $action, string $message = '') : void
Assert that the last handled request did NOT use the given action
Name | Type | Description |
---|---|---|
$action | string | |
$message | string |


assertNotController(string $controller, string $message = '') : void
Assert that the last handled request did NOT use the given controller
Name | Type | Description |
---|---|---|
$controller | string | |
$message | string |


assertNotHeader(string $header, string $message = '') : void
Assert response header does not exist
Name | Type | Description |
---|---|---|
$header | string | |
$message | string |


assertNotHeaderContains(string $header, string $match, string $message = '') : void
Assert response header does not exist and/or does not contain the given string
Name | Type | Description |
---|---|---|
$header | string | |
$match | string | |
$message | string |


assertNotHeaderRegex(string $header, string $pattern, string $message = '') : void
Assert response header does not exist and/or does not match the given regex
Name | Type | Description |
---|---|---|
$header | string | |
$pattern | string | |
$message | string |


assertNotModule(string $module, string $message = '') : void
Assert that the last handled request did NOT use the given module
Name | Type | Description |
---|---|---|
$module | string | |
$message | string |


assertNotQuery(string $path, string $message = '') : void
Assert against DOM selection
Name | Type | Description |
---|---|---|
$path | string | CSS selector path |
$message | string |


assertNotQueryContentContains(string $path, string $match, string $message = '') : void
Assert against DOM selection; node should NOT contain content
Name | Type | Description |
---|---|---|
$path | string | CSS selector path |
$match | string | content that should NOT be contained in matched nodes |
$message | string |


assertNotQueryContentRegex(string $path, string $pattern, string $message = '') : void
Assert against DOM selection; node should NOT match content
Name | Type | Description |
---|---|---|
$path | string | CSS selector path |
$pattern | string | pattern that should NOT be contained in matched nodes |
$message | string |


assertNotQueryCount(string $path, string $count, string $message = '') : void
Assert against DOM selection; should NOT contain exact number of nodes
Name | Type | Description |
---|---|---|
$path | string | CSS selector path |
$count | string | Number of nodes that should NOT match |
$message | string |


assertNotRedirect(string $message = '') : void
Assert that response is NOT a redirect
Name | Type | Description |
---|---|---|
$message | string |


assertNotRedirectRegex(string $pattern, string $message = '') : void
Assert that redirect location does not match pattern
Name | Type | Description |
---|---|---|
$pattern | string | |
$message | string |


assertNotRedirectTo(string $url, string $message = '') : void
Assert that response does not redirect to given URL
Name | Type | Description |
---|---|---|
$url | string | |
$message | string |


assertNotResponseCode(int $code, string $message = '') : void
Assert response code
Name | Type | Description |
---|---|---|
$code | int | |
$message | string |


assertNotRoute(string $route, string $message = '') : void
Assert that the route matched is NOT as specified
Name | Type | Description |
---|---|---|
$route | string | |
$message | string |


assertNotXpath(string $path, string $message = '') : void
Assert against XPath selection
Name | Type | Description |
---|---|---|
$path | string | XPath path |
$message | string |


assertNotXpathContentContains(string $path, string $match, string $message = '') : void
Assert against XPath selection; node should NOT contain content
Name | Type | Description |
---|---|---|
$path | string | XPath path |
$match | string | content that should NOT be contained in matched nodes |
$message | string |


assertNotXpathContentRegex(string $path, string $pattern, string $message = '') : void
Assert against XPath selection; node should NOT match content
Name | Type | Description |
---|---|---|
$path | string | XPath path |
$pattern | string | pattern that should NOT be contained in matched nodes |
$message | string |


assertNotXpathCount(string $path, string $count, string $message = '') : void
Assert against XPath selection; should NOT contain exact number of nodes
Name | Type | Description |
---|---|---|
$path | string | XPath path |
$count | string | Number of nodes that should NOT match |
$message | string |


assertQuery(string $path, string $message = '') : void
Assert against DOM selection
Name | Type | Description |
---|---|---|
$path | string | CSS selector path |
$message | string |


assertQueryContentContains(string $path, string $match, string $message = '') : void
Assert against DOM selection; node should contain content
Name | Type | Description |
---|---|---|
$path | string | CSS selector path |
$match | string | content that should be contained in matched nodes |
$message | string |


assertQueryContentRegex(string $path, string $pattern, string $message = '') : void
Assert against DOM selection; node should match content
Name | Type | Description |
---|---|---|
$path | string | CSS selector path |
$pattern | string | Pattern that should be contained in matched nodes |
$message | string |


assertQueryCount(string $path, string $count, string $message = '') : void
Assert against DOM selection; should contain exact number of nodes
Name | Type | Description |
---|---|---|
$path | string | CSS selector path |
$count | string | Number of nodes that should match |
$message | string |


assertQueryCountMax(string $path, string $count, string $message = '') : void
Assert against DOM selection; should contain no more than this number of nodes
Name | Type | Description |
---|---|---|
$path | string | CSS selector path |
$count | string | Maximum number of nodes that should match |
$message | string |


assertQueryCountMin(string $path, string $count, string $message = '') : void
Assert against DOM selection; should contain at least this number of nodes
Name | Type | Description |
---|---|---|
$path | string | CSS selector path |
$count | string | Minimum number of nodes that should match |
$message | string |


assertRedirect(string $message = '') : void
Assert that response is a redirect
Name | Type | Description |
---|---|---|
$message | string |


assertRedirectRegex(string $pattern, string $message = '') : void
Assert that redirect location matches pattern
Name | Type | Description |
---|---|---|
$pattern | string | |
$message | string |


assertRedirectTo(string $url, string $message = '') : void
Assert that response redirects to given URL
Name | Type | Description |
---|---|---|
$url | string | |
$message | string |


assertResponseCode(int $code, string $message = '') : void
Assert response code
Name | Type | Description |
---|---|---|
$code | int | |
$message | string |


assertRoute(string $route, string $message = '') : void
Assert that the specified route was used
Name | Type | Description |
---|---|---|
$route | string | |
$message | string |


assertXpath(string $path, string $message = '') : void
Assert against XPath selection
Name | Type | Description |
---|---|---|
$path | string | XPath path |
$message | string |


assertXpathContentContains(string $path, string $match, string $message = '') : void
Assert against XPath selection; node should contain content
Name | Type | Description |
---|---|---|
$path | string | XPath path |
$match | string | content that should be contained in matched nodes |
$message | string |


assertXpathContentRegex(string $path, string $pattern, string $message = '') : void
Assert against XPath selection; node should match content
Name | Type | Description |
---|---|---|
$path | string | XPath path |
$pattern | string | Pattern that should be contained in matched nodes |
$message | string |


assertXpathCount(string $path, string $count, string $message = '') : void
Assert against XPath selection; should contain exact number of nodes
Name | Type | Description |
---|---|---|
$path | string | XPath path |
$count | string | Number of nodes that should match |
$message | string |


assertXpathCountMax(string $path, string $count, string $message = '') : void
Assert against XPath selection; should contain no more than this number of nodes
Name | Type | Description |
---|---|---|
$path | string | XPath path |
$count | string | Maximum number of nodes that should match |
$message | string |


assertXpathCountMin(string $path, string $count, string $message = '') : void
Assert against XPath selection; should contain at least this number of nodes
Name | Type | Description |
---|---|---|
$path | string | XPath path |
$count | string | Minimum number of nodes that should match |
$message | string |


bootstrap() : void
Bootstrap the front controller
Resets the front controller, and then bootstraps it.
If $bootstrap is a callback, executes it; if it is a file, it include's it. When done, sets the test case request and response objects into the front controller.


dispatch(string | null $url = null) : void
Dispatch the MVC
If a URL is provided, sets it as the request URI in the request object. Then sets test case request and response objects in front controller, disables throwing exceptions, and disables returning the response. Finally, dispatches the front controller.
Name | Type | Description |
---|---|---|
$url | string | null |


getFrontController() : \Zend_Controller_Front
Retrieve front controller instance
Type | Description |
---|---|
\Zend_Controller_Front |


getRequest() : \Zend_Controller_Request_HttpTestCase
Retrieve test case request object
Type | Description |
---|---|
\Zend_Controller_Request_HttpTestCase |


getResponse() : \Zend_Controller_Response_HttpTestCase
Retrieve test case response object
Type | Description |
---|---|
\Zend_Controller_Response_HttpTestCase |


registerXpathNamespaces(array $xpathNamespaces) : void
Register XPath namespaces
Name | Type | Description |
---|---|---|
$xpathNamespaces | array |


reset() : void
Reset MVC state
Creates new request/response objects, resets the front controller instance, and resets the action helper broker.
- Todo
- Need to update Zend_Layout to add a resetInstance() method


resetRequest() : \Zend_Test_PHPUnit_ControllerTestCase
Reset the request object
Useful for test cases that need to test multiple trips to the server.
Type | Description |
---|---|
\Zend_Test_PHPUnit_ControllerTestCase |


resetResponse() : \Zend_Test_PHPUnit_ControllerTestCase
Reset the response object
Useful for test cases that need to test multiple trips to the server.
Type | Description |
---|---|
\Zend_Test_PHPUnit_ControllerTestCase |


url(array $urlOptions = array(), string $name = null, bool $reset = false, bool $encode = true) : void
URL Helper
Name | Type | Description |
---|---|---|
$urlOptions | array | |
$name | string | |
$reset | bool | |
$encode | bool |