- update README.md with latest PHP information
- update composer.json to support PHP 7.3 to PHP8
  - active support for PHP 7.2 ended 6 Dec 2020
  - PHP8 was released 26-Nov-2020
  - update the dependencies
- PHPUnit now version 9.5 and config file updated
- ECS now version 9.3 and config file changed from `ecs.yaml` to `ecs.php`

ApprovalTest removed, in line with latest readme, all set for refactoring :)

Tested with PHP 7.3, 7.4 and 8.0 one failing "fixme" != "foo" test!
This commit is contained in:
Pen-y-Fan 2021-05-03 16:02:47 +01:00
parent 179a22ecfa
commit 10d3cf7f5a
9 changed files with 2569 additions and 1391 deletions

View File

@ -1,16 +1,17 @@
# GildedRose Kata - PHP Version # GildedRose Kata - PHP Version
See the [top level readme](../README.md) for general information about this exercise. This is the PHP version of the See the [top level readme](../README.md) for general information about this exercise. This is the PHP version of the
GildedRose Kata. GildedRose Kata.
## Installation ## Installation
The kata uses: The kata uses:
- PHP 7.2+ - [PHP 7.3 or 7.4 or 8.0+](https://www.php.net/downloads.php)
- [Composer](https://getcomposer.org) - [Composer](https://getcomposer.org)
Recommended: Recommended:
- [Git](https://git-scm.com/downloads) - [Git](https://git-scm.com/downloads)
Clone the repository Clone the repository
@ -39,31 +40,33 @@ The project uses composer to install:
- [PHPUnit](https://phpunit.de/) - [PHPUnit](https://phpunit.de/)
- [ApprovalTests.PHP](https://github.com/approvals/ApprovalTests.php) - [ApprovalTests.PHP](https://github.com/approvals/ApprovalTests.php)
- [PHPStan](https://github.com/phpstan/phpstan) - [PHPStan](https://github.com/phpstan/phpstan)
- [Easy Coding Standard (ECS)](https://github.com/symplify/easy-coding-standard) - [Easy Coding Standard (ECS)](https://github.com/symplify/easy-coding-standard)
- [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/wiki) - [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/wiki)
## Folders ## Folders
- `src` - contains the two classes: - `src` - contains the two classes:
- `Item.php` - this class should not be changed. - `Item.php` - this class should not be changed
- `GildedRose.php` - this class needs to be refactored, and the new feature added. - `GildedRose.php` - this class needs to be refactored, and the new feature added
- `tests` - contains the tests - `tests` - contains the tests
- `GildedRoseTest.php` - Starter test. - `GildedRoseTest.php` - starter test.
- `ApprovalTest.php` - alternative approval test (set to 30 days) - Tip: ApprovalTests has been included as a dev dependency, see the PHP version of
the [Theatrical Players Refactoring Kata](https://github.com/emilybache/Theatrical-Players-Refactoring-Kata/)
for an example
- `Fixture` - `Fixture`
- `texttest_fixture.php` used by the approval test, or can be run from the command line - `texttest_fixture.php` this could be used by an ApprovalTests, or run from the command line
## Testing ## Testing
PHPUnit is pre-configured to run tests. PHPUnit can be run using a composer script. To run the unit tests, from the PHPUnit is configured for testing, a composer script has been provided. To run the unit tests, from the root of the PHP
root of the PHP project run: project run:
```shell script ```shell script
composer test composer test
``` ```
On Windows a batch file has been created, similar to an alias on Linux/Mac (e.g. `alias pu="composer test"`), the same 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: PHPUnit `composer test` can be run:
```shell script ```shell script
pu pu
@ -77,12 +80,13 @@ To run all test and generate a html coverage report run:
composer test-coverage composer test-coverage
``` ```
The test-coverage report will be created in /builds, it is best viewed by opening **index.html** in your browser. The test-coverage report will be created in /builds, it is best viewed by opening /builds/**index.html** in your
browser.
## Code Standard ## Code Standard
Easy Coding Standard (ECS) is used to check for style and code standards, **PSR-12** is used. The current code is not Easy Coding Standard (ECS) is configured for style and code standards, **PSR-12** is used. The current code is not upto
upto standard! standard!
### Check Code ### Check Code
@ -92,8 +96,8 @@ To check code, but not fix errors:
composer check-cs composer check-cs
``` ```
On Windows a batch file has been created, similar to an alias on Linux/Mac (e.g. `alias cc="composer check-cs"`), the On Windows a batch file has been created, like an alias on Linux/Mac (e.g. `alias cc="composer check-cs"`), the same
same PHPUnit `composer check-cs` can be run: PHPUnit `composer check-cs` can be run:
```shell script ```shell script
cc cc
@ -101,14 +105,14 @@ cc
### Fix Code ### Fix Code
There are may code fixes automatically provided by ECS, if advised to run --fix, the following script can be run: ECS provides may code fixes, automatically, if advised to run --fix, the following script can be run:
```shell script ```shell script
composer fix-cs composer fix-cs
``` ```
On Windows a batch file has been created, similar to an alias on Linux/Mac (e.g. `alias fc="composer fix-cs"`), the same 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: PHPUnit `composer fix-cs` can be run:
```shell script ```shell script
fc fc
@ -122,11 +126,11 @@ PHPStan is used to run static analysis checks:
composer phpstan composer phpstan
``` ```
On Windows a batch file has been created, similar to an alias on Linux/Mac (e.g. `alias ps="composer phpstan"`), the On Windows a batch file has been created, like an alias on Linux/Mac (e.g. `alias ps="composer phpstan"`), the same
same PHPUnit `composer phpstan` can be run: PHPUnit `composer phpstan` can be run:
```shell script ```shell script
ps ps
``` ```
**Happy coding**! **Happy coding**!

View File

@ -2,7 +2,7 @@
"name": "emilybache/gilded-rose-refactoring-kata", "name": "emilybache/gilded-rose-refactoring-kata",
"description": "A kata to practice refactoring, tests and polymorphism", "description": "A kata to practice refactoring, tests and polymorphism",
"require": { "require": {
"php": "^7.2" "php": "^7.3 || ^8.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
@ -15,11 +15,11 @@
} }
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^8.0", "phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^0.12.23", "phpstan/phpstan": "^0.12.85",
"phpstan/phpstan-phpunit": "^0.12.8", "phpstan/phpstan-phpunit": "^0.12.18",
"symplify/easy-coding-standard": "^7.3", "symplify/easy-coding-standard": "^9.3",
"symplify/phpstan-extensions": "^7.3", "symplify/phpstan-extensions": "^9.3",
"approvals/approval-tests": "^1.4" "approvals/approval-tests": "^1.4"
}, },
"scripts": { "scripts": {
@ -28,8 +28,8 @@
"test": "phpunit", "test": "phpunit",
"tests": "phpunit", "tests": "phpunit",
"test-coverage": "phpunit --coverage-html build/coverage", "test-coverage": "phpunit --coverage-html build/coverage",
"check-cs": "ecs check src tests --ansi", "check-cs": "ecs check",
"fix-cs": "ecs check src tests --fix --ansi", "fix-cs": "ecs check --fix",
"phpstan": "phpstan analyse --ansi" "phpstan": "phpstan analyse --ansi"
} }
} }

3773
php/composer.lock generated

File diff suppressed because it is too large Load Diff

36
php/ecs.php Normal file
View File

@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(ArraySyntaxFixer::class)
->call('configure', [[
'syntax' => 'short',
]]);
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [
__DIR__ . '/fixtures',
__DIR__ . '/src',
__DIR__ . '/tests',
]);
$parameters->set
(Option::SETS,
[
SetList::CLEAN_CODE,
SetList::COMMON,
SetList::PSR_12,
]
);
$parameters->set(Option::INDENTATION, "spaces");
$parameters->set(Option::LINE_ENDING, "\n");
};

View File

@ -1,19 +0,0 @@
parameters:
sets:
- 'psr12'
- 'php70'
- 'php71'
- 'symplify'
- 'common'
- 'clean-code'
line_ending: "\n"
# 4 spaces
indentation: " "
skip:
Symplify\CodingStandard\Sniffs\Architecture\DuplicatedClassShortNameSniff: null
# Allow snake_case for tests
PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff:
- tests/**

View File

@ -1,13 +1,15 @@
<?php <?php
declare(strict_types=1);
require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../vendor/autoload.php';
use GildedRose\GildedRose; use GildedRose\GildedRose;
use GildedRose\Item; use GildedRose\Item;
echo "OMGHAI!" . PHP_EOL; echo 'OMGHAI!' . PHP_EOL;
$items = array( $items = [
new Item('+5 Dexterity Vest', 10, 20), new Item('+5 Dexterity Vest', 10, 20),
new Item('Aged Brie', 2, 0), new Item('Aged Brie', 2, 0),
new Item('Elixir of the Mongoose', 5, 7), new Item('Elixir of the Mongoose', 5, 7),
@ -17,8 +19,8 @@ $items = array(
new Item('Backstage passes to a TAFKAL80ETC concert', 10, 49), new Item('Backstage passes to a TAFKAL80ETC concert', 10, 49),
new Item('Backstage passes to a TAFKAL80ETC concert', 5, 49), new Item('Backstage passes to a TAFKAL80ETC concert', 5, 49),
// this conjured item does not work properly yet // this conjured item does not work properly yet
new Item('Conjured Mana Cake', 3, 6) new Item('Conjured Mana Cake', 3, 6),
); ];
$app = new GildedRose($items); $app = new GildedRose($items);
@ -28,8 +30,8 @@ if (count($argv) > 1) {
} }
for ($i = 0; $i < $days; $i++) { for ($i = 0; $i < $days; $i++) {
echo("-------- day $i --------" . PHP_EOL); echo "-------- day ${i} --------" . PHP_EOL;
echo("name, sellIn, quality" . PHP_EOL); echo 'name, sellIn, quality' . PHP_EOL;
foreach ($items as $item) { foreach ($items as $item) {
echo $item . PHP_EOL; echo $item . PHP_EOL;
} }

View File

@ -13,4 +13,4 @@ parameters:
checkGenericClassInNonGenericObjectType: false checkGenericClassInNonGenericObjectType: false
checkMissingIterableValueType: false checkMissingIterableValueType: false

View File

@ -1,17 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" <coverage processUncoveredFiles="true">
bootstrap="vendor/autoload.php" <include>
colors="true" <directory suffix=".php">./src</directory>
> </include>
<testsuites> </coverage>
<testsuite name="AllTests"> <testsuites>
<directory>./tests</directory> <testsuite name="AllTests">
</testsuite> <directory>./tests</directory>
</testsuites> </testsuite>
<filter> </testsuites>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit> </phpunit>

View File

@ -1,24 +0,0 @@
<?php
declare(strict_types=1);
namespace Tests;
use ApprovalTests\Approvals;
use PHPUnit\Framework\TestCase;
class ApprovalTest extends TestCase
{
public function testTestFixture(): void
{
$argv[0] = 'texttest_fixture.php';
$argv[1] = 31;
ob_start();
require_once __DIR__ . '/../fixtures/texttest_fixture.php';
$output = ob_get_contents();
ob_end_clean();
Approvals::verifyString($output);
}
}