Skip to content

Commit

Permalink
Version12
Browse files Browse the repository at this point in the history
Adding steps for checking dimensions and exits are available. These
weren't explicit in our initial conversation but through working through
the model and subsequent (ok fake in this case) conversations with the
client it's now apparant that dimensions and exits are part of this
model. In true DDD style, making the implicit, explicit.
  • Loading branch information
jenkoian committed Jan 20, 2015
1 parent a81431f commit 802936f
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 12 deletions.
15 changes: 11 additions & 4 deletions features/navigating-house.feature
@@ -1,15 +1,22 @@
@home-owner @potential-buyer
Feature: Navigating the house
Feature: Home owner navigating the house

Scenario: Entering the house
Given I am in the "front garden"
When I enter through the front door
Then I should be in the "hallway"

Scenario: Getting room info
Given I am in the "hallway"
Given there are the following locations in the house
| name | type | width | height |
| front garden | garden | 300 | 300 |
| hallway | room | 300 | 300 |
| living room | room | 300 | 300 |
| kitchen | room | 300 | 300 |
And I am in the "hallway"
When I request room info
Then I should have dimensions and exits
Then I should have dimensions "300 x 300"
And I should have exits

Scenario: Leaving the house
Given I am in the "hallway"
Expand All @@ -28,4 +35,4 @@ Feature: Navigating the house

Scenario: Entering a room that doesn't exist
Given I am in the "hallway"
Then I should not be able to enter the "made up" room
Then I should not be able to enter the "made up" room
11 changes: 11 additions & 0 deletions spec/Jenko/House/GardenSpec.php
Expand Up @@ -16,6 +16,7 @@ function let()
function it_is_initializable()
{
$this->shouldHaveType('Jenko\House\Garden');
$this->shouldHaveType('Jenko\House\Location');
}

function it_should_be_created_with_a_name()
Expand All @@ -37,4 +38,14 @@ function it_should_be_able_to_set_dimensions()

$this->getDimensions()->shouldEqual($dimensions);
}

function it_should_have_information_on_dimensions()
{
$dimensions = Dimensions::fromWidthAndHeight(350, 300);
$this->setDimensions($dimensions);

$info = $this->getInformation();

$info['dimensions']->shouldBe('350 x 300');
}
}
11 changes: 11 additions & 0 deletions spec/Jenko/House/RoomSpec.php
Expand Up @@ -16,6 +16,7 @@ function let()
function it_is_initializable()
{
$this->shouldHaveType('Jenko\House\Room');
$this->shouldHaveType('Jenko\House\Location');
}

function it_should_be_created_with_a_name()
Expand All @@ -37,4 +38,14 @@ function it_should_be_able_to_set_dimensions()

$this->getDimensions()->shouldEqual($dimensions);
}

function it_should_have_information_on_dimensions()
{
$dimensions = Dimensions::fromWidthAndHeight(350, 300);
$this->setDimensions($dimensions);

$info = $this->getInformation();

$info['dimensions']->shouldBe('350 x 300');
}
}
8 changes: 8 additions & 0 deletions src/Jenko/House/Dimensions.php
Expand Up @@ -65,4 +65,12 @@ public function getHeight()
{
return $this->height;
}

/**
* @return string
*/
public function __toString()
{
return $this->getWidth() . ' x ' . $this->getHeight();
}
}
2 changes: 1 addition & 1 deletion src/Jenko/House/Location.php
Expand Up @@ -35,7 +35,7 @@ public function getName()
*/
public function getInformation()
{
return ['dimensions' => '', 'exits' => ''];
return ['dimensions' => (string)$this->getDimensions(), 'exits' => ''];
}

/**
Expand Down
29 changes: 22 additions & 7 deletions tests/contexts/HomeOwnerContext.php
@@ -1,5 +1,6 @@
<?php

use Behat\Behat\Tester\Exception\PendingException;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\TableNode;
Expand Down Expand Up @@ -29,13 +30,7 @@ public function __construct()
*/
public function iAmInThe($location)
{
if (false !== strpos($location, 'garden')) {
$location = Room::named($location);
} else {
$location = Garden::named($location);
}

$this->house->setLocation($location);
$this->iEnterTheRoom($location);
}

/**
Expand Down Expand Up @@ -134,4 +129,24 @@ public function iShouldNotBeAbleToEnterTheRoom($roomName)
return true;
}
}

/**
* @Then I should have dimensions :dimensions
*/
public function iShouldHaveDimensions($dimensions)
{
$information = $this->house->whereAmI()->getInformation();

PHPUnit_Framework_Assert::assertArrayHasKey('dimensions', $information);
PHPUnit_Framework_Assert::assertEquals($dimensions, $information['dimensions']);
}

/**
* @Then I should have exits
*/
public function iShouldHaveExits()
{
$information = $this->house->whereAmI()->getInformation();
PHPUnit_Framework_Assert::assertArrayHasKey('exits', $information);
}
}

0 comments on commit 802936f

Please sign in to comment.