GildedRose-Refactoring-Kata/php/README.md
2021-05-11 22:53:30 +03:00

4.1 KiB

GildedRose Kata - PHP Version

See the top level readme for general information about this exercise. This is the PHP version of the GildedRose Kata.

Installation

The kata uses:

Dependencies

The project used composer to install:

Folders

  • src - contains the two classes:
    • Item.php - this class was not changed;
    • GildedRose.php - this class was refactored, and the new feature added;
  • tests - contains the tests:
    • GildedRoseTest.php - starter test.
  • Fixture
    • texttest_fixture.php this was used by an ApprovalTests, and run from the command line

Testing

Tests were written for all the requirement specifications listed in "Gilded Rose Requirements".

Test methods takes initial (starting) values, that can be changed accordingly. E.g., "31" for sell_in value and "50" for quality value:

$items = [new Item('+5 Dexterity Vest', 31, 50)];

puts them in GildedRose Class updateQuality() method and checks for expected values. E.g., "30" for sell_in value and "49" for quality value:

self::assertSame(30, $items[0]->sell_in);
self::assertSame(49, $items[0]->quality);

Furthermore, where more than one arbitrary arguments are desired for single test, @dataProvider method was used and relevant Scenarios were created. E.g., 'data' array accepts initial values for sell_in and quality and 'expect' array - expected ones.

public function qualityNeverNegativeScenario(): array
    {
        return [
            [[
                'data' => [
                    'sell_in' => 1,
                    'quality' => 0,
                ],
                'expect' => [
                    'sell_in' => 0,
                    'quality' => 0,
                    
                ]
            ]]

To run the unit tests, from the root of the PHP project run:

composer test

A Windows a batch file has been created, like an alias on Linux/Mac (e.g. alias pu="composer test"), the same PHPUnit composer test can be run:

pu

Approval Test

'sell_in' and 'quality' values of GildedRose items for 31 day were generated via terminal command from the root of the PHP project:

php fixtures/texttest_fixture.php

and compared to provided "Approval Test document" until data were identical.

Tests with Coverage Report

To run all test and generate a html coverage report run:

composer test-coverage

The test-coverage report will be created in /builds, it is best viewed by opening /builds/index.html in your browser.

Code Standard

Easy Coding Standard (ECS) is configured for style and code standards, PSR-12 is used. The current code is not upto standard!

Check Code

To check code, but not fix errors:

composer check-cs

On Windows a batch file has been created, like an alias on Linux/Mac (e.g. alias cc="composer check-cs"), the same PHPUnit composer check-cs can be run:

cc

Fix Code

ECS provides may code fixes, automatically, if advised to run --fix, the following script can be run:

composer fix-cs

On Windows a batch file has been created, like an alias on Linux/Mac (e.g. alias fc="composer fix-cs"), the same PHPUnit composer fix-cs can be run:

fc

Static Analysis

PHPStan is used to run static analysis checks:

composer phpstan

On Windows a batch file has been created, like an alias on Linux/Mac (e.g. alias ps="composer phpstan"), the same PHPUnit composer phpstan can be run:

ps