To provide a better behavioural test harness, add Behat tests for all features

This commit is contained in:
Sam Burns 2024-01-24 14:35:56 +00:00
parent 1a572c1eb7
commit bad5ca93fd
6 changed files with 116 additions and 9 deletions

View File

@ -16,36 +16,72 @@ class ServiceLevelContext implements Context
private Item $item; private Item $item;
private GildedRose $gildedRose; private GildedRose $gildedRose;
private function createItem(string $name, int $initialSellIn, int $initialQuality): void
{
$this->item = new Item($name, $initialSellIn, $initialQuality);
$this->gildedRose = new GildedRose([$this->item]);
}
#[Then('I should see :expectedOutput')] #[Then('I should see :expectedOutput')]
public function iShouldSee(string $expectedOutput): void public function iShouldSee(string $expectedOutput): void
{ {
Assert::assertEquals([$expectedOutput], $this->result); Assert::assertEquals([$expectedOutput], $this->result);
} }
#[Given('an item with a sell_in of :initialellIn and a quality of :initialQuality')] #[Given('an item with a sell-in of :initialSellIn and a quality of :initialQuality')]
public function anItemWithASellInOfAndAQualityOf(int $initialellIn, int $initialQuality) public function anItemWithASellInOfAndAQualityOf(int $initialSellIn, int $initialQuality): void
{ {
$this->item = new Item('foo', $initialellIn, $initialQuality); $this->createItem('foo', $initialSellIn, $initialQuality);
$this->gildedRose = new GildedRose([$this->item]); }
#[Given('an item with a sell-in of :initialSellIn')]
public function anItemWithASellInOf(int $initialSellIn): void
{
$this->createItem('foo', $initialSellIn, 20);
} }
#[When('I update the quality')] #[When('I update the quality')]
public function iUpdateTheQuality() #[When('I update the sell-in')]
public function iUpdateTheQuality(): void
{ {
$this->gildedRose->updateQuality(); $this->gildedRose->updateQuality();
} }
#[Then('the item should have a quality of :expectedQuality')] #[Then('the item should have a quality of :expectedQuality')]
public function theItemShouldHaveAQualityOf($expectedQuality) public function theItemShouldHaveAQualityOf($expectedQuality): void
{ {
Assert::assertEquals($expectedQuality, $this->item->quality); Assert::assertEquals($expectedQuality, $this->item->quality);
} }
#[When('I update the quality :noOfDays times')] #[When('I update the quality :noOfDays times')]
public function iUpdateTheQualityTimes(int $noOfDays) public function iUpdateTheQualityTimes(int $noOfDays): void
{ {
for ($i = 0; $i < $noOfDays; $i++) { for ($i = 0; $i < $noOfDays; $i++) {
$this->gildedRose->updateQuality(); $this->gildedRose->updateQuality();
} }
} }
#[Then('the item should have a sell-in of :expectedSellIn')]
public function theItemShouldHaveASellInOf(int $sellIn): void
{
Assert::assertEquals($sellIn, $this->item->sellIn);
}
#[Given('some brie with a sell-in of :initialSellIn and a quality of :initialQuality')]
public function someBrieWithASellInOfAndAQualityOf(int $initialSellIn, int $initialQuality): void
{
$this->createItem('Aged Brie', $initialSellIn, $initialQuality);
}
#[Given('a backstage pass with a sell-in of :initialSellIn and a quality of :initialQuality')]
public function aBackstagePassWithASellInOfAndAQualityOf(int $initialSellIn, int $initialQuality): void
{
$this->createItem('Backstage passes to a TAFKAL80ETC concert', $initialSellIn, $initialQuality);
}
#[Given('a sulfura with a sell-in of :initialSellIn and a quality of :initialQuality')]
public function aSulfuraWithASellInOfAndAQualityOf(int $initialSellIn, int $initialQuality): void
{
$this->createItem('Sulfuras, Hand of Ragnaros', $initialSellIn, $initialQuality);
}
} }

View File

@ -0,0 +1,28 @@
Feature: Backstage passes quality changes
In order to keep track of backstage passes
As a shopkeeper
I want to see the quality of backstage passes change appropriately
Scenario: Backstage pass quality update
Given a backstage pass with a sell-in of 20 and a quality of 20
When I update the quality
Then the item should have a quality of 21
Scenario: Backstage pass with 10 days left
Given a backstage pass with a sell-in of 10 and a quality of 20
When I update the quality
Then the item should have a quality of 22
Scenario: Backstage pass with 5 days left
Given a backstage pass with a sell-in of 5 and a quality of 20
When I update the quality
Then the item should have a quality of 23
Scenario: Backstage pass after the concert
Given a backstage pass with a sell-in of 0 and a quality of 20
When I update the quality
Then the item should have a quality of 0

View File

@ -0,0 +1,16 @@
Feature: Brie quality changes
In order to keep track of aged brie
As a shopkeeper
I want to see the quality of aged brie increase
Scenario: Aged brie quality update
Given some brie with a sell-in of 20 and a quality of 20
When I update the quality
Then the item should have a quality of 21
Scenario: Aged brie at maximum quality
Given some brie with a sell-in of 20 and a quality of 50
When I update the quality
Then the item should have a quality of 50

View File

@ -5,12 +5,18 @@ Feature: Default quality degradation
Scenario: Single quality update Scenario: Single quality update
Given an item with a sell_in of 20 and a quality of 20 Given an item with a sell-in of 20 and a quality of 20
When I update the quality When I update the quality
Then the item should have a quality of 19 Then the item should have a quality of 19
Scenario: Quality updates over multiple days Scenario: Quality updates over multiple days
Given an item with a sell_in of 20 and a quality of 20 Given an item with a sell-in of 20 and a quality of 20
When I update the quality 5 times When I update the quality 5 times
Then the item should have a quality of 15 Then the item should have a quality of 15
Scenario: Quality cannot be negative
Given an item with a sell-in of 20 and a quality of 0
When I update the quality
Then the item should have a quality of 0

View File

@ -0,0 +1,10 @@
Feature: Sell-in tracking
In order to keep track of the sell-by date of an item
As a shopkeeper
I want to see the sell-in value decremented each day
Scenario: Basic sell-in tracking
Given an item with a sell-in of 20
When I update the sell-in
Then the item should have a sell-in of 19

View File

@ -0,0 +1,11 @@
Feature: Sulfuras
In order to keep track of sulfuras
As a shopkeeper
I want to see the quality and sell-in of sulfuras stay the same
Scenario: Sulfuras quality and sell-in not changing
Given a sulfura with a sell-in of 20 and a quality of 20
When I update the quality
Then the item should have a quality of 20
And the item should have a sell-in of 20