PHPackages                             phabric/phabric - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. phabric/phabric

ActiveLibrary[Testing &amp; Quality](/categories/testing)

phabric/phabric
===============

A DB mockup / fixture creation library for Behat

05.2k1PHP

Since Mar 8Pushed 13y ago2 watchersCompare

[ Source](https://github.com/hoborglabs/Phabric)[ Packagist](https://packagist.org/packages/phabric/phabric)[ RSS](/packages/phabric-phabric/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (3)Used By (1)

Phabric
=======

[](#phabric)

[![Build Status](https://camo.githubusercontent.com/a3ca3b4ec1cd743e9648d64bc659f7bff12dd41c2441c5175b241c306e94904f/687474703a2f2f636930312e686f626f72676c6162732e636f6d2f6a656e6b696e732f6a6f622f506861627269632f62616467652f69636f6e)](http://ci01.hoborglabs.com/jenkins/job/Phabric/)

A tool that translates Gherkin Tables into database inserts / updates.

It's for use with the BDD library Behat which can be found at:

The aim of this project is to allow the user to define fixtures 'on the fly' using Gherkin tables without having to undergo the painful process of maintaining an SQL file used to drive Behat test suites.

Introduction
============

[](#introduction)

When adopting Behat at the company I work for we quickly found that in order to write clear tests we needed to set the state of the database in scenarios rather than in monolithic fixture files.

Problems with fixture files:

- They are difficult to maintain
- It's easy to wreck an existing test by modifying it's data in the fixture
- The semantics of the data are lost in the fixture file rather than being explicitly stated in a scenario.

The solution we settled on was to load an initial fixture containing just the basic DB structure and to define all the data in Gherkin tables within the scenarios of our test.

Enter Phabric...

Phabric
=======

[](#phabric-1)

Phabric allows the user to mark up data for insertion into the database in a scenario. Like So:

```
Given The following events exist
    | Name  | Date             | Venue                  | Desc             |
    | PHPNW | 08/10/2011 09:00 | Ramada Hotel           | An awesome conf! |
    | PHPUK | 27/02/2012 09:00 | London Business Center | Quite good conf. |
```

To make the data as readable as possible Phabric supports the following:

**Column Name Transformations** - You can map the name of a column in Gherkin to a database column name. EG Desc &gt; conf\_description

**Column Data Transformations** - You can translate the data in the column by registering functions. EG 08/10/2011 09:00 &gt; 2011-10-08 09:00:00

**Default Values** - You can assign default values to columns so you do not have to explicitly include them in the gherkin.

**Relational data** is supported. EG An Event with many Attendees

The aim of these features is to assist the user in setting up a scenario in a readable and maintainable way. It should facilitate behaviour driven development as once the initial creator steps have been setup anyone will be able to mark up entities in your system (testers and BAs included!).

Preview
-------

[](#preview)

The documentation below outlines how to configure and use Phabric. Here is a quick preview of whats achievable when Phabric is installed, configured and running:

The scenario:

```
Scenario:
    Given The following events exist
    | Name  | Date             | Venue                  | Desc             |
    | PHPNW | 08/10/2011 09:00 | Ramada Hotel           | An awesome conf! |
    | PHPUK | 27/02/2012 09:00 | London Business Center | Quite good conf. |
```

*Note:* The example contains name and data transformations.

The step:

```
