mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 16:01:42 +00:00
Before adding Conjured Mana Cake
This commit is contained in:
parent
d4aed50b88
commit
ec38231369
@ -18,7 +18,7 @@ we can begin selling a new category of items. First an introduction to our syste
|
||||
|
||||
Pretty simple, right? Well this is where it gets interesting:
|
||||
|
||||
- Once the sell by date has passed, Quality degrades twice as fast
|
||||
+ Once the sell by date has passed, Quality degrades twice as fast
|
||||
- The Quality of an item is never negative
|
||||
- "Aged Brie" actually increases in Quality the older it gets
|
||||
- The Quality of an item is never more than 50
|
||||
@ -54,12 +54,6 @@ final class GildedRose
|
||||
{
|
||||
/** @var Item $item */
|
||||
foreach ($this->items as $item) {
|
||||
//conjured quality -2 + test. test first!
|
||||
// if ($item->name === 'Conjured Mana Cake') {
|
||||
// $this->lowerQuality($item, 1);
|
||||
// }
|
||||
|
||||
//spare Sulfuras from quality drop
|
||||
if ($item->name === 'Sulfuras, Hand of Ragnaros') {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -8,86 +8,168 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
class GildedRoseTest extends TestCase
|
||||
{
|
||||
public function testFoo(): void
|
||||
public function testCommonItemDailyChange(): void
|
||||
{
|
||||
$items = [new Item('foo', 0, 0)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
self::assertSame('foo', $items[0]->name);
|
||||
self::assertSame(-1, $items[0]->sell_in);
|
||||
|
||||
}
|
||||
|
||||
public function testNotBelowZero(): void
|
||||
{
|
||||
$items = [new Item('foo', 0, 1)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
self::assertSame(0, $items[0]->quality);
|
||||
self::assertSame(-1, $items[0]->sell_in);
|
||||
}
|
||||
|
||||
public function testQualityDropsTwice(): void
|
||||
{
|
||||
$items = [new Item('foo', 0, 2)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
self::assertSame(0, $items[0]->quality);
|
||||
self::assertSame(-1, $items[0]->sell_in);
|
||||
}
|
||||
|
||||
public function testAgedBrieQualityIncreases(): void
|
||||
{
|
||||
$items = [new Item('Aged Brie', 0, 1)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
self::assertSame(3, $items[0]->quality);
|
||||
self::assertSame(-1, $items[0]->sell_in);
|
||||
}
|
||||
|
||||
public function testQualityNotMoreThan50(): void
|
||||
{
|
||||
$items = [new Item('Aged Brie', -1, 47)];
|
||||
$items = [new Item('+5 Dexterity Vest', 31, 50)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
self::assertSame('+5 Dexterity Vest', $items[0]->name);
|
||||
self::assertSame(30, $items[0]->sell_in);
|
||||
self::assertSame(49, $items[0]->quality);
|
||||
}
|
||||
|
||||
public function testQualityDropsTwiceAfterZeroDate(): void
|
||||
{
|
||||
$items = [new Item('randomItem', -1, 3)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
self::assertSame(1, $items[0]->quality);
|
||||
self::assertSame(-2, $items[0]->sell_in);
|
||||
}
|
||||
|
||||
public function testSulfurasQualityAndSellinStays(): void
|
||||
public function testQualityNeverMoreThan50(): void
|
||||
{
|
||||
$items = [new Item('Sulfuras, Hand of Ragnaros', 1, 47)];
|
||||
$items = [new Item('Aged Brie', -1, 49)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
self::assertSame(47, $items[0]->quality);
|
||||
self::assertSame(1, $items[0]->sell_in);
|
||||
self::assertSame(50, $items[0]->quality);
|
||||
self::assertSame(-2, $items[0]->sell_in);
|
||||
}
|
||||
|
||||
/** @dataProvider BackstageScenario */
|
||||
public function testBackstageQuality(array $scenario): void
|
||||
/** @dataProvider qualityNeverNegativeScenario */
|
||||
public function testQualityNeverNegative(array $qualityNeverNegativeScenario): void
|
||||
{
|
||||
$items = [new Item('Backstage passes to a TAFKAL80ETC concert', $scenario['data']['sell_in'], $scenario['data']['quality'])];
|
||||
$items = [new Item('foo', $qualityNeverNegativeScenario['data']['sell_in'], $qualityNeverNegativeScenario['data']['quality'])];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
self::assertSame($scenario['expect']['quality'], $items[0]->quality);
|
||||
self::assertSame($scenario['expect']['sell_in'], $items[0]->sell_in);
|
||||
self::assertSame($qualityNeverNegativeScenario['expect']['quality'], $items[0]->quality);
|
||||
self::assertSame($qualityNeverNegativeScenario['expect']['sell_in'], $items[0]->sell_in);
|
||||
}
|
||||
|
||||
public function BackstageScenario(): array
|
||||
public function qualityNeverNegativeScenario(): array
|
||||
{
|
||||
return [
|
||||
[[
|
||||
'data' => ['sell_in' => 1, 'quality' => 47],
|
||||
'expect' => ['sell_in' => 0, 'quality' => 50],
|
||||
'data' => ['sell_in' => 1, 'quality' => 0],
|
||||
'expect' => ['sell_in' => 0, 'quality' => 0],
|
||||
]],
|
||||
[[
|
||||
'data' => ['sell_in' => 5, 'quality' => 50],
|
||||
'expect' => ['sell_in' => 4, 'quality' => 50],
|
||||
]],
|
||||
[[
|
||||
'data' => ['sell_in' => 9, 'quality' => 40],
|
||||
'expect' => ['sell_in' => 8, 'quality' => 42],
|
||||
'data' => ['sell_in' => -1, 'quality' => 1],
|
||||
'expect' => ['sell_in' => -2, 'quality' => 0],
|
||||
]]
|
||||
];
|
||||
}
|
||||
/** end of QualityNeverNegativeScenario */
|
||||
|
||||
/** @dataProvider agedBrieScenario */
|
||||
public function testAgedBrieQualityIncreases(array $agedBrieScenario): void
|
||||
{
|
||||
$items = [new Item('Aged Brie', $agedBrieScenario['data']['sell_in'], $agedBrieScenario['data']['quality'])];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
self::assertSame($agedBrieScenario['expect']['quality'], $items[0]->quality);
|
||||
self::assertSame($agedBrieScenario['expect']['sell_in'], $items[0]->sell_in);
|
||||
}
|
||||
|
||||
public function agedBrieScenario(): array
|
||||
{
|
||||
return [
|
||||
[[
|
||||
'data' => ['sell_in' => 11, 'quality' => 49],
|
||||
'expect' => ['sell_in' => 10, 'quality' => 50],
|
||||
]],
|
||||
[[
|
||||
'data' => ['sell_in' => 0, 'quality' => 47],
|
||||
'expect' => ['sell_in' => -1, 'quality' => 49],
|
||||
]]
|
||||
];
|
||||
}
|
||||
/** end of agedBrieScenario */
|
||||
|
||||
/** @dataProvider sulfurasScenario */
|
||||
public function testSulfurasQualityAndSellinStays(array $sulfurasScenario): void
|
||||
{
|
||||
$items = [new Item('Sulfuras, Hand of Ragnaros', $sulfurasScenario['data']['sell_in'], $sulfurasScenario['data']['quality'])];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
self::assertSame($sulfurasScenario['expect']['quality'], $items[0]->quality);
|
||||
self::assertSame($sulfurasScenario['expect']['sell_in'], $items[0]->sell_in);
|
||||
}
|
||||
|
||||
public function sulfurasScenario(): array
|
||||
{
|
||||
return [
|
||||
[[
|
||||
'data' => ['sell_in' => 31, 'quality' => 80],
|
||||
'expect' => ['sell_in' => 31, 'quality' => 80],
|
||||
]],
|
||||
[[
|
||||
'data' => ['sell_in' => 0, 'quality' => 80],
|
||||
'expect' => ['sell_in' => 0, 'quality' => 80],
|
||||
]],
|
||||
[[
|
||||
'data' => ['sell_in' => -1, 'quality' => 80],
|
||||
'expect' => ['sell_in' => -1, 'quality' => 80],
|
||||
]]
|
||||
];
|
||||
}
|
||||
/** end of sulfurasScenario */
|
||||
|
||||
/** @dataProvider backstagePassScenario */
|
||||
public function testBackstagePassQuality(array $backstagePassScenario): void
|
||||
{
|
||||
$items = [new Item('Backstage passes to a TAFKAL80ETC concert', $backstagePassScenario['data']['sell_in'], $backstagePassScenario['data']['quality'])];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
self::assertSame($backstagePassScenario['expect']['quality'], $items[0]->quality);
|
||||
self::assertSame($backstagePassScenario['expect']['sell_in'], $items[0]->sell_in);
|
||||
}
|
||||
|
||||
public function backstagePassScenario(): array
|
||||
{
|
||||
return [
|
||||
[[
|
||||
'data' => ['sell_in' => 31, 'quality' => 43],
|
||||
'expect' => ['sell_in' => 30, 'quality' => 44],
|
||||
]],
|
||||
[[
|
||||
'data' => ['sell_in' => 10, 'quality' => 44],
|
||||
'expect' => ['sell_in' => 9, 'quality' => 46],
|
||||
]],
|
||||
[[
|
||||
'data' => ['sell_in' => 1, 'quality' => 46],
|
||||
'expect' => ['sell_in' => 0, 'quality' => 49],
|
||||
]],
|
||||
[[
|
||||
'data' => ['sell_in' => 0, 'quality' => 49],
|
||||
'expect' => ['sell_in' => -1, 'quality' => 0],
|
||||
]]
|
||||
];
|
||||
}
|
||||
/** end of backstageScenario */
|
||||
|
||||
/** @dataProvider conjuredItemsScenario */
|
||||
public function testConjuredItems(array $conjuredItemsScenario): void
|
||||
{
|
||||
$items = [new Item('Conjured Mana Cake', $conjuredItemsScenario['data']['sell_in'], $conjuredItemsScenario['data']['quality'])];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
self::assertSame($conjuredItemsScenario['expect']['quality'], $items[0]->quality);
|
||||
self::assertSame($conjuredItemsScenario['expect']['sell_in'], $items[0]->sell_in);
|
||||
}
|
||||
|
||||
public function conjuredItemsScenario(): array
|
||||
{
|
||||
return [
|
||||
[[
|
||||
'data' => ['sell_in' => 31, 'quality' => 50],
|
||||
'expect' => ['sell_in' => 30, 'quality' => 48],
|
||||
]],
|
||||
[[
|
||||
'data' => ['sell_in' => 0, 'quality' => 48],
|
||||
'expect' => ['sell_in' => -1, 'quality' => 44],
|
||||
]]
|
||||
];
|
||||
}
|
||||
/** end of conjuredItemsScenario */
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user