ishan-biztech / cakephp-fixture-factories

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CakePHP Fixture Factories

This package provides an alternative approach of managing test fixtures in a CakePHP application. The main idea is to provide fixture factories in replacement to the fixtures you can find out of the box in CakePHP.

The CakePHP Fixture Factories plugin

  • increases the speed of your tests,
  • reduces the effort of writing and maintaining tests,
  • enhances the readability of your tests: you get what you seed in your test, tests do not share test fixtures,
  • offers to manage your test DB schema with the same migrations you use on your regular DB.

You will never have to create, maintain or declare any test fixtures again.

The package is compatible with the traditional CakePHP test fixtures. You may continue using them along with the Fixture Factories, these will work just as before. It is however recommended to migrate to the Fixture Factories approach.

Here is a presentation held at the CakePHP online Meetup on 29th April 2020.

Here is a serie of videos on the present package.

Installation

For CakePHP 4.x:

composer require --dev pakacuda/cakephp-fixture-factories

For CakePHP 3.x, append: "^0.1.0"

Adjustments before using the fixture factories (1 minute). This is also illustrated, along with the usage of migrations, in this video.

Take full advantage of the Phinx migrations in order to maintain the schema of your test DB. This is optional, but highly recommended.

Load the plugin and create all your factories in one command line.

bin/cake bake fixture_factory -h

What the Fixture Factories look like, and how they can incoporate your business logic.

In this section, we'll see how to use them. Here is a quick example of persisting five articles having each three different authors, each with different addresses, in different cities, but all located in Kenya.

$article = ArticleFactory::make(5)->with('Authors[3].Address.City.Country', ['name' => 'Kenya'])->persist();

The only step performed by the package's test suite is to truncate dirty tables before each test.

License

The CakePHPFixtureFactories plugin is offered under an MIT license.

Copyright 2020 Nicolas Masson and Juan Pablo Ramirez

Licensed under The MIT License Redistributions of files must retain the above copyright notice.

Authors

  • Nicolas Masson
  • Juan Pablo Ramirez

About

License:MIT License


Languages

Language:PHP 98.3%Language:HTML 1.4%Language:Shell 0.3%