Permalink
Browse files

Version5

Some further refactoring of the models basically following the Red ->
Green -> Refactor loop at this point.
  • Loading branch information...
jenkoian committed Oct 6, 2014
1 parent 5661411 commit 3dab522b244512d6fbfad70d27d947819d9c16b2
@@ -15,6 +15,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()
@@ -37,4 +37,12 @@ function it_should_build_with_locations()
$house->shouldHaveType('Jenko\House\House');
$house->getLocations()->shouldEqual($locations);
}
function it_should_set_location()
{
$location = Room::named('garage');
$this->setLocation($location);
$this->whereAmI()->shouldBe($location);
}
}
@@ -15,6 +15,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()
View
@@ -2,21 +2,8 @@
namespace Jenko\House;
final class Garden
final class Garden extends Location
{
/**
* @var string
*/
private $name;
/**
* @param string $name
*/
private function __construct($name)
{
$this->name = $name;
}
/**
* @param string $name
* @return Room
@@ -25,12 +12,4 @@ public static function named($name)
{
return new Garden($name);
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
}
View
@@ -9,6 +9,11 @@
*/
private $locations;
/**
* @var Location
*/
private $currentLocation;
/**
* @param array $locations
*/
@@ -33,4 +38,23 @@ public function getLocations()
{
return $this->locations;
}
/**
* @param Location $location
* @return $this
*/
public function setLocation(Location $location)
{
$this->currentLocation = $location;
return $this;
}
/**
* @return Location
*/
public function whereAmI()
{
return $this->currentLocation;
}
}
@@ -0,0 +1,27 @@
<?php
namespace Jenko\House;
abstract class Location
{
/**
* @var string
*/
private $name;
/**
* @param string $name
*/
protected function __construct($name)
{
$this->name = $name;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
}
View
@@ -2,21 +2,8 @@
namespace Jenko\House;
final class Room
final class Room extends Location
{
/**
* @var string
*/
private $name;
/**
* @param string $name
*/
private function __construct($name)
{
$this->name = $name;
}
/**
* @param string $name
* @return Room
@@ -25,12 +12,4 @@ public static function named($name)
{
return new Room($name);
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
}

0 comments on commit 3dab522

Please sign in to comment.