Skip to content

Commit

Permalink
Most of the datasource abstraction is completed with this commit.
Browse files Browse the repository at this point in the history
A seperate datasource interface is defined and a concrete Doctrine datasource  implimentation is created.
This is now utilized by the main phabric tests and all tests and behat features have been updated.
  • Loading branch information
benwaine committed Aug 22, 2011
1 parent 0e09a96 commit 1566e23
Show file tree
Hide file tree
Showing 13 changed files with 805 additions and 213 deletions.
77 changes: 56 additions & 21 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,14 @@ Setting Up Phabric
Phabric requires some setting up in the main feature context file of your behat
tests folder.

Phabric makes use of the Doctrine DBAL. This allows support for many databases
'out of the box'. Most popular databases are supported including MySQL, Oracle
and MSSQL.
Phabric requires a datasource to persist Gherkin tabkes to. Usually this is a
relational database. Phabric ships with a Doctrine DBAL adapter.
This allows support for many databases 'out of the box'. Most popular databases
are supported including MySQL, Oracle and MSSQL.

If you wish to support non relational databases or databases that Donctrine does
not support you can do so by writting an adapter and implementing Phabrics
'IDatasource' interface.

**Autoloading**
Classes are loaded using the Doctrine Projects autoloader.
Expand Down Expand Up @@ -193,9 +198,13 @@ public function __construct(array $parameters) {

```

A Doctrine DBAL connection (database connection class) needs to be created and injected into the Phabric object,
this class manages your interactions with Phabric. Database connection parameters
should be added to your behat.yml config file.
A Doctrine DBAL connection (database connection class) needs to be created and
injected into a Phabric datasource object, this class manages interactions with
the datasource.
Database connection parameters should be added to your behat.yml config file.
Also some basic meta data is inut about the 'entities' we wish to map.
An entity is a Gherkin to DB table mapping, this is discussed further in
later sections.

``` yaml
default:
Expand All @@ -208,9 +217,35 @@ default:
dbname: 'behat-demo'
host: '127.0.0.1'
driver: 'pdo_mysql'
Phabric:
entities:
event:
tableName: 'event'
primaryKey: 'id'
nameCol: 'name'
session:
tableName: 'session'
primaryKey: 'id'
nameCol: 'session_code'
attendee:
tableName: 'attendee'
primaryKey: 'id'
nameCol: 'name'
vote:
tableName: 'vote'
primaryKey: 'id'
nameCol: null

```

**NB** Note that some basic table meta data is required in the Phabric section
of the behat.yml file. tableName, primaryKey and nameCol.

* tableName: The name of the table to nbe mapped eg 'event'
* primaryKey: the name of the primary key column eg 'id'
* nameCol: this is a column used to identify a piece of data inserted by phabric.
It can be any column in the database but should be unique. eg 'PHPNW'

Creating the DBAL Connections and setting it as the database connection used by
Phabric:

Expand All @@ -220,20 +255,20 @@ Phabric:
protected $phabric;

public function __construct(array $parameters) {

$config = new \Doctrine\DBAL\Configuration();

self::$db = \Doctrine\DBAL\DriverManager::getConnection(array(
'dbname' => $parameters['database']['dbname'],
'user' => $parameters['database']['username'],
'password' => $parameters['database']['password'],
'host' => $parameters['database']['host'],
'driver' => $parameters['database']['driver'],
));



$this->phabric = new Phabric\Phabric(self::$db);
$config = new \Doctrine\DBAL\Configuration();

self::$db = \Doctrine\DBAL\DriverManager::getConnection(array(
'dbname' => $parameters['database']['dbname'],
'user' => $parameters['database']['username'],
'password' => $parameters['database']['password'],
'host' => $parameters['database']['host'],
'driver' => $parameters['database']['driver'],
));
$datasource = new \Phabric\Datasource\Doctrine(self::$db, $parameters['Phabric']['entities']);
$this->phabric = new Phabric\Phabric($datasource);

}

Expand All @@ -249,7 +284,7 @@ The Phabric Class

The Phabric object handles interaction with all the 'entities' (Gherkin table >
db table mappings) created when using Phabric.
It accepts a database connection as it's only argument. It should be created in
It accepts a datasource as it's only argument. It should be created in
the constructor of the FeatureContext class and saved to a member variable (as
in the example above).

Expand Down
Binary file added docs/Phabric Intro.doc
Binary file not shown.
14 changes: 7 additions & 7 deletions examples/features/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ default:
event:
tableName: 'event'
primaryKey: 'id'
entityName: 'Event'
nameCol: 'name'
nameTransformations:
Date: datetime
Desc: description
Expand All @@ -27,20 +27,20 @@ default:
session:
tableName: 'session'
primaryKey: 'id'
entityName: 'Session'
nameCol: 'session_code'
nameTransformations:
Session Code: session_code
attendee:
tableName: 'attendee'
primaryKey: 'id'
entityName: 'Attendee'
primaryKey: 'id'
nameCol: 'name'
vote:
tableName: 'vote'
primaryKey: 'id'
entityName: 'Vote'
primaryKey: 'id'
nameCol: null
nameTransformations:
Attendee: attendee_id
Session: session_id
Session Code: session_id
dataTransformations:
attendee_id: ATTENDEELOOKUP
session_id: SESSIONLOOKUP
Expand Down
4 changes: 3 additions & 1 deletion examples/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ public function __construct(array $parameters) {
'host' => $parameters['database']['host'],
'driver' => $parameters['database']['driver'],
));

$datasource = new \Phabric\Datasource\Doctrine(self::$db, $parameters['Phabric']['entities']);

$this->phabric = new Phabric(self::$db);
$this->phabric = new Phabric($datasource);

$this->phabric->createEntitiesFromConfig($parameters['Phabric']['entities']);

Expand Down
18 changes: 9 additions & 9 deletions examples/features/releational-data.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ Feature: Phabric Example
Scenario:
Given the following sessions exist
| Session Code | name | time | description |
| BDD | BDD with behat | 12:50 | Test driven behaviour development is cool |
| CI | Continous Integration | 13:30 | Integrate this! |
| BDD | BDD with behat | 12:50 | Test driven behaviour development is cool |
| CI | Continous Integration | 13:30 | Integrate this! |
And the following attendees exist
| name |
| Jack The Lad |
| Simple Simon |
| Peter Pan |
And the following votes exist
| Attendee | Session | Vote |
| Jack The Lad | BDD | UP |
| Simple Simon | BDD | UP |
| Peter Pan | BDD | UP |
| Jack The Lad | CI | UP |
| Simple Simon | CI | UP |
| Peter Pan | CI | DOWN |
| Attendee | Session Code | Vote |
| Jack The Lad | BDD | UP |
| Simple Simon | BDD | UP |
| Peter Pan | BDD | UP |
| Jack The Lad | CI | UP |
| Simple Simon | CI | UP |
| Peter Pan | CI | DOWN |
Then the session "BDD" should have a score of 3
And the session "CI" should have a score of 1

Expand Down
8 changes: 4 additions & 4 deletions examples/features/reset-fixture.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Feature: Phabric Example
As a Phabric user I want to be able to update entries previously inserted
by Phabric.
As a Phabric user I want to be able to reset all previous inserts and
updates on a fixture.

Scenario: Data has only been inserted by Phabric
Scenario: Data that has only been inserted by Phabric is reset correctly
Given The following events exist
| Name | Date | Venue | Desc |
| PHPNW | 08/10/2011 09:00 | Ramada Hotel | An awesome conf! |
Expand All @@ -16,7 +16,7 @@ Scenario: Data has only been inserted by Phabric
Then there sould be not data in the "event" table


Scenario: Data has been inserted and updated by phabric
Scenario: Data that has been inserted and updated by phabric is reset correctly
Given The following events exist
| Name | Date | Venue | Desc |
| PHPNW | 08/10/2011 09:00 | Ramada Hotel | An awesome conf! |
Expand Down
Loading

1 comment on commit 1566e23

@glenjamin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The verify functions are acting somewhat like assert lines, except you end up duplicating the exception messages in the caller.

It's also probably worth firming up the interface for select and delete, and maybe some rough docs for implementing your own datasource (including how there's no reason you couldn't have a data source which hits an external API or actually fills in forms on your front end). I'd have the Doctrine DBAL source throw NotImplemented for the methods currently not supported in the mean-time.

Please sign in to comment.