To provide behavioural test infrastructure, add install Behat and add first test

This commit is contained in:
Sam Burns 2024-01-24 13:01:43 +00:00
parent fb7d21042e
commit 1a572c1eb7
4 changed files with 80 additions and 2 deletions

9
php/behat.yml Normal file
View File

@ -0,0 +1,9 @@
default:
suites:
servicelevel:
paths: [ '%paths.base%/tests/behat/feature_files' ]
filters:
tags: ~@wip
contexts: [ 'BehatTests\ServiceLevelContext' ]

View File

@ -7,6 +7,7 @@
},
"require-dev": {
"approvals/approval-tests": "dev-Main",
"behat/behat": "^3.14",
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^1.9",
"phpstan/phpstan-phpunit": "^1.3",
@ -20,11 +21,12 @@
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
"Tests\\": "tests/",
"BehatTests\\": "tests/behat/contexts/"
}
},
"scripts": {
"tests": "phpunit",
"tests": "./vendor/bin/phpunit; ./vendor/bin/behat;",
"test-coverage": "phpunit --coverage-html build/coverage",
"check-cs": "ecs check",
"fix-cs": "ecs check --fix",

View 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();
}
}
}

View File

@ -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