mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
Add PHP8
- 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:
parent
179a22ecfa
commit
10d3cf7f5a
@ -7,10 +7,11 @@ See the [top level readme](../README.md) for general information about this exer
|
||||
|
||||
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)
|
||||
|
||||
Recommended:
|
||||
|
||||
- [Git](https://git-scm.com/downloads)
|
||||
|
||||
Clone the repository
|
||||
@ -45,24 +46,26 @@ 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.
|
||||
- `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
|
||||
- `GildedRoseTest.php` - Starter test.
|
||||
- `ApprovalTest.php` - alternative approval test (set to 30 days)
|
||||
- `GildedRoseTest.php` - starter test.
|
||||
- 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`
|
||||
- `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
|
||||
|
||||
PHPUnit is pre-configured to run tests. PHPUnit can be run using a composer script. To run the unit tests, from the
|
||||
root of the PHP project run:
|
||||
PHPUnit is configured for testing, a composer script has been provided. To run the unit tests, from the root of the PHP
|
||||
project run:
|
||||
|
||||
```shell script
|
||||
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:
|
||||
|
||||
```shell script
|
||||
@ -77,12 +80,13 @@ 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 **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
|
||||
|
||||
Easy Coding Standard (ECS) is used to check for style and code standards, **PSR-12** is used. The current code is not
|
||||
upto 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
|
||||
|
||||
@ -92,8 +96,8 @@ To check code, but not fix errors:
|
||||
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
|
||||
same PHPUnit `composer check-cs` can be run:
|
||||
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:
|
||||
|
||||
```shell script
|
||||
cc
|
||||
@ -101,13 +105,13 @@ cc
|
||||
|
||||
### 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
|
||||
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:
|
||||
|
||||
```shell script
|
||||
@ -122,8 +126,8 @@ PHPStan is used to run static analysis checks:
|
||||
composer phpstan
|
||||
```
|
||||
|
||||
On Windows a batch file has been created, similar to an alias on Linux/Mac (e.g. `alias ps="composer phpstan"`), the
|
||||
same PHPUnit `composer phpstan` can be run:
|
||||
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:
|
||||
|
||||
```shell script
|
||||
ps
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
"name": "emilybache/gilded-rose-refactoring-kata",
|
||||
"description": "A kata to practice refactoring, tests and polymorphism",
|
||||
"require": {
|
||||
"php": "^7.2"
|
||||
"php": "^7.3 || ^8.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@ -15,11 +15,11 @@
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8.0",
|
||||
"phpstan/phpstan": "^0.12.23",
|
||||
"phpstan/phpstan-phpunit": "^0.12.8",
|
||||
"symplify/easy-coding-standard": "^7.3",
|
||||
"symplify/phpstan-extensions": "^7.3",
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"phpstan/phpstan": "^0.12.85",
|
||||
"phpstan/phpstan-phpunit": "^0.12.18",
|
||||
"symplify/easy-coding-standard": "^9.3",
|
||||
"symplify/phpstan-extensions": "^9.3",
|
||||
"approvals/approval-tests": "^1.4"
|
||||
},
|
||||
"scripts": {
|
||||
@ -28,8 +28,8 @@
|
||||
"test": "phpunit",
|
||||
"tests": "phpunit",
|
||||
"test-coverage": "phpunit --coverage-html build/coverage",
|
||||
"check-cs": "ecs check src tests --ansi",
|
||||
"fix-cs": "ecs check src tests --fix --ansi",
|
||||
"check-cs": "ecs check",
|
||||
"fix-cs": "ecs check --fix",
|
||||
"phpstan": "phpstan analyse --ansi"
|
||||
}
|
||||
}
|
||||
|
||||
3735
php/composer.lock
generated
3735
php/composer.lock
generated
File diff suppressed because it is too large
Load Diff
36
php/ecs.php
Normal file
36
php/ecs.php
Normal 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");
|
||||
};
|
||||
19
php/ecs.yaml
19
php/ecs.yaml
@ -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/**
|
||||
@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use GildedRose\GildedRose;
|
||||
use GildedRose\Item;
|
||||
|
||||
echo "OMGHAI!" . PHP_EOL;
|
||||
echo 'OMGHAI!' . PHP_EOL;
|
||||
|
||||
$items = array(
|
||||
$items = [
|
||||
new Item('+5 Dexterity Vest', 10, 20),
|
||||
new Item('Aged Brie', 2, 0),
|
||||
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', 5, 49),
|
||||
// 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);
|
||||
|
||||
@ -28,8 +30,8 @@ if (count($argv) > 1) {
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $days; $i++) {
|
||||
echo("-------- day $i --------" . PHP_EOL);
|
||||
echo("name, sellIn, quality" . PHP_EOL);
|
||||
echo "-------- day ${i} --------" . PHP_EOL;
|
||||
echo 'name, sellIn, quality' . PHP_EOL;
|
||||
foreach ($items as $item) {
|
||||
echo $item . PHP_EOL;
|
||||
}
|
||||
|
||||
@ -1,17 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true"
|
||||
>
|
||||
<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">
|
||||
<coverage processUncoveredFiles="true">
|
||||
<include>
|
||||
<directory suffix=".php">./src</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
<testsuites>
|
||||
<testsuite name="AllTests">
|
||||
<directory>./tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">./src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user