diff --git a/php7/phpunit.xml b/php7/phpunit.xml
index f09680b8..281edc63 100644
--- a/php7/phpunit.xml
+++ b/php7/phpunit.xml
@@ -10,4 +10,10 @@
test
+
+
+
+ src
+
+
diff --git a/php7/src/GildedRose.php b/php7/src/GildedRose.php
index d088e46c..5a7cd7c9 100644
--- a/php7/src/GildedRose.php
+++ b/php7/src/GildedRose.php
@@ -2,15 +2,15 @@
namespace App;
-class GildedRose {
+final class GildedRose {
private $items = [];
- function __construct($items) {
+ public function __construct($items) {
$this->items = $items;
}
- function updateQuality() {
+ public function updateQuality() {
foreach ($this->items as $item) {
if ($item->name != 'Aged Brie' and $item->name != 'Backstage passes to a TAFKAL80ETC concert') {
if ($item->quality > 0) {
diff --git a/php7/src/Item.php b/php7/src/Item.php
index 8a1dfd04..9ff2741b 100644
--- a/php7/src/Item.php
+++ b/php7/src/Item.php
@@ -2,7 +2,7 @@
namespace App;
-class Item {
+final class Item {
public $name;
public $sell_in;
diff --git a/php7/test/GildedRoseTest.php b/php7/test/GildedRoseTest.php
index d8ccb190..49cb3ad2 100644
--- a/php7/test/GildedRoseTest.php
+++ b/php7/test/GildedRoseTest.php
@@ -2,13 +2,45 @@
namespace App;
-require_once __DIR__ . '/../vendor/autoload.php';
-
class GildedRoseTest extends \PHPUnit\Framework\TestCase {
public function testFoo() {
$items = array(new Item("foo", 0, 0));
$gildedRose = new GildedRose($items);
$gildedRose->updateQuality();
- $this->assertEquals("fixme", $items[0]->name);
+ $this->assertEquals("foo", $items[0]->name);
+ $this->assertEquals("foo, -1, 0", (string)$items[0]);
+ }
+
+ /**
+ * @dataProvider itemProvider
+ */
+ public function testItems(Item $item, $expected, $sellIn) {
+ $rose = new GildedRose([$item]);
+
+ while ($sellIn > 1) {
+ $rose->updateQuality();
+ $sellIn--;
+ }
+
+ $actual = $item->quality;
+ $this->assertEquals($expected, $actual);
+ }
+
+ public function itemProvider() {
+ // if you comment out any assignment/increment/decrement operation in updateQuality,
+ // at least one of these tests should fail. If there isn't a failure, then perhaps
+ // that line of code does not need to exist.
+ return [
+ 'foo' => ['item' => new Item('foo', 9, 10), 'expected' => 2, 'sell_in' => 9],
+ 'Aged Brie' => ['item' => new Item('Aged Brie', 9, 10), 'expected' => 18, 'sell_in' => 9],
+ 'Backstage' => ['item' => new Item('Backstage passes to a TAFKAL80ETC concert', 9, 10), 'expected' => 30, 'sell_in' => 9],
+ 'Backstage2' => ['item' => new Item('Backstage passes to a TAFKAL80ETC concert', 9, 10), 'expected' => 0, 'sell_in' => 19],
+ 'Backstage3' => ['item' => new Item('Backstage passes to a TAFKAL80ETC concert', 9, 10), 'expected' => 0, 'sell_in' => 19],
+ 'Sulfuras1' => ['item' => new Item('Sulfuras, Hand of Ragnaros', 9, 10), 'expected' => 10, 'sell_in' => 9],
+ 'aged-foo' => ['item' => new Item('foo', 3, 14), 'expected' => 1, 'sell_in' => 9],
+ 'qualityFoo' => ['item' => new Item('foo', 3, 94), 'expected' => 39, 'sell_in' => 30],
+ 'qualityBrie' => ['item' => new Item('Aged Brie', 3, 94), 'expected' => 94, 'sell_in' => 30],
+ 'cheapBrie' => ['item' => new Item('Aged Brie', 3, 3), 'expected' => 50, 'sell_in' => 30],
+ ];
}
}