sfEnvironmentFixturesPlugin - 0.1.0

Provides support for defining additional fixtures for each symfony environment.

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
Show source

sfEnvironmentFixturesPlugin

The sfEnvironmentFixturesPlugin is a symfony plugin that provides support for defining additional fixtures for each symfony environment.

The plugin does so in such a way that any symfony task which internally uses the data-load task will function in the same way.

Installation

  • Install the plugin (via a package):

    $ symfony plugin:install sfEnvironmentFixturesPlugin-0.1.0a
    
  • Install the plugin (via a Subversion checkout):

    $ svn co http://svn.symfony-project.com/plugins/sfEnvironmentFixturesPlugin/branches/0.1/ plugins/sfEnvironmentFixturesPlugin
    
  • Enable the plugin in config/ProjectConfiguration.class.php:

    class ProjectConfiguration extends sfProjectConfiguration
    {
      public function setup()
      {
        $this->enablePlugins(array(
          'sfEnvironmentFixturesPlugin',
        ));
      }
    }
    

Usage

The plugin will search the data directory (usually data) for a sub-directory that follows the naming convention:

fixtures_<environment name>

For example, when running in the dev environment, fixtures will be loaded from data/fixtures_dev.

Simply place the fixture files in the corresponding directories and they will be loaded any time the data-load task is invoked.

You should see output similar to the following:

>> doctrine  Loading data fixtures from "/path/to/project/data/fixtures"
>> fixtures  Loading data fixtures for environment "dev"
>> fixtures  Loading data fixtures from "/path/to/project/data/fixtures_dev"
>> doctrine  Data was successfully loaded

Important points

  • The default environment for the data-load task is dev, so unless you specify an environment with the --env option, fixtures in the fixtures_dev directory will be loaded, which could be very bad in a production environment.

  • Fixtures are always loaded from the main fixtures directory regardless of the current environment.

  • Record labels must be unique across the main fixtures directory and the environment-specific one. This is because...

  • Environment-specific fixtures can still reference records in the main fixture file by label, making references easy to set up.

  • Fixtures are loaded in a recursive manner similar to the main fixtures directory, meaning you can have fixtures in subdirectories if you so desire.

  • Fixtures can still contain PHP code.

NOTE: This plugin has only been tested under Doctrine, however there is nothing Doctrine-specific about the plugin, so it should also work fine for Propel. If you have success or problems using this with Propel, please let me know.