Spork Code Libraries

TestCaseDb

PHPUnit Test Case that setups up environment for tests that require database access.

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

$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

$dbInitialized

$dbInitialized : boolean

Has database been initialized

Type

boolean

$dbAdapter

$dbAdapter : \Zend\Db\Adapter\AdapterInterface

Database adapter

Type

\Zend\Db\Adapter\AdapterInterface

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

setUp()

setUp() 

Initializes database on first run then resets tables on subsequent runs.

Throws

\Exception

on attempt to reset non temporary table

See also

tearDown()

tearDown() 

Remove Service Manager

Inherited from
\Spork\Test\TestCase\TestCaseService

initializePrototype()

initializePrototype() 

Create a Service Manager Prototype object

Inherited from
\Spork\Test\TestCase\TestCaseService

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

initializeDatabase()

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

Parameters

\Zend\Db\Adapter\Adapter $source
\Zend\Db\Adapter\Adapter $dest

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

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

getTables()

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

Get list of tables in current schema

Parameters

\Zend\Db\Adapter\Adapter $db

Returns

array