GildedRose-Refactoring-Kata/php/README.md
Pen-y-Fan 081c69b864 Bump to PHP 8.0+
PHP 7.4 was end of life November 2022, it's time to bump to PHP 8 standard 🎉

- updated starting code to PHP 8 standard
- upgraded tooling (code quality, static analysis) to the latest versions
- tested with PHP 8.0, 8.1 and 8.2
   - the fixture is working
   - the example test is failing, as expected
   - code quality is as expected
   - static analysis is ok
2023-01-07 17:19:35 +00:00

3.5 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:

Recommended:

See GitHub cloning a repository for details on how to create a local copy of this project on your computer.

git clone git@github.com:emilybache/GildedRose-Refactoring-Kata.git

or

git clone https://github.com/emilybache/GildedRose-Refactoring-Kata.git

Install all the dependencies using composer

cd ./GildedRose-Refactoring-Kata/php
composer install

Dependencies

The project uses composer to install:

Folders

  • src - contains the two classes:
    • Item.php - this class should not be changed
    • GildedRose.php - this class needs to be refactored, and the new feature added
  • tests - contains the tests
  • Fixture
    • texttest_fixture.php this could be used by an ApprovalTests, or run from the command line

Fixture

To run the fixture from the php directory:

php .\fixtures\texttest_fixture.php 10

Change 10 to the required days.

Testing

PHPUnit is configured for testing, a composer script has been provided. To run the unit tests, from the root of the PHP project run:

composer tests

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

pu.bat

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.

The XDEbug extension is required for generating the coverage report.

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.bat

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.bat

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.bat

Happy coding!