Skip to content

Commit

Permalink
Changed the 'createFromTable' method to 'insertFromTable' in preperat…
Browse files Browse the repository at this point in the history
…ion for implimenting the 'updateFromTable' method.

Also removed references to phabricBus in the examples and documentation.
  • Loading branch information
benwaine committed Aug 16, 2011
1 parent 56542fe commit 3d2ac6a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 52 deletions.
40 changes: 20 additions & 20 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ The step:
*/
public function theFollowingEventsExist(TableNode $table) {

$this->phabricBus->createFromTable('event', $table);
$this->phabric->insertFromTable('event', $table);
}

```
Expand Down Expand Up @@ -217,7 +217,7 @@ Phabric:
``` php
<?php

protected $phabricBus;
protected $phabric;

public function __construct(array $parameters) {

Expand All @@ -233,7 +233,7 @@ public function __construct(array $parameters) {



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

}

Expand Down Expand Up @@ -271,7 +271,7 @@ Programmatically:
<?php

// Note: no second config parameter passed
$event = $this->phabricBus->createEntity('event');
$event = $this->phabric->createEntity('event');

$event->setTableName('event');

Expand All @@ -285,7 +285,7 @@ And Using configuration:

// Note: The config array is pulled from the $parameters argument passed
// into the FeatureContext constructor method.
$this->phabricBus->createEntity('event', $parameters['Phabric']['entities']['event']);
$this->phabric->createEntity('event', $parameters['Phabric']['entities']['event']);

```

Expand Down Expand Up @@ -346,7 +346,7 @@ With the Phabric object set up you can now obtain Phabric entity instances like
``` php
<?php

$event = $this->phabricBus->createEntity('event', $config);
$event = $this->phabric->createEntity('event', $config);

```

Expand All @@ -373,7 +373,7 @@ First create an entity:

<?php

$event = $this->phabricBus->createEntity('event', $config);
$event = $this->phabric->createEntity('event', $config);

```

Expand Down Expand Up @@ -419,7 +419,7 @@ The closure accepts the data from a column and returns its translated form.
``` php
<?php

$this->phabricBus->addDataTransformation(
$this->phabric->addDataTransformation(
'UKTOMYSQLDATE', function($date) {
$date = \DateTime::createFromFormat('d/m/Y H:i', $date);
return $date->format('Y-m-d H:i:s');
Expand Down Expand Up @@ -482,7 +482,7 @@ with a data transformation) and include the column in the Gherkin table.
'Displayed' => 'ev_disp'
));

$this->phabricBus->addDataTransformation(
$this->phabric->addDataTransformation(
'YESNOFLAG', function($ynFlag) {
switch($ynFlag) {
case 'YES':
Expand Down Expand Up @@ -549,9 +549,9 @@ And in the corresponding Behat step:
public function theFollowingEventsExist(TableNode $table) {

// With an entity previously configured just pass it's name and
// the table node tot the 'createFromTable' method on the Phabric
// the table node to the 'insertFromTable' method on the Phabric
//object.
$this->phabricBus->createFromTable('event', $table);
$this->phabric->insertFromTable('event', $table);
}

```
Expand Down Expand Up @@ -618,7 +618,7 @@ Attendee names and session names with there ID's:

<?php

$this->phabricBus->addDataTransformation(
$this->phabric->addDataTransformation(
'ATTENDEELOOKUP', function($attendeeName, $bus) {
$ent = $bus->getEntity('attendee');

Expand All @@ -627,7 +627,7 @@ $this->phabricBus->addDataTransformation(
return $id;
});

$this->phabricBus->addDataTransformation(
$this->phabric->addDataTransformation(
'SESSIONLOOKUP', function($sessionName, $bus) {
$ent = $bus->getEntity('session');

Expand Down Expand Up @@ -662,8 +662,8 @@ The create() method is used as in the previous example:
*/
public function theFollowingVotesExist(TableNode $table)
{
$attePh = $this->phabricBus->getEntity('vote');
$attePh->createFromTable($table);
$attePh = $this->phabric->getEntity('vote');
$attePh->insertFromTable($table);
}

```
Expand Down Expand Up @@ -738,10 +738,10 @@ In the constructor of the FeatureContext class:
``` php
<?php

$event = $this->phabricBus->createEntity('event', $parameters['Phabric']['entities']['event']);
$attendee = $this->phabricBus->createEntity('attendee', $parameters['Phabric']['entities']['attendee']);
$session = $this->phabricBus->createEntity('session', $parameters['Phabric']['entities']['session']);
$vote = $this->phabricBus->createEntity('vote', $parameters['Phabric']['entities']['vote']);
$event = $this->phabric->createEntity('event', $parameters['Phabric']['entities']['event']);
$attendee = $this->phabric->createEntity('attendee', $parameters['Phabric']['entities']['attendee']);
$session = $this->phabric->createEntity('session', $parameters['Phabric']['entities']['session']);
$vote = $this->phabric->createEntity('vote', $parameters['Phabric']['entities']['vote']);

```

Expand All @@ -751,7 +751,7 @@ retrieved in step methods by using the bus:
```php
<?php

$eventPh = $this->phabricBus->getEntity('event');
$eventPh = $this->phabric->getEntity('event');

```

Expand Down
30 changes: 15 additions & 15 deletions examples/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class FeatureContext extends BehatContext {
*
* @var Phabric\Bus
*/
private $phabricBus;
private $phabric;

/**
* The Databse Connection.
Expand All @@ -61,21 +61,21 @@ public function __construct(array $parameters) {
'driver' => $parameters['database']['driver'],
));

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

$event = $this->phabricBus->createEntity('event', $parameters['Phabric']['entities']['event']);
$attendee = $this->phabricBus->createEntity('attendee', $parameters['Phabric']['entities']['attendee']);
$session = $this->phabricBus->createEntity('session', $parameters['Phabric']['entities']['session']);
$vote = $this->phabricBus->createEntity('vote', $parameters['Phabric']['entities']['vote']);
$event = $this->phabric->createEntity('event', $parameters['Phabric']['entities']['event']);
$attendee = $this->phabric->createEntity('attendee', $parameters['Phabric']['entities']['attendee']);
$session = $this->phabric->createEntity('session', $parameters['Phabric']['entities']['session']);
$vote = $this->phabric->createEntity('vote', $parameters['Phabric']['entities']['vote']);

$this->phabricBus->addDataTransformation(
$this->phabric->addDataTransformation(
'UKTOMYSQLDATE', function($date) {
$date = \DateTime::createFromFormat('d/m/Y H:i', $date);
return $date->format('Y-m-d H:i:s');
}
);

$this->phabricBus->addDataTransformation(
$this->phabric->addDataTransformation(
'ATTENDEELOOKUP', function($attendeeName, $bus) {
$ent = $bus->getEntity('attendee');

Expand All @@ -84,7 +84,7 @@ public function __construct(array $parameters) {
return $id;
});

$this->phabricBus->addDataTransformation(
$this->phabric->addDataTransformation(
'SESSIONLOOKUP', function($sessionName, $bus) {
$ent = $bus->getEntity('session');

Expand All @@ -93,7 +93,7 @@ public function __construct(array $parameters) {
return $id;
});

$this->phabricBus->addDataTransformation(
$this->phabric->addDataTransformation(
'UPDOWNTOINT', function($action) {
$action = strtoupper($action);
switch ($action) {
Expand Down Expand Up @@ -127,7 +127,7 @@ public static function prepare(SuiteEvent $event) {
* @Given /^The following events exist$/
*/
public function theFollowingEventsExist(TableNode $table) {
$this->phabricBus->createFromTable('event', $table);
$this->phabric->insertFromTable('event', $table);
}

/**
Expand Down Expand Up @@ -170,31 +170,31 @@ public function iShouldSeeTheFollowingRecords(TableNode $table) {
*/
public function theFollowingSessionsExist(TableNode $table)
{
$this->phabricBus->createFromTable('session', $table);
$this->phabric->insertFromTable('session', $table);
}

/**
* @Given /^the following attendees exist$/
*/
public function theFollowingAttendeesExist(TableNode $table)
{
$this->phabricBus->createFromTable('attendee', $table);
$this->phabric->insertFromTable('attendee', $table);
}

/**
* @Given /^the following votes exist$/
*/
public function theFollowingVotesExist(TableNode $table)
{
$this->phabricBus->createFromTable('vote', $table);
$this->phabric->insertFromTable('vote', $table);
}

/**
* @Then /^the session "([^"]*)" should have a score of (\d+)$/
*/
public function theSessionShouldHaveAScoreOf($session, $score)
{
$sesPh = $this->phabricBus->getEntity('session');
$sesPh = $this->phabric->getEntity('session');
$sessionId = $sesPh->getNamedItemId($session);

$sql = 'SELECT sum(vote) as votes FROM vote WHERE session_id = :id';
Expand Down
2 changes: 1 addition & 1 deletion lib/Phabric/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function setDataTransformations($transformations)
*
* @return void
*/
public function createFromTable(TableNode $table, $defaultFlag = true)
public function insertFromTable(TableNode $table, $defaultFlag = true)
{

$data = $table->getRows();
Expand Down
4 changes: 2 additions & 2 deletions lib/Phabric/Phabric.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ public function getEntity($name)
* @param boolean $default Determines if default data values should be applied.
*
*/
public function createFromTable($entityName, TableNode $table, $default = null)
public function insertFromTable($entityName, TableNode $table, $default = null)
{
$entity = $this->getEntity($entityName);

if($entity instanceof Entity)
{
return $entity->createFromTable($table, $default);
return $entity->insertFromTable($table, $default);
}
else
{
Expand Down
22 changes: 11 additions & 11 deletions tests/lib/Phabric/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function tearDown() {
m::close();
}

public function testCreate() {
public function testInsertFromTable() {
$tableData = array(
array('name', 'datetime', 'venue', 'description'),
array('PHPNW', '2011-10-08 09:00:00', 'Ramada Hotel', 'A Great Conf!')
Expand All @@ -66,10 +66,10 @@ public function testCreate() {

$this->object->setTableName('Event');

$this->object->createFromTable($tableNode);
$this->object->insertFromTable($tableNode);
}

public function testCreateWithNameTransformations() {
public function testInsertFromTableWithNameTransformations() {
$tableData = array(
array('Name', 'Date', 'Venue', 'Desc'),
array('PHPNW', '2011-10-08 09:00:00', 'Ramada Hotel', 'A Great Conf!')
Expand All @@ -94,10 +94,10 @@ public function testCreateWithNameTransformations() {
$this->object->setNameTransformations(array('Date' => 'datetime',
'Desc' => 'description'));

$this->object->createFromTable($tableNode);
$this->object->insertFromTable($tableNode);
}

public function testCreateWithDefaults() {
public function testInsertFromTableWithDefaults() {
$tableData = array(
array('name', 'datetime', 'venue'),
array('PHPNW', '2011-10-08 09:00:00', 'Ramada Hotel')
Expand All @@ -124,10 +124,10 @@ public function testCreateWithDefaults() {
'venue' => 'TEST VENUE'
));

$this->object->createFromTable($tableNode);
$this->object->insertFromTable($tableNode);
}

public function testCreateWithDataTransformations() {
public function testInsertFromTableWithDataTransformations() {

$tableData = array(
array('name', 'datetime', 'venue', 'description'),
Expand Down Expand Up @@ -164,10 +164,10 @@ public function testCreateWithDataTransformations() {

$this->object->setDataTransformations(array('datetime' => 'UKTOMYSQLDATE'));

$this->object->createFromTable($tableNode);
$this->object->insertFromTable($tableNode);
}

public function testCreateWithMultipleFeaturesEnabled() {
public function testInsertFromTableWithMultipleFeaturesEnabled() {
$tableData = array(
array('Name', 'Date', 'Venue'),
array('PHPNW', '08/10/2011 09:00', 'Ramada Hotel')
Expand Down Expand Up @@ -208,7 +208,7 @@ public function testCreateWithMultipleFeaturesEnabled() {

$this->object->setDataTransformations(array('datetime' => 'UKTOMYSQLDATE'));

$this->object->createFromTable($tableNode);
$this->object->insertFromTable($tableNode);
}

public function testGetNamedItemId() {
Expand All @@ -234,7 +234,7 @@ public function testGetNamedItemId() {

$this->object->setTableName('Event');

$this->object->createFromTable($tableNode);
$this->object->insertFromTable($tableNode);

$this->assertInternalType('integer', $this->object->getNamedItemId('PHPNW'));
$this->assertEquals(12, $this->object->getNamedItemId('PHPNW'));
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/Phabric/PhabricTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function testGetEntityNotFound()
$this->object->getEntity('anything');
}

public function testCreateFromTable()
public function testInsertFromTable()
{
$tableData = array(
array('name', 'datetime', 'venue', 'description'),
Expand All @@ -106,13 +106,13 @@ public function testCreateFromTable()

$mockEntity = m::mock('\Phabric\Entity');

$mockEntity->shouldReceive('createFromTable')
$mockEntity->shouldReceive('insertFromTable')
->with($tableNode, null)
->once();

$this->object->addEntity('TEST', $mockEntity);

$this->object->createFromTable('TEST', $tableNode);
$this->object->insertFromTable('TEST', $tableNode);

}

Expand Down

0 comments on commit 3d2ac6a

Please sign in to comment.