macpaw/behat-doctrine-fixtures

Bundle for creating Doctrine fixtures

Installs: 74 189

Dependents: 0

Suggesters: 0

Security: 0

Stars: 6

Watchers: 4

Forks: 2

Open Issues: 2

Type:symfony-bundle

v2.1.0 2024-02-08 13:56 UTC

This package is auto-updated.

Last update: 2024-04-08 14:18:56 UTC


README

Version Build Status Code Coverage
master CI Coverage Status
develop CI Coverage Status

Migrate from 1.x to 2.0

To migrate from 1.x to 2.0, follow our guide.

Installation

Step 1: Install Bundle

Open a command console, enter your project directory and execute:

$ composer require --dev macpaw/behat-doctrine-fixtures

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

If you use PostgreSQL database, you also need to install postgresql-client:

$ apt-get install -y postgresql-client

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            BehatDoctrineFixtures\BehatDoctrineFixturesBundle::class => ['test' => true]
        );

        // ...
    }

    // ...
}

Step 3: Create Behat Doctrine Fixtures Config:

config/packages/test/behat_doctrine_fixtures.yaml

Configurating behat database context

behat_doctrine_fixtures:
  connections:
    default:
      database_fixtures_paths:
        - <path to directory with your fixtures>

You don't need to explicitly pass database url here, since this bundle uses doctrine connection under the hood. For now, we support PostgreSQL and Sqlite databases.

If you want to use multiple databases in your project, just add one more connection under behat_doctrine_fixtures.connections with its own configuration:

behat_doctrine_fixtures:
  connections:
    default:
      database_fixtures_paths:
        - <path to directory with your fixtures>
    <secondConnectionName>:
      run_migrations_command: <customMigrationsCommand>
      database_fixtures_paths:
        - <path to directory with your fixtures>

Step 4: Configure Behat

Go to behat.yml

...
  contexts:
    - BehatDoctrineFixtures\Context\DatabaseContext
...