mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
To provide behavioural test infrastructure, add install Behat and add first test
This commit is contained in:
parent
fb7d21042e
commit
1a572c1eb7
9
php/behat.yml
Normal file
9
php/behat.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
default:
|
||||||
|
|
||||||
|
suites:
|
||||||
|
|
||||||
|
servicelevel:
|
||||||
|
paths: [ '%paths.base%/tests/behat/feature_files' ]
|
||||||
|
filters:
|
||||||
|
tags: ~@wip
|
||||||
|
contexts: [ 'BehatTests\ServiceLevelContext' ]
|
||||||
@ -7,6 +7,7 @@
|
|||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"approvals/approval-tests": "dev-Main",
|
"approvals/approval-tests": "dev-Main",
|
||||||
|
"behat/behat": "^3.14",
|
||||||
"phpunit/phpunit": "^9.5",
|
"phpunit/phpunit": "^9.5",
|
||||||
"phpstan/phpstan": "^1.9",
|
"phpstan/phpstan": "^1.9",
|
||||||
"phpstan/phpstan-phpunit": "^1.3",
|
"phpstan/phpstan-phpunit": "^1.3",
|
||||||
@ -20,11 +21,12 @@
|
|||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Tests\\": "tests/"
|
"Tests\\": "tests/",
|
||||||
|
"BehatTests\\": "tests/behat/contexts/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"tests": "phpunit",
|
"tests": "./vendor/bin/phpunit; ./vendor/bin/behat;",
|
||||||
"test-coverage": "phpunit --coverage-html build/coverage",
|
"test-coverage": "phpunit --coverage-html build/coverage",
|
||||||
"check-cs": "ecs check",
|
"check-cs": "ecs check",
|
||||||
"fix-cs": "ecs check --fix",
|
"fix-cs": "ecs check --fix",
|
||||||
|
|||||||
51
php/tests/behat/contexts/ServiceLevelContext.php
Normal file
51
php/tests/behat/contexts/ServiceLevelContext.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BehatTests;
|
||||||
|
|
||||||
|
use Behat\Behat\Tester\Exception\PendingException;
|
||||||
|
use Behat\Behat\Context\Context;
|
||||||
|
use Behat\Step\Given;
|
||||||
|
use Behat\Step\Then;
|
||||||
|
use Behat\Step\When;
|
||||||
|
use GildedRose\Item;
|
||||||
|
use GildedRose\GildedRose;
|
||||||
|
use PHPUnit\Framework\Assert;
|
||||||
|
|
||||||
|
class ServiceLevelContext implements Context
|
||||||
|
{
|
||||||
|
private Item $item;
|
||||||
|
private GildedRose $gildedRose;
|
||||||
|
|
||||||
|
#[Then('I should see :expectedOutput')]
|
||||||
|
public function iShouldSee(string $expectedOutput): void
|
||||||
|
{
|
||||||
|
Assert::assertEquals([$expectedOutput], $this->result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Given('an item with a sell_in of :initialellIn and a quality of :initialQuality')]
|
||||||
|
public function anItemWithASellInOfAndAQualityOf(int $initialellIn, int $initialQuality)
|
||||||
|
{
|
||||||
|
$this->item = new Item('foo', $initialellIn, $initialQuality);
|
||||||
|
$this->gildedRose = new GildedRose([$this->item]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[When('I update the quality')]
|
||||||
|
public function iUpdateTheQuality()
|
||||||
|
{
|
||||||
|
$this->gildedRose->updateQuality();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Then('the item should have a quality of :expectedQuality')]
|
||||||
|
public function theItemShouldHaveAQualityOf($expectedQuality)
|
||||||
|
{
|
||||||
|
Assert::assertEquals($expectedQuality, $this->item->quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[When('I update the quality :noOfDays times')]
|
||||||
|
public function iUpdateTheQualityTimes(int $noOfDays)
|
||||||
|
{
|
||||||
|
for ($i = 0; $i < $noOfDays; $i++) {
|
||||||
|
$this->gildedRose->updateQuality();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
Feature: Default quality degradation
|
||||||
|
In order to keep track of item quality
|
||||||
|
As a shopkeeper
|
||||||
|
I want to see the quality of an item decrease by 1 each day
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: Single quality update
|
||||||
|
Given an item with a sell_in of 20 and a quality of 20
|
||||||
|
When I update the quality
|
||||||
|
Then the item should have a quality of 19
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: Quality updates over multiple days
|
||||||
|
Given an item with a sell_in of 20 and a quality of 20
|
||||||
|
When I update the quality 5 times
|
||||||
|
Then the item should have a quality of 15
|
||||||
Loading…
Reference in New Issue
Block a user