Spork Code Libraries

TestCaseController

PHPUnit Test Case for testing controller actions

NOTE: This was written for MySQL and probably won't work with other databases.

Database is initialized on first use by coping the structure of existing tables and creating temporary tables on top of them. The temporary tables are then truncated and reused on additional tests to speed up performance. Temporary tables are changed to use the Memory engine when possible to speed up performance.

Extends

Properties

$dbInitialized

$dbInitialized : boolean

Has database been initialized

Type

boolean
Inherited from
\Spork\Test\TestCase\TestCaseDb

$dbAdapter

$dbAdapter : \Zend\Db\Adapter\AdapterInterface

Database adapter

Type

\Zend\Db\Adapter\AdapterInterface
Inherited from
\Spork\Test\TestCase\TestCaseDb

$config

$config : 

Type

Inherited from
\Spork\Test\TestCase\TestCaseService

$configPath

$configPath : 

Type

Inherited from
\Spork\Test\TestCase\TestCaseService

$cloneServices

$cloneServices : boolean

Should services be cloned from prototype or created from scratch. This is experimental and should be used with caution.

Type

boolean
Inherited from
\Spork\Test\TestCase\TestCaseService

$serviceManagerPrototype

$serviceManagerPrototype : \Zend\ServiceManager\ServiceManager

Service Manager Prototype

Type

\Zend\ServiceManager\ServiceManager
Inherited from
\Spork\Test\TestCase\TestCaseService

$services

$services : \Zend\ServiceManager\ServiceLocatorInterface

Service Manager

Type

\Zend\ServiceManager\ServiceLocatorInterface
Inherited from
\Spork\ServiceManager\ServicesAwareTrait

$application

$application : \Zend\Mvc\Application

Type

\Zend\Mvc\Application

$isConsole

$isConsole : Boolean

Is console state

Type

Boolean

$params

$params : array

List of request parameters

Type

array

$request

$request : \Zend\Http\PhpEnvironment\Request

Request object

Type

\Zend\Http\PhpEnvironment\Request

$response

$response : \Zend\Http\PhpEnvironment\Response

Response object

Type

\Zend\Http\PhpEnvironment\Response

Methods

__destruct()

__destruct() 

Unset services

Inherited from
\Spork\ServiceManager\ServicesAwareTrait

getServices()

getServices() : \Zend\ServiceManager\ServiceLocatorInterface

Get Service Manager

Returns

\Zend\ServiceManager\ServiceLocatorInterface
Inherited from
\Spork\ServiceManager\ServicesAwareTrait

setServices()

setServices(\Zend\ServiceManager\ServiceLocatorInterface  $services) 

Set Service Manager

Parameters

\Zend\ServiceManager\ServiceLocatorInterface $services
Inherited from
\Spork\ServiceManager\ServicesAwareTrait

getServiceLocator()

getServiceLocator() : \Zend\ServiceManager\ServiceLocatorInterface

Provides compatibility ServiceLocatorAwareInterface

Returns

\Zend\ServiceManager\ServiceLocatorInterface
Inherited from
\Spork\ServiceManager\ServicesAwareTrait

setServiceLocator()

setServiceLocator(\Zend\ServiceManager\ServiceLocatorInterface  $services) 

Provides compatibility ServiceLocatorAwareInterface

Parameters

\Zend\ServiceManager\ServiceLocatorInterface $services
Inherited from
\Spork\ServiceManager\ServicesAwareTrait

getServiceManager()

getServiceManager() : \Zend\ServiceManager\ServiceLocatorInterface

Provides compatibility ServiceManagerAwareInterface

Returns

\Zend\ServiceManager\ServiceLocatorInterface
Inherited from
\Spork\ServiceManager\ServicesAwareTrait

setServiceManager()

setServiceManager(\Zend\ServiceManager\ServiceLocatorInterface  $services) 

Provides compatibility ServiceManagerAwareInterface

Parameters

\Zend\ServiceManager\ServiceLocatorInterface $services
Inherited from
\Spork\ServiceManager\ServicesAwareTrait

assertTableRowCount()

assertTableRowCount(integer  $count, string|\Zend\Db\TableGateway  $table, string|array|\Spork\Test\TestCase\Closure|\Spork\Test\TestCase\PredicateInterface  $where = null) 

Assert that a table has specified number for rows

Parameters

integer $count
string|\Zend\Db\TableGateway $table
string|array|\Spork\Test\TestCase\Closure|\Spork\Test\TestCase\PredicateInterface $where

Throws

\Exception

on $table not a table name or TableGateway instance

Inherited from
\Spork\Test\TestCase\TestCaseDb

setUp()

setUp() 

