Backstage regular product runs quality max test

and quality dip down to 0 test OK.
This commit is contained in:
Povilas Brilius 2020-05-01 23:52:44 +03:00
parent 4d2389857a
commit cd58aa0141
2 changed files with 66 additions and 21 deletions

View File

@ -62,32 +62,32 @@ final class GildedRose
if ($item->name === 'Sulfuras, Hand of Ragnaros') {
continue;
}
if ($item->name !== 'Aged Brie' && $item->name !== 'Backstage passes to a TAFKAL80ETC concert') {
if ($item->quality > 0) {
if (strstr($item->name, 'Conjured', true) === '') {
$item->quality -= 2;
} else {
$item->quality--;
if ($item->sell_in >= 0) {
if ($item->name !== 'Aged Brie' && $item->name !== 'Backstage passes to a TAFKAL80ETC concert') {
if ($item->quality > 0) {
if (strstr($item->name, 'Conjured', true) === '') {
$item->quality -= 2;
} else {
$item->quality--;
}
}
}
} else {
if ($item->quality < 50) {
if ($item->name === 'Aged Brie') {
$item->quality++;
} else if ($item->name === 'Backstage passes to a TAFKAL80ETC concert') {
if ($item->sell_in <= 10 && $item->sell_in > 5) {
$item->quality += 2;
} else if ($item->sell_in <= 5) {
$item->quality += 3;
} else if ($item->sell_in > 10) {
} else {
if ($item->quality < 50) {
if ($item->name === 'Aged Brie') {
$item->quality++;
} else if ($item->name === 'Backstage passes to a TAFKAL80ETC concert') {
if ($item->sell_in <= 10 && $item->sell_in > 5) {
$item->quality += 2;
} else if ($item->sell_in <= 5) {
$item->quality += 3;
} else if ($item->sell_in > 10) {
$item->quality++;
}
}
}
}
}
if ($item->sell_in < 0) {
} else {
if ($item->name !== 'Aged Brie') {
if ($item->name === 'Backstage passes to a TAFKAL80ETC concert') {
$item->quality = 0;

View File

@ -173,4 +173,49 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase
$this->assertEquals(9, $app->getItems()[2]->sell_in);
}
/**
* Test stage prouct jumps to 0 quality after sale pass
*
* @return void
*/
public function testQualityDipToZero()
{
$items = [
new Item('Backstage passes to a TAFKAL80ETC concert', 1, 14),
];
$interval = 3;
$app = new GildedRose($items);
for ($i = 0; $i < $interval; $i++) {
$app->updateQuality();
}
$this->assertEquals(0, $app->getItems()[0]->quality);
}
/**
* Regular products max quality assessment value limit
*
* @return void
*/
public function testQualityMaxLimitOnSimpleProduct()
{
$items = [
new Item('Backstage passes to a TAFKAL80ETC concert', 20, 49),
new Item('Backstage passes to a TAFKAL80ETC concert', 20, 48),
new Item('Backstage passes to a TAFKAL80ETC concert', 20, 50),
];
$interval = 3;
$app = new GildedRose($items);
for ($i = 0; $i < $interval; $i++) {
$app->updateQuality();
}
$this->assertEquals(50, $app->getItems()[0]->quality);
}
}