Sulfurasのリファクタリング

This commit is contained in:
bestaff-hirakawa 2022-08-07 03:10:30 +09:00
parent fcecd11fba
commit a3e2d56a24
2 changed files with 46 additions and 0 deletions

View File

@ -27,6 +27,8 @@ final class GildedRose
・引数のsell_inを-1する ・引数のsell_inを-1する
・計算後sell_inが0未満の場合、quality+2する ・計算後sell_inが0未満の場合、quality+2する
・計算後sell_inが0以上の場合、quality+1する ・計算後sell_inが0以上の場合、quality+1する
[商品Sulfuras]
・sell_in、qualityどちらも変更しない
*/ */
/** /**
@ -38,6 +40,9 @@ final class GildedRose
if ($this->item->name === 'Aged Brie') { if ($this->item->name === 'Aged Brie') {
// 商品Aged Brieの処理 // 商品Aged Brieの処理
$this->agedBrie(); $this->agedBrie();
} elseif ($this->item->name === 'Sulfuras, Hand of Ragnaros') {
// 商品Sulfurasの処理
$this->sulfuras();
} }
} }
} }
@ -56,6 +61,14 @@ final class GildedRose
} }
} }
/**
* 商品Sulfuras計算処理
*/
private function sulfuras(): void
{
// 何もしない
}
/** /**
* sell_inの減算を行う * sell_inの減算を行う
*/ */

View File

@ -67,6 +67,39 @@ class GildedRoseTest extends TestCase
$this->assertSame(50, $items[0]->quality); $this->assertSame(50, $items[0]->quality);
} }
/**
* Sulfurassell_inが1以上、qualityが80
* 期待値sell_in、qualityどちらも変更なし
*/
public function testSulfurasNormal(): void
{
$items = [new Item('Sulfuras, Hand of Ragnaros', 5, 80)];
$gildedRose = new GildedRose($items);
$gildedRose->updateQuality();
$this->assertSame('Sulfuras, Hand of Ragnaros', $items[0]->name);
$this->assertSame(5, $items[0]->sell_in);
$this->assertSame(80, $items[0]->quality);
}
/**
* 複数商品
*/
public function testMixCase(): void
{
$items = [
new Item('Aged Brie', 5, 10),
new Item('Sulfuras, Hand of Ragnaros', 5, 80),
];
$gildedRose = new GildedRose($items);
$gildedRose->updateQuality();
$this->assertSame('Aged Brie', $items[0]->name);
$this->assertSame(4, $items[0]->sell_in);
$this->assertSame(11, $items[0]->quality);
$this->assertSame('Sulfuras, Hand of Ragnaros', $items[1]->name);
$this->assertSame(5, $items[1]->sell_in);
$this->assertSame(80, $items[1]->quality);
}
// テストエラーの原因が特定できないので後で調査する // テストエラーの原因が特定できないので後で調査する
/* /*
public function testApproveArray() public function testApproveArray()