From a2798f44dece039cd1e9abd8b91c8ac2e7538d3a Mon Sep 17 00:00:00 2001 From: kitfbgh Date: Sat, 2 Apr 2022 11:20:08 +0800 Subject: [PATCH] Complete test cases --- php/src/GildedRose.php | 5 ++ php/tests/GildedRoseTest.php | 144 +++++++++++++++++++++++++++++++++-- 2 files changed, 144 insertions(+), 5 deletions(-) diff --git a/php/src/GildedRose.php b/php/src/GildedRose.php index 07a4d747..3350949b 100644 --- a/php/src/GildedRose.php +++ b/php/src/GildedRose.php @@ -16,6 +16,11 @@ final class GildedRose $this->items = $items; } + public function getItems(): array + { + return $this->items; + } + public function updateQuality(): void { foreach ($this->items as $item) { diff --git a/php/tests/GildedRoseTest.php b/php/tests/GildedRoseTest.php index 52e7ddc6..f0db9e7b 100644 --- a/php/tests/GildedRoseTest.php +++ b/php/tests/GildedRoseTest.php @@ -10,11 +10,145 @@ use PHPUnit\Framework\TestCase; class GildedRoseTest extends TestCase { - public function testFoo(): void + public function testQualityNeverIsNegative(): void { - $items = [new Item('foo', 0, 0)]; - $gildedRose = new GildedRose($items); - $gildedRose->updateQuality(); - $this->assertSame('fixme', $items[0]->name); + $items = [new Item("foo", 0, 0)]; + $app = new GildedRose($items); + + $app->updateQuality(); + + $this->assertSame(0, $app->getItems()[0]->quality); + } + + public function testSulfurasCouldNotBeSold(): void + { + $items = [new Item("Sulfuras, Hand of Ragnaros", 10, 0)]; + $app = new GildedRose($items); + + $app->updateQuality(); + + $this->assertSame(10, $app->getItems()[0]->sellIn); + } + + public function testSulfurasCouldNotDecreaseQuality(): void + { + $items = [new Item("Sulfuras, Hand of Ragnaros", 10, 10)]; + $app = new GildedRose($items); + + $app->updateQuality(); + + $this->assertSame(10, $app->getItems()[0]->quality); + } + + public function testQualityCouldNotBeMoreThanFifty(): void + { + $items = [new Item("Aged Brie", 10, 50)]; + $app = new GildedRose($items); + + $app->updateQuality(); + + $this->assertSame(50, $app->getItems()[0]->quality); + } + + public function testItemWithDatePassedQualityDecreaseByTwice(): void + { + $items = [new Item("foo", -1, 40)]; + $app = new GildedRose($items); + + $app->updateQuality(); + + $this->assertSame(38, $app->getItems()[0]->quality); + } + + public function testAgedBrieIncreaseQualityWhenItGetsOlder(): void + { + $items = [new Item("Aged Brie", 1, 40)]; + $app = new GildedRose($items); + + $app->updateQuality(); + + $this->assertSame(41, $app->getItems()[0]->quality); + } + + public function testAgedBrieIncreaseByTwoQualityWhenDatePassed(): void + { + $items = [new Item("Aged Brie", -1, 40)]; + $app = new GildedRose($items); + + $app->updateQuality(); + + $this->assertSame(42, $app->getItems()[0]->quality); + } + + public function testAgedBrieIncreaseByTwoQualityWhenDatePassedAndNotMoreThanFifty() { + $items = [new Item("Aged Brie", -1, 50)]; + $app = new GildedRose($items); + + $app->updateQuality(); + + $this->assertSame(50, $app->getItems()[0]->quality); + } + + public function testBackstagePassesIncreaseQualityByTwoWhenSelinLessThanTen() { + $items = [new Item("Backstage passes to a TAFKAL80ETC concert", 10, 40)]; + $app = new GildedRose($items); + + $app->updateQuality(); + + $this->assertSame(42, $app->getItems()[0]->quality); + } + + public function testBackstagePassesIncreaseQualityByTwoWhenSellinLessThanSix() { + $items = [new Item("Backstage passes to a TAFKAL80ETC concert", 6, 40)]; + $app = new GildedRose($items); + + $app->updateQuality(); + + $this->assertSame(42, $app->getItems()[0]->quality); + } + + public function testBackstagePassesIncreaseQualityByThreeWhenSellinLessThanFive() { + $items = [new Item("Backstage passes to a TAFKAL80ETC concert", 5, 40)]; + $app = new GildedRose($items); + + $app->updateQuality(); + + $this->assertSame(43, $app->getItems()[0]->quality); + } + + public function testBackstagePassesIncreaseQualityByTwoWhenSellinLessThanSixAndNotMoreThanFifty() { + $items = [new Item("Backstage passes to a TAFKAL80ETC concert", 6, 49)]; + $app = new GildedRose($items); + + $app->updateQuality(); + + $this->assertSame(50, $app->getItems()[0]->quality); + } + + public function testBackstagePassesIncreaseQualityByThreeWhenSellinLessThanFiveAndNotMoreThanFifty() { + $items = [new Item("Backstage passes to a TAFKAL80ETC concert", 5, 48)]; + $app = new GildedRose($items); + + $app->updateQuality(); + + $this->assertSame(50, $app->getItems()[0]->quality); + } + + public function testBackstagePassesQualityDropsToZeroAfterConcert() { + $items = [new Item("Backstage passes to a TAFKAL80ETC concert", 0, 40)]; + $app = new GildedRose($items); + + $app->updateQuality(); + + $this->assertSame(0, $app->getItems()[0]->quality); + } + + public function testBackstagePassesQualityIncreaseQualityByOneWhenDateIsMoreThanTen() { + $items = [new Item("Backstage passes to a TAFKAL80ETC concert", 11, 40)]; + $app = new GildedRose($items); + + $app->updateQuality(); + + $this->assertSame(41, $app->getItems()[0]->quality); } }