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 4.6 Strawberry API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 4.6
      • 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
    • Auth
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
      • Constraint
      • Fixture
      • Stub
    • Utility
    • Validation
    • View

Class SchemaLoader

Create test database schema from one or more SQL dump files.

This class can be useful to create test database schema when your schema is managed by tools external to your CakePHP application.

It is not well suited for applications/plugins that need to support multiple database platforms. You should use migrations for that instead.

Namespace: Cake\TestSuite\Fixture

Property Summary

  • $helper protected
    Cake\TestSuite\ConnectionHelper

Method Summary

  • __construct() public

    Constructor.

  • loadInternalFile() public

    Load and apply CakePHP schema file.

  • loadSqlFiles() public

    Load and apply schema sql file, or an array of files.

Method Detail

__construct() ¶ public

__construct()

Constructor.

loadInternalFile() ¶ public

loadInternalFile(string $file, string $connectionName = 'test'): void

Load and apply CakePHP schema file.

This method will process the array returned by $file and treat the contents as a list of table schema.

An example table is:

return [
  'articles' => [
     'columns' => [
         'id' => [
             'type' => 'integer',
         ],
         'author_id' => [
             'type' => 'integer',
             'null' => true,
         ],
         'title' => [
             'type' => 'string',
             'null' => true,
         ],
         'body' => 'text',
         'published' => [
             'type' => 'string',
             'length' => 1,
             'default' => 'N',
         ],
     ],
     'constraints' => [
         'primary' => [
             'type' => 'primary',
             'columns' => [
                 'id',
             ],
         ],
     ],
  ],
];

This schema format can be useful for plugins that want to include tables to test against but don't need to include production ready schema via migrations. Applications should favour using migrations or SQL dump files over this format for ease of maintenance.

A more complete example can be found in tests/schema.php.

Parameters
string $file

Schema file

string $connectionName optional

Connection name

Returns
void
Throws
InvalidArgumentException
For missing table name(s).

loadSqlFiles() ¶ public

loadSqlFiles(array<string>|string $paths, string $connectionName = 'test', bool $dropTables = true, bool $truncateTables = false): void

Load and apply schema sql file, or an array of files.

Parameters
array<string>|string $paths

Schema files to load

string $connectionName optional

Connection name

bool $dropTables optional

Drop all tables prior to loading schema files

bool $truncateTables optional

Truncate all tables after loading schema files

Returns
void

Property Detail

$helper ¶ protected

Type
Cake\TestSuite\ConnectionHelper
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