Setup resources for dispatching a controller action

See also

tearDown()

tearDown() 

Reset is console flag

See also

initializePrototype()

initializePrototype() 

Create a Service Manager Prototype object

Inherited from
\Spork\Test\TestCase\TestCaseService

dispatch()

dispatch(string  $controller, string  $action = null) : mixed

Dispatch a controller action

Parameters

string $controller
string $action

Returns

mixed

assertApplicationException()

assertApplicationException(string  $class = 'Exception', string  $message = null) 

Assert that the application caught an exception

Parameters

string $class
string $message

assertResponse()

assertResponse() 

Test that a response was created

assertResponseOk()

assertResponseOk() 

Test that response has status 200 OK

assertResponseStatusCode()

assertResponseStatusCode(integer  $code, string  $message = null) 

Test that response has specific status code

Parameters

integer $code
string $message

assertResponseRedirect()

assertResponseRedirect(string  $url = null) 

Test that response has status 302 Redirect and optionally that the location header is set to a specific URL.

Parameters

string $url

assertResponseAccessDenied()

assertResponseAccessDenied() 

Test that response has status 403 Forbidden

assertResponseError()

assertResponseError() 

Test that response has status 500 Application Error

assertResponseNotFound()

assertResponseNotFound() 

Test that response has status 404 Page Not Found

getAuthMember()

getAuthMember() 

Get authenticated user

getQuery()

getQuery(string  $name = null, string  $default = null) : \Zend\Stdlib\ParametersInterface

Get a value or list of values from the request's query values

Parameters

string $name
string $default

Returns

\Zend\Stdlib\ParametersInterface —

| mixed

getPost()

getPost(string  $name = null, string  $default = null) : \Zend\Stdlib\ParametersInterface

Get a value or list of values from the request's post values

Parameters

string $name
string $default

Returns

\Zend\Stdlib\ParametersInterface —

| mixed

getRequest()

getRequest() : \Zend\Http\PhpEnvironment\Request

Get the Request object

Returns

\Zend\Http\PhpEnvironment\Request

getResponse()

getResponse() : \Zend\Http\PhpEnvironment\Response

Get the Response object

Returns

\Zend\Http\PhpEnvironment\Response

setAuthMember()

setAuthMember(\Spork\Test\TestCase\unknown  $member) 

Set authenticated member

Parameters

\Spork\Test\TestCase\unknown $member

setContent()

setContent(mixed  $content) 

Set Request content

Parameters

mixed $content

setMethod()

setMethod(string  $method) 

Set Request method

Parameters

string $method

GET, POST, etc

setQuery()

setQuery(array|\Zend\Stdlib\ParametersInterface  $query) 

Set requests query values

Parameters

array|\Zend\Stdlib\ParametersInterface $query

setParams()

setParams(array  $params) 

Set route parameters

Parameters

array $params

setPost()

setPost(array|\Zend\Stdlib\ParametersInterface  $post) 

Set requests post values

Parameters

array|\Zend\Stdlib\ParametersInterface $post

setRequest()

setRequest(\Zend\Stdlib\RequestInterface  $request) 

Set Request object

Parameters

\Zend\Stdlib\RequestInterface $request

setResponse()

setResponse(\Zend\Stdlib\ResponseInterface  $response) 

Set Response object

Parameters

\Zend\Stdlib\ResponseInterface $response

initializeDatabase()

initializeDatabase(\Zend\Db\Adapter\Adapter  $source, \Zend\Db\Adapter\Adapter  $dest) 

Parameters

\Zend\Db\Adapter\Adapter $source
\Zend\Db\Adapter\Adapter $dest
Inherited from
\Spork\Test\TestCase\TestCaseDb

createTestTable()

createTestTable(string  $table, \Zend\Db\Adapter\Adapter  $source, \Zend\Db\Adapter\Adapter  $dest) 

Copies table structure and creates temporary table on top of it.

Parameters

string $table

Table name

\Zend\Db\Adapter\Adapter $source
\Zend\Db\Adapter\Adapter $dest
Inherited from
\Spork\Test\TestCase\TestCaseDb

getCreateTable()

getCreateTable(string  $table, \Zend\Db\Adapter\Adapter  $db) : mixed

Gets table structure

Parameters

string $table

Table name

\Zend\Db\Adapter\Adapter $db

Returns

mixed
Inherited from
\Spork\Test\TestCase\TestCaseDb

getTables()

getTables(\Zend\Db\Adapter\Adapter  $db) : array

Get list of tables in current schema

Parameters

\Zend\Db\Adapter\Adapter $db

Returns

array
Inherited from
\Spork\Test\TestCase\TestCaseDb