Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
[![Latest Stable Version](https://img.shields.io/packagist/v/FriendsOfCake/fixturize.svg?style=flat-square)](https://packagist.org/packages/FriendsOfCake/fixturize)

# Introduction

The fixturize plugin will help improve performance of your fixture based tests.

This plugin currently only work with MySQL/MariaDB/Percona databases.

# Installation

```
composer require friendsofcake/fixturize
```

# Introduction
Load the plugin in ``Application::bootstrap``, if you want to use the [themed Bake template](#themed-bake-template):

The fixturize plugin will help improve performance of your fixture based tests.

This plugin currently only work with MySQL/MariaDB/Percona databases.
```` php
if (PHP_SAPI === 'cli') {
try {
$this->addPlugin('FriendsOfCake/Fixturize');
} catch (MissingPluginException $e) {
// Do not halt if the plugin is missing
}
}
````

# Usage

Expand Down Expand Up @@ -50,3 +62,16 @@ Re-run your tests and enjoy the speed!
</table>

Feel free to submit your own results above.

# Themed Bake Template

To use the built-in [themed Bake template](https://book.cakephp.org/bake/2/en/development.html#creating-a-bake-theme),
execute:

```` bash
php bin/cake.php bake fixture ModelName --theme FriendsOfCake/Fixturize
````

Make sure, you have [loaded the plugin](#installation).

For more information, see the [Bake documentation](https://book.cakephp.org/bake/2/en/index.html).
72 changes: 72 additions & 0 deletions templates/bake/tests/fixture.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{#
/**
* Fixture Template file
*
* Fixture Template used when baking fixtures with bake
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 2.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
#}
<?php
namespace {{ namespace }}\Test\Fixture;

use FriendsOfCake\Fixturize\TestSuite\Fixture\ChecksumTestFixture as TestFixture;

/**
* {{ name }}Fixture
*/
class {{ name }}Fixture extends TestFixture
{
{% if table %}
/**
* Table name
*
* @var string
*/
public $table = '{{ table|raw }}';
{% endif %}

{%- if import %}
/**
* Import
*
* @var array
*/
public $import = {{ import|raw }};

{% endif %}

{%- if schema %}
/**
* Fields
*
* @var array
*/
// @codingStandardsIgnoreStart
public $fields = {{ schema|raw }};
// @codingStandardsIgnoreEnd
{% endif %}

{%- if records %}
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = {{ records|raw }};
parent::init();
}
{% endif %}
}