Class FixtureManager
A factory class to manage the life cycle of test fixtures
Properties summary
-
$_debug
protectedboolean
Is the test runner being run with
--debug
enabled. When true, fixture SQL will also be logged. -
$_fixtureMap
protected -
$_initialized
protectedWas this instance already initialized?boolean
-
$_insertionMap
protectedA map of connection names and the fixture currently in it.array
-
$_loaded
protected -
$_processed
protectedList of TestCase class name that have been processedarray
Method Summary
- _aliasConnections() protectedAdd aliases for all non test prefixed connections.
- _fixtureConnections() protectedGet the unique list of connections that a set of fixtures contains.
- _initDb() protectedInitializes this class with a DataSource object to use as default for all fixtures
- _loadFixtures() protectedLooks for fixture files and instantiates the classes accordingly
- _runOperation() protectedRun a function on each connection and collection of fixtures.
- _setupTable() protectedRuns the drop and create commands on the fixtures if necessary.
- fixturize() publicInspects the test to look for unloaded fixtures and loads them
- isFixtureSetup() publicCheck whether or not a fixture has been inserted in a given connection name.
- load() publicCreates the fixtures tables and inserts data on them.
- loadSingle() publicCreates a single fixture table and loads data into it.
- loaded() publicGet the loaded fixtures.
- setDebug() publicModify the debug mode.
- shutDown() publicDrop all fixture tables loaded by this class
- unload() publicTruncates the fixtures tables
Method Detail
_aliasConnections()source protected
_aliasConnections( )
Add aliases for all non test prefixed connections.
This allows models to use the test connections without a pile of configuration work.
_fixtureConnections()source protected
_fixtureConnections( array $fixtures )
Get the unique list of connections that a set of fixtures contains.
Parameters
- array
$fixtures
- The array of fixtures a list of connections is needed from.
Returns
arrayAn array of connection names.
_initDb()source protected
_initDb( )
Initializes this class with a DataSource object to use as default for all fixtures
_loadFixtures()source protected
_loadFixtures( Cake\TestSuite\TestCase $test )
Looks for fixture files and instantiates the classes accordingly
Parameters
-
Cake\TestSuite\TestCase
$test
- The test suite to load fixtures for.
Throws
UnexpectedValueExceptionwhen a referenced fixture does not exist.
_runOperation()source protected
_runOperation( array $fixtures , callable $operation )
Run a function on each connection and collection of fixtures.
Parameters
- array
$fixtures
- A list of fixtures to operate on.
- callable
$operation
- The operation to run on each connection + fixture set.
_setupTable()source protected
_setupTable( Cake\Datasource\FixtureInterface $fixture , Cake\Database\Connection $db , array $sources , boolean $drop true )
Runs the drop and create commands on the fixtures if necessary.
Parameters
-
Cake\Datasource\FixtureInterface
$fixture
- the fixture object to create
-
Cake\Database\Connection
$db
- The Connection object instance to use
- array
$sources
- The existing tables in the datasource.
- boolean
$drop
optional true - whether drop the fixture if it is already created or not
fixturize()source public
fixturize( Cake\TestSuite\TestCase $test )
Inspects the test to look for unloaded fixtures and loads them
Parameters
-
Cake\TestSuite\TestCase
$test
- The test case to inspect.
isFixtureSetup()source public
isFixtureSetup( string $connection , Cake\Datasource\FixtureInterface $fixture )
Check whether or not a fixture has been inserted in a given connection name.
Parameters
- string
$connection
- The connection name.
-
Cake\Datasource\FixtureInterface
$fixture
- The fixture to check.
Returns
booleanload()source public
load( Cake\TestSuite\TestCase $test )
Creates the fixtures tables and inserts data on them.
Parameters
-
Cake\TestSuite\TestCase
$test
- The test to inspect for fixture loading.
Throws
Cake\Core\Exception\Exception
When fixture records cannot be inserted.
loadSingle()source public
loadSingle( string $name , Cake\Datasource\ConnectionInterface|null $db null , boolean $dropTables true )
Creates a single fixture table and loads data into it.
Parameters
- string
$name
- of the fixture
-
Cake\Datasource\ConnectionInterface
|null$db
optional null - Connection instance or leave null to get a Connection from the fixture
- boolean
$dropTables
optional true - Whether or not tables should be dropped and re-created.
Throws
UnexpectedValueExceptionif $name is not a previously loaded class
setDebug()source public
setDebug( boolean $debug )
Modify the debug mode.
Parameters
- boolean
$debug
- Whether or not fixture debug mode is enabled.
unload()source public
unload( Cake\TestSuite\TestCase $test )
Truncates the fixtures tables
Parameters
-
Cake\TestSuite\TestCase
$test
- The test to inspect for fixture unloading.
Properties detail
$_debugsource
protected boolean
Is the test runner being run with --debug
enabled. When true, fixture SQL will also be logged.
false
$_fixtureMapsource
protected Cake\Datasource\FixtureInterface[]
Holds the fixture classes that where instantiated indexed by class name
[]
$_loadedsource
protected Cake\Datasource\FixtureInterface[]
Holds the fixture classes that where instantiated
[]
© 2005–2017 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.
https://api.cakephp.org/3.4/class-Cake.TestSuite.Fixture.FixtureManager.html