Skip to content

Instantly share code, notes, and snippets.

@Abban
Last active January 31, 2020 13:01
Show Gist options
  • Save Abban/e864321393df6bdca034487c2ef9e418 to your computer and use it in GitHub Desktop.
Save Abban/e864321393df6bdca034487c2ef9e418 to your computer and use it in GitHub Desktop.
Integration Tests for Abban's Test
<?php namespace GildedRose\Tests;
use GildedRose\InventoryItem;
use GildedRose\InventoryItemLegendary;
use GildedRose\InventoryItemTicket;
use GildedRose\Program;
use PHPUnit\Framework\TestCase;
class InventoryItemTest extends TestCase
{
/** @test */
public function InventoryItem_OnSetQuality_SetsCorrectValues()
{
$app = new Program([new InventoryItem(['name' => "+5 Dexterity Vest", 'sellIn' => 10, 'quality' => 20], -1)]);
$this->assertEquals(20, $app->getItems()[0]->getItem()->quality, "Did not set correct quality");
$this->assertEquals(10, $app->getItems()[0]->getItem()->sellIn, "Did not set correct Sell In");
}
/** @test */
public function InventoryItem_OnUpdate_AdjustsQualityByCorrectValue()
{
$app = new Program([new InventoryItem(['name' => "+5 Dexterity Vest", 'sellIn' => 10, 'quality' => 20], -1)]);
$app->UpdateQuality();
$this->assertEquals(19, $app->getItems()[0]->getItem()->quality, "Did not adjust correct quality");
}
/** @test */
public function InventoryItem_OnUpdate_DropsSellInByCorrectValue()
{
$app = new Program([new InventoryItem(['name' => "+5 Dexterity Vest", 'sellIn' => 10, 'quality' => 20], -1)]);
$app->UpdateQuality();
$this->assertEquals(9, $app->getItems()[0]->getItem()->sellIn, "Did not adjust correct sellIn");
}
/** @test */
public function InventoryItem_OnUpdate_QualityDoesNotDropBelow0()
{
$app = new Program([new InventoryItem(['name' => "+5 Dexterity Vest", 'sellIn' => 10, 'quality' => 0], -1)]);
$app->UpdateQuality();
$this->assertEquals(0, $app->getItems()[0]->getItem()->quality, "Quality dropped below zero");
}
/** @test */
public function InventoryItem_OnUpdate_QualityDoesNotGoAbove50()
{
$app = new Program([new InventoryItem(['name' => "+5 Dexterity Vest", 'sellIn' => 10, 'quality' => 45], 10)]);
$app->UpdateQuality();
$this->assertEquals(50, $app->getItems()[0]->getItem()->quality, "Quality went above 50");
}
/** @test */
public function InventoryItem_OnUpdateBelow0SellIn_AdjustsQualityByCorrectValue()
{
$app = new Program([new InventoryItem(['name' => "+5 Dexterity Vest", 'sellIn' => 0, 'quality' => 20], -1)]);
$app->UpdateQuality();
$this->assertEquals(18, $app->getItems()[0]->getItem()->quality, "Did not adjust correct quality");
}
/** @test */
public function LegendaryItem_OnUpdate_DoesNothing()
{
$app = new Program([new InventoryItemLegendary(['name' => "+5 Dexterity Vest", 'sellIn' => 10, 'quality' => 20], -1)]);
$app->UpdateQuality();
$this->assertEquals(20, $app->getItems()[0]->getItem()->quality, "Legendary Item quality changed");
$this->assertEquals(10, $app->getItems()[0]->getItem()->sellIn, "Legendary Item sellIn changed");
}
/** @test */
public function TicketItem_OnUpdateOver10SellIn_AdjustsQualityByCorrectValue()
{
$app = new Program([new InventoryItemTicket(['name' => "+5 Dexterity Vest", 'sellIn' => 12, 'quality' => 20], -1)]);
$app->UpdateQuality();
$this->assertEquals(21, $app->getItems()[0]->getItem()->quality, "Did not adjust correct quality on ticket item");
}
/** @test */
public function TicketItem_OnUpdateUnder10SellIn_AdjustsQualityByCorrectValue()
{
$app = new Program([new InventoryItemTicket(['name' => "+5 Dexterity Vest", 'sellIn' => 10, 'quality' => 20], -1)]);
$app->UpdateQuality();
$this->assertEquals(22, $app->getItems()[0]->getItem()->quality, "Did not adjust correct quality on ticket item");
}
/** @test */
public function TicketItem_OnUpdateUnder5SellIn_AdjustsQualityByCorrectValue()
{
$app = new Program([new InventoryItemTicket(['name' => "+5 Dexterity Vest", 'sellIn' => 5, 'quality' => 20], -1)]);
$app->UpdateQuality();
$this->assertEquals(23, $app->getItems()[0]->getItem()->quality, "Did not adjust correct quality on ticket item");
}
/** @test */
public function TicketItem_OnUpdateUnder0SellIn_AdjustsQualityByCorrectValue()
{
$app = new Program([new InventoryItemTicket(['name' => "+5 Dexterity Vest", 'sellIn' => 0, 'quality' => 20], -1)]);
$app->UpdateQuality();
$this->assertEquals(0, $app->getItems()[0]->getItem()->quality, "Did not adjust correct quality on ticket item");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment