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 6.0 API

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

Class DeleteStrategy

Fixture strategy that deletes all rows from the fixture tables at the end of test.

A drop-in alternative to {@link \Cake\TestSuite\Fixture\TruncateStrategy}: fixtures are inserted before each test and the tables are emptied afterwards, without a wrapping transaction, so afterCommit listeners behave as they do in the application.

TRUNCATE is a DDL statement, and on most database servers it does more work than removing the rows - InnoDB for example drops and recreates the tablespace of every table it is issued against. Deleting the handful of rows a fixture holds is usually a lot cheaper, so test suites with many fixtures can spend noticeably less time in teardown with this strategy.

The trade off is that DELETE does not reset auto increment counters. Fixtures whose records omit their primary key, and which other fixtures or assertions then refer to by id, need that counter to start from 1 in every test and have to keep using TruncateStrategy.

Unlike TRUNCATE, DELETE is subject to foreign keys on every driver, so the rows are removed with the constraints disabled and the order of the fixtures does not matter.

Namespace: Cake\TestSuite\Fixture

Property Summary

  • $fixtures protected
    array<Cake\Datasource\FixtureInterface>
  • $helper protected
    Cake\TestSuite\Fixture\FixtureHelper

Method Summary

  • __construct() public

    Initialize strategy.

  • setupTest() public

    Called before each test run in each TestCase.

  • teardownTest() public

    Called after each test run in each TestCase.

Method Detail

__construct() ¶ public

__construct()

Initialize strategy.

setupTest() ¶ public

setupTest(array<string> $fixtureNames): void

Called before each test run in each TestCase.

Parameters
array<string> $fixtureNames
Returns
void

teardownTest() ¶ public

teardownTest(): void

Called after each test run in each TestCase.

Returns
void

Property Detail

$fixtures ¶ protected

Type
array<Cake\Datasource\FixtureInterface>

$helper ¶ protected

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