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

C CakePHP 5.3 Chiffon API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 5.3
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 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

Namespaces

  • Global
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
      • Constraint
      • Fixture
        • Extension
      • Stub
    • Utility
    • Validation
    • View

Class TestFixture

Cake TestFixture is responsible for building and destroying tables to be used during testing.

Namespace: Cake\TestSuite\Fixture

Property Summary

  • $_schema protected
    Cake\Database\Schema\TableSchemaInterface&Cake\Database\Schema\SqlGeneratorInterface

    The schema for this fixture.

  • $_tableLocator protected
    Cake\ORM\Locator\LocatorInterface|null

    Table locator instance

  • $connection public
    string

    Fixture Datasource

  • $defaultTable protected
    string|null

    This object's default table alias.

  • $records public
    array

    Fixture records to be inserted.

  • $strictFields protected
    bool

    Whether to be strict about invalid fields. Useful for catching typos.

  • $table public
    string

    The physical database table name to use.

  • $tableAlias public
    string

    The ORM table alias to use.

Method Summary

  • __construct() public

    Instantiate the fixture.

  • _aliasFromClass() protected

    Returns the ORM table alias using the fixture class.

  • _getRecords() protected

    Converts the internal records into data used to generate a query.

  • _schemaFromReflection() protected

    Build fixture schema directly from the datasource

  • connection() public

    Get the connection name this fixture should be inserted into.

  • fetchTable() public

    Convenience method to get a table instance.

  • getTableLocator() public

    Gets the table locator.

  • getTableSchema() public

    Returns the table schema for this fixture.

  • init() public

    Initialize the fixture.

  • insert() public

    Run before each test is executed.

  • setTableLocator() public

    Sets the table locator.

  • sourceName() public

    Get the table/collection name for this fixture.

  • truncate() public

    Truncates the current fixture.

Method Detail

__construct() ¶ public

__construct()

Instantiate the fixture.

Throws
Cake\Core\Exception\CakeException
on invalid datasource usage.

_aliasFromClass() ¶ protected

_aliasFromClass(): string

Returns the ORM table alias using the fixture class.

Uses tableize() then camelize() to respect custom Inflector rules like uninflected words.

For plugin fixtures (namespace pattern {Plugin}\Test\Fixture\), the plugin name is automatically prepended to the alias.

Returns
string

_getRecords() ¶ protected

_getRecords(): array

Converts the internal records into data used to generate a query.

Returns
array

_schemaFromReflection() ¶ protected

_schemaFromReflection(): void

Build fixture schema directly from the datasource

Returns
void
Throws
Cake\Core\Exception\CakeException
when trying to reflect a table that does not exist

connection() ¶ public

connection(): string

Get the connection name this fixture should be inserted into.

Returns
string

fetchTable() ¶ public

fetchTable(class-string<T>|string|null $alias = null, array<string, mixed> $options = []): $alias is class-string<T> ? T : \Cake\ORM\Table

Convenience method to get a table instance.

Templates
T of \Cake\ORM\Table
Parameters
class-string<T>|string|null $alias optional

The alias name you want to get. Should be in CamelCase format. If null then the value of $defaultTable property is used.

array<string, mixed> $options optional

The options you want to build the table with. If a table has already been loaded the registry options will be ignored.

Returns
$alias is class-string<T> ? T : \Cake\ORM\Table
Throws
Cake\Core\Exception\CakeException
If `$alias` argument and `$defaultTable` property both are `null`.
See Also
\Cake\ORM\TableLocator::get()

getTableLocator() ¶ public

getTableLocator(): Cake\ORM\Locator\LocatorInterface

Gets the table locator.

Returns
Cake\ORM\Locator\LocatorInterface

getTableSchema() ¶ public

getTableSchema(): Cake\Database\Schema\TableSchemaInterface&Cake\Database\Schema\SqlGeneratorInterface

Returns the table schema for this fixture.

Returns
Cake\Database\Schema\TableSchemaInterface&Cake\Database\Schema\SqlGeneratorInterface

init() ¶ public

init(): void

Initialize the fixture.

Returns
void
Throws
Cake\ORM\Exception\MissingTableClassException
When importing from a table that does not exist.

insert() ¶ public

insert(Cake\Datasource\ConnectionInterface $connection): bool

Run before each test is executed.

Should insert all the records into the test database.

Parameters
Cake\Datasource\ConnectionInterface $connection
Returns
bool

setTableLocator() ¶ public

setTableLocator(Cake\ORM\Locator\LocatorInterface $tableLocator): $this

Sets the table locator.

Parameters
Cake\ORM\Locator\LocatorInterface $tableLocator

LocatorInterface instance.

Returns
$this

sourceName() ¶ public

sourceName(): string

Get the table/collection name for this fixture.

Returns
string

truncate() ¶ public

truncate(Cake\Datasource\ConnectionInterface $connection): bool

Truncates the current fixture.

Parameters
Cake\Datasource\ConnectionInterface $connection
Returns
bool

Property Detail

$_schema ¶ protected

The schema for this fixture.

Type
Cake\Database\Schema\TableSchemaInterface&Cake\Database\Schema\SqlGeneratorInterface

$_tableLocator ¶ protected

Table locator instance

Type
Cake\ORM\Locator\LocatorInterface|null

$connection ¶ public

Fixture Datasource

Type
string

$defaultTable ¶ protected

This object's default table alias.

Type
string|null

$records ¶ public

Fixture records to be inserted.

Type
array

$strictFields ¶ protected

Whether to be strict about invalid fields. Useful for catching typos.

Type
bool

$table ¶ public

The physical database table name to use.

If set, tableAlias must initially be empty. $tableAlias will then be inflected as Inflector::camelize($table).

Type
string

$tableAlias ¶ public

The ORM table alias to use.

If set, table must initially be empty. $table will be read from the ORM table loaded via the alias.

If both table and tableAlias are empty, the alias will be inflected from the class name using tableize() then camelize() to respect custom Inflector rules. For plugin fixtures, the plugin name is automatically prepended (e.g., MyPlugin.Articles).

Type
string
OpenHub
Pingping
Linode
  • 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
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs