diff --git a/php/behat.yml b/php/behat.yml new file mode 100644 index 00000000..883c613c --- /dev/null +++ b/php/behat.yml @@ -0,0 +1,9 @@ +default: + + suites: + + servicelevel: + paths: [ '%paths.base%/tests/behat/feature_files' ] + filters: + tags: ~@wip + contexts: [ 'BehatTests\ServiceLevelContext' ] diff --git a/php/composer.json b/php/composer.json index 5c4459d8..a07c73bf 100644 --- a/php/composer.json +++ b/php/composer.json @@ -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", diff --git a/php/tests/behat/contexts/ServiceLevelContext.php b/php/tests/behat/contexts/ServiceLevelContext.php new file mode 100644 index 00000000..1253d94a --- /dev/null +++ b/php/tests/behat/contexts/ServiceLevelContext.php @@ -0,0 +1,51 @@ +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(); + } + } +} diff --git a/php/tests/behat/feature_files/default-quality-degradation.feature b/php/tests/behat/feature_files/default-quality-degradation.feature new file mode 100644 index 00000000..6ce4dbe4 --- /dev/null +++ b/php/tests/behat/feature_files/default-quality-degradation.feature @@ -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