diff --git a/.idea/php-docker-settings.xml b/.idea/php-docker-settings.xml
new file mode 100644
index 0000000..14d87ab
--- /dev/null
+++ b/.idea/php-docker-settings.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/php-test-framework.xml b/.idea/php-test-framework.xml
new file mode 100644
index 0000000..5ff2c25
--- /dev/null
+++ b/.idea/php-test-framework.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/php.xml b/.idea/php.xml
index f6159c8..ac353f2 100644
--- a/.idea/php.xml
+++ b/.idea/php.xml
@@ -1,4 +1,89 @@
+
+
+
+
+
+
+
+
+
+
+
+ /usr/local/etc/php/conf.d/docker-php-ext-bcmath.ini, /usr/local/etc/php/conf.d/docker-php-ext-calendar.ini, /usr/local/etc/php/conf.d/docker-php-ext-exif.ini, /usr/local/etc/php/conf.d/docker-php-ext-gd.ini, /usr/local/etc/php/conf.d/docker-php-ext-imagick.ini, /usr/local/etc/php/conf.d/docker-php-ext-imap.ini, /usr/local/etc/php/conf.d/docker-php-ext-intl.ini, /usr/local/etc/php/conf.d/docker-php-ext-ldap.ini, /usr/local/etc/php/conf.d/docker-php-ext-mysqli.ini, /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini, /usr/local/etc/php/conf.d/docker-php-ext-pcntl.ini, /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini, /usr/local/etc/php/conf.d/docker-php-ext-pdo_pgsql.ini, /usr/local/etc/php/conf.d/docker-php-ext-pgsql.ini, /usr/local/etc/php/conf.d/docker-php-ext-rdkafka.ini, /usr/local/etc/php/conf.d/docker-php-ext-redis.ini, /usr/local/etc/php/conf.d/docker-php-ext-soap.ini, /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini, /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini, /usr/local/etc/php/conf.d/docker-php-ext-zip.ini, /usr/local/etc/php/conf.d/laravel.ini, /usr/local/etc/php/conf.d/opcache.ini, /usr/local/etc/php/conf.d/xdebug.ini
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Bread.php b/src/Bread.php
new file mode 100644
index 0000000..c76c5a6
--- /dev/null
+++ b/src/Bread.php
@@ -0,0 +1,10 @@
+milkPrices = $milkPrices;
+ $this->whiskyPrices = $whiskyPrices;
+ }
+
+ public function priceFor(Good $good): Pound
+ {
+ if($good->isMilk()){
+ return $this->milkPrices->current();
+ }
+
+ if($good->isWhisky()){
+ return $this->whiskyPrices->current();
+ }
}
public function sellTo(Offer $offer): Pound
{
- return new Pound(
- $offer->amount()->amount() *
+ return (new Pound(
+ $offer->amount()->amount()
+ ))
+ ->multiply(
$this->priceFor($offer->good())->amount()
);
}
diff --git a/src/Pound.php b/src/Pound.php
index 1be124e..9eb12d9 100644
--- a/src/Pound.php
+++ b/src/Pound.php
@@ -17,4 +17,9 @@ public function amount(): int
{
return $this->amount;
}
+
+ public function multiply(int $multiplier)
+ {
+ return new self($this->amount * $multiplier);
+ }
}
diff --git a/src/PriceList.php b/src/PriceList.php
index 8a6a231..cdb03c8 100644
--- a/src/PriceList.php
+++ b/src/PriceList.php
@@ -30,4 +30,16 @@ public function current(): Pound
{
return $this->prices[$this->position];
}
+
+ public function decrement(int $steps = 1)
+ {
+ $this->position -= $steps;
+ return $this->position;
+ }
+
+ public function increment(int $steps = 1)
+ {
+ $this->position += $steps;
+ return $this->position;
+ }
}
diff --git a/src/PriceListBuilder.php b/src/PriceListBuilder.php
index bc0da06..90dc407 100644
--- a/src/PriceListBuilder.php
+++ b/src/PriceListBuilder.php
@@ -3,6 +3,38 @@
final class PriceListBuilder
{
+ public function woolPrices(): PriceList
+ {
+ return PriceList::fromList(
+ new Pound(3),
+ new Pound(3),
+ new Pound(4),
+ new Pound(4),
+ new Pound(5),
+ new Pound(5),
+ new Pound(6),
+ new Pound(6),
+ new Pound(7),
+ new Pound(8)
+ );
+ }
+
+ public function grainPrices(): PriceList
+ {
+ return PriceList::fromList(
+ new Pound(3),
+ new Pound(3),
+ new Pound(4),
+ new Pound(5),
+ new Pound(6),
+ new Pound(6),
+ new Pound(7),
+ new Pound(7),
+ new Pound(8),
+ new Pound(8)
+ );
+ }
+
public function milkPrices(): PriceList
{
return PriceList::fromList(
@@ -18,4 +50,53 @@ public function milkPrices(): PriceList
new Pound(8)
);
}
+
+ public function breadPrices(): PriceList
+ {
+ return PriceList::fromList(
+ new Pound(7),
+ new Pound(8),
+ new Pound(9),
+ new Pound(10),
+ new Pound(11),
+ new Pound(11),
+ new Pound(12),
+ new Pound(13),
+ new Pound(14),
+ new Pound(15)
+ );
+ }
+
+ public function cheesePrices(): PriceList
+ {
+ return PriceList::fromList(
+ new Pound(7),
+ new Pound(8),
+ new Pound(9),
+ new Pound(10),
+ new Pound(11),
+ new Pound(12),
+ new Pound(13),
+ new Pound(14),
+ new Pound(14),
+ new Pound(15)
+ );
+ }
+
+ public function whiskyPrices(): PriceList
+ {
+ return PriceList::fromList(
+ new Pound(8),
+ new Pound(9),
+ new Pound(10),
+ new Pound(11),
+ new Pound(12),
+ new Pound(13),
+ new Pound(13),
+ new Pound(14),
+ new Pound(15),
+ new Pound(16)
+ );
+ }
+
}
diff --git a/src/Whisky.php b/src/Whisky.php
new file mode 100644
index 0000000..fcf4afb
--- /dev/null
+++ b/src/Whisky.php
@@ -0,0 +1,10 @@
+ '/Bread.php',
+ 'clansofcaledonia\\cheese' => '/Cheese.php',
'clansofcaledonia\\exception' => '/Exception.php',
'clansofcaledonia\\good' => '/Good.php',
+ 'clansofcaledonia\\grain' => '/Grain.php',
'clansofcaledonia\\market' => '/Market.php',
'clansofcaledonia\\milk' => '/Milk.php',
'clansofcaledonia\\offer' => '/Offer.php',
@@ -16,7 +19,9 @@ function($class) {
'clansofcaledonia\\pound' => '/Pound.php',
'clansofcaledonia\\pricelist' => '/PriceList.php',
'clansofcaledonia\\pricelistbuilder' => '/PriceListBuilder.php',
- 'clansofcaledonia\\unit' => '/Unit.php'
+ 'clansofcaledonia\\unit' => '/Unit.php',
+ 'clansofcaledonia\\whisky' => '/Whisky.php',
+ 'clansofcaledonia\\wool' => '/Wool.php'
);
}
$cn = strtolower($class);
diff --git a/tests/MarketTest.php b/tests/MarketTest.php
index d01128e..7634ff5 100644
--- a/tests/MarketTest.php
+++ b/tests/MarketTest.php
@@ -15,14 +15,14 @@ final class MarketTest extends TestCase
{
public function testMilkCosts5PoundsInitially(): void
{
- $market = new Market;
+ $market = $this->createMarket();
$this->assertEquals(new Pound(5), $market->priceFor(Good::milk()));
}
public function testMilkCanBeSoldToTheMarket(): Market
{
- $market = new Market;
+ $market = $this->createMarket();
$payment = $market->sellTo(
new Offer(
@@ -36,6 +36,21 @@ public function testMilkCanBeSoldToTheMarket(): Market
return $market;
}
+ public function testMilkCanBeBoughtFromTheMarket()
+ {
+ $market = $this->createMarket();
+
+ $payment = $market->buyFrom(
+ new Offer(
+ new Unit(3),
+ Good::milk()
+ )
+ );
+
+ $this->assertEquals(new Pound(10), $payment);
+
+ }
+
/**
* @depends testMilkCanBeSoldToTheMarket
*/
@@ -43,4 +58,29 @@ public function testSellingMilkToTheMarketReducesMilkPrice(Market $market): void
{
$this->assertEquals(new Pound(4), $market->priceFor(Good::milk()));
}
+
+ public function testWhiskyCanBeSoldToTheMarket(): Market
+ {
+ $market = $this->createMarket();
+
+ $payment = $market->sellTo(
+ new Offer(
+ new Unit(3),
+ Good::whisky()
+ )
+ );
+
+ $this->assertEquals(new Pound(33), $payment);
+
+ return $market;
+ }
+
+ /**
+ * @return Market
+ */
+ protected function createMarket(): Market
+ {
+ $builder = new PriceListBuilder();
+ return new Market($builder->milkPrices(), $builder->whiskyPrices());
+ }
}
diff --git a/tests/PoundTest.php b/tests/PoundTest.php
index 3d3ec6d..3213e2e 100644
--- a/tests/PoundTest.php
+++ b/tests/PoundTest.php
@@ -16,4 +16,14 @@ public function testHasAmount(): void
$this->assertSame($amount, $p->amount());
}
+
+ public function testItCanMultiplyByAnotherPound()
+ {
+ $firstPound = new Pound(5);
+
+ $resultingPound = $firstPound->multiply(6);
+
+ $this->assertInstanceOf(Pound::class, $resultingPound);
+ $this->assertEquals(30, $resultingPound->amount());
+ }
}
diff --git a/tests/PriceListTest.php b/tests/PriceListTest.php
index aba7abb..a32496d 100644
--- a/tests/PriceListTest.php
+++ b/tests/PriceListTest.php
@@ -12,7 +12,57 @@ final class PriceListTest extends TestCase
{
public function testHasInitialPrice(): void
{
- $prices = PriceList::fromList(
+ $priceList = $this->getTestPriceList();
+
+ $this->assertEquals(new Pound(4), $priceList->current());
+ }
+
+ public function testCanDecrementPosition()
+ {
+ $priceList = $this->getTestPriceList();
+
+ $this->assertEquals(new Pound(4), $priceList->current());
+ $priceList->decrement();
+ $this->assertEquals(new Pound(3), $priceList->current());
+ }
+
+
+ public function testCanDecremenPositiontByMultipleSteps()
+ {
+ $priceList = $this->getTestPriceList();
+
+ $this->assertEquals(new Pound(4), $priceList->current());
+ $priceList->decrement(3);
+ $this->assertEquals(new Pound(1), $priceList->current());
+ }
+
+
+
+ public function testCanIncrementPosition()
+ {
+ $priceList = $this->getTestPriceList();
+
+ $this->assertEquals(new Pound(4), $priceList->current());
+ $priceList->increment();
+ $this->assertEquals(new Pound(5), $priceList->current());
+ }
+
+
+ public function testCanIncrementPositiontByMultipleSteps()
+ {
+ $priceList = $this->getTestPriceList();
+
+ $this->assertEquals(new Pound(4), $priceList->current());
+ $priceList->increment(3);
+ $this->assertEquals(new Pound(7), $priceList->current());
+ }
+
+ /**
+ * @return PriceList
+ */
+ protected function getTestPriceList(): PriceList
+ {
+ return PriceList::fromList(
new Pound(1),
new Pound(2),
new Pound(3),
@@ -24,7 +74,5 @@ public function testHasInitialPrice(): void
new Pound(9),
new Pound(10)
);
-
- $this->assertEquals(new Pound(4), $prices->current());
}
}