mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 20:32:15 +00:00
commit
ef5d1ffb9f
3
php/.editorconfig
Normal file
3
php/.editorconfig
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
[*.php]
|
||||
indent_size = 4
|
||||
6
php/.gitignore
vendored
Normal file
6
php/.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
/.idea
|
||||
/report.xml
|
||||
/.phpstorm.meta.php
|
||||
/.phpunit.result.cache
|
||||
/build
|
||||
/vendor
|
||||
132
php/README.md
Normal file
132
php/README.md
Normal file
@ -0,0 +1,132 @@
|
||||
# GildedRose Kata - PHP Version
|
||||
|
||||
See the [top level readme](../README.md) for general information about this exercise. This is the PHP version of the
|
||||
GildedRose Kata.
|
||||
|
||||
## Installation
|
||||
|
||||
The kata uses:
|
||||
|
||||
- PHP 7.2+
|
||||
- [Composer](https://getcomposer.org)
|
||||
|
||||
Recommended:
|
||||
- [Git](https://git-scm.com/downloads)
|
||||
|
||||
Clone the repository
|
||||
|
||||
```sh
|
||||
git clone git@github.com:emilybache/GildedRose-Refactoring-Kata.git
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```shell script
|
||||
git clone https://github.com/emilybache/GildedRose-Refactoring-Kata.git
|
||||
```
|
||||
|
||||
Install all the dependencies using composer
|
||||
|
||||
```shell script
|
||||
cd ./GildedRose-Refactoring-Kata/php
|
||||
composer install
|
||||
```
|
||||
|
||||
## Dependencies
|
||||
|
||||
The project uses composer to install:
|
||||
|
||||
- [PHPUnit](https://phpunit.de/)
|
||||
- [ApprovalTests.PHP](https://github.com/approvals/ApprovalTests.php)
|
||||
- [PHPStan](https://github.com/phpstan/phpstan)
|
||||
- [Easy Coding Standard (ECS)](https://github.com/symplify/easy-coding-standard)
|
||||
- [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/wiki)
|
||||
|
||||
## 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
|
||||
- `GildedRoseTest.php` - Starter test.
|
||||
- `ApprovalTest.php` - alternative approval test (set to 30 days)
|
||||
- `Fixture`
|
||||
- `texttest_fixture.php` used by the approval test, or can be 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:
|
||||
|
||||
```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
|
||||
PHPUnit `composer test` can be run:
|
||||
|
||||
```shell script
|
||||
pu
|
||||
```
|
||||
|
||||
### Tests with Coverage Report
|
||||
|
||||
To run all test and generate a html coverage report run:
|
||||
|
||||
```shell script
|
||||
composer test-coverage
|
||||
```
|
||||
|
||||
The test-coverage report will be created in /builds, it is best viewed by opening **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!
|
||||
|
||||
### Check Code
|
||||
|
||||
To check code, but not fix errors:
|
||||
|
||||
```shell script
|
||||
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:
|
||||
|
||||
```shell script
|
||||
cc
|
||||
```
|
||||
|
||||
### Fix Code
|
||||
|
||||
There are may code fixes automatically provided by ECS, 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
|
||||
PHPUnit `composer fix-cs` can be run:
|
||||
|
||||
```shell script
|
||||
fc
|
||||
```
|
||||
|
||||
## Static Analysis
|
||||
|
||||
PHPStan is used to run static analysis checks:
|
||||
|
||||
```shell script
|
||||
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:
|
||||
|
||||
```shell script
|
||||
ps
|
||||
```
|
||||
|
||||
**Happy coding**!
|
||||
1
php/cc.bat
Normal file
1
php/cc.bat
Normal file
@ -0,0 +1 @@
|
||||
composer check-cs
|
||||
35
php/composer.json
Normal file
35
php/composer.json
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "emilybache/gilded-rose-refactoring-kata",
|
||||
"description": "A kata to practice refactoring, tests and polymorphism",
|
||||
"require": {
|
||||
"php": "^7.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GildedRose\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"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",
|
||||
"approvals/approval-tests": "^1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"checkcode": "phpcs src tests --standard=PSR12",
|
||||
"fixcode": "phpcbf src tests --standard=PSR12",
|
||||
"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",
|
||||
"phpstan": "phpstan analyse --ansi"
|
||||
}
|
||||
}
|
||||
4887
php/composer.lock
generated
Normal file
4887
php/composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
19
php/ecs.yaml
Normal file
19
php/ecs.yaml
Normal file
@ -0,0 +1,19 @@
|
||||
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
php/fc.bat
Normal file
1
php/fc.bat
Normal file
@ -0,0 +1 @@
|
||||
composer fix-cs
|
||||
@ -2,10 +2,10 @@
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use App\GildedRose;
|
||||
use App\Item;
|
||||
use GildedRose\GildedRose;
|
||||
use GildedRose\Item;
|
||||
|
||||
echo "OMGHAI!\n";
|
||||
echo "OMGHAI!" . PHP_EOL;
|
||||
|
||||
$items = array(
|
||||
new Item('+5 Dexterity Vest', 10, 20),
|
||||
@ -28,8 +28,8 @@ if (count($argv) > 1) {
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $days; $i++) {
|
||||
echo("-------- day $i --------\n");
|
||||
echo("name, sellIn, quality\n");
|
||||
echo("-------- day $i --------" . PHP_EOL);
|
||||
echo("name, sellIn, quality" . PHP_EOL);
|
||||
foreach ($items as $item) {
|
||||
echo $item . PHP_EOL;
|
||||
}
|
||||
16
php/phpstan.neon
Normal file
16
php/phpstan.neon
Normal file
@ -0,0 +1,16 @@
|
||||
includes:
|
||||
- vendor/symplify/phpstan-extensions/config/config.neon
|
||||
- vendor/phpstan/phpstan-phpunit/extension.neon
|
||||
|
||||
parameters:
|
||||
paths:
|
||||
- src
|
||||
- tests
|
||||
- fixtures
|
||||
|
||||
# The level 8 is the highest level
|
||||
level: 8
|
||||
|
||||
checkGenericClassInNonGenericObjectType: false
|
||||
|
||||
checkMissingIterableValueType: false
|
||||
17
php/phpunit.xml
Normal file
17
php/phpunit.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?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"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="AllTests">
|
||||
<directory>./tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">./src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
1
php/ps.bat
Normal file
1
php/ps.bat
Normal file
@ -0,0 +1 @@
|
||||
composer phpstan
|
||||
1
php/pu.bat
Normal file
1
php/pu.bat
Normal file
@ -0,0 +1 @@
|
||||
composer test
|
||||
@ -1,16 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
declare(strict_types=1);
|
||||
|
||||
final class GildedRose {
|
||||
namespace GildedRose;
|
||||
|
||||
private $items = [];
|
||||
final class GildedRose
|
||||
{
|
||||
/**
|
||||
* @var Item[]
|
||||
*/
|
||||
private $items;
|
||||
|
||||
public function __construct($items) {
|
||||
public function __construct(array $items)
|
||||
{
|
||||
$this->items = $items;
|
||||
}
|
||||
|
||||
public function updateQuality() {
|
||||
public function updateQuality(): void
|
||||
{
|
||||
foreach ($this->items as $item) {
|
||||
if ($item->name != 'Aged Brie' and $item->name != 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
if ($item->quality > 0) {
|
||||
@ -60,4 +67,3 @@ final class GildedRose {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
35
php/src/Item.php
Normal file
35
php/src/Item.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GildedRose;
|
||||
|
||||
final class Item
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $sell_in;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $quality;
|
||||
|
||||
public function __construct(string $name, int $sell_in, int $quality)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->sell_in = $sell_in;
|
||||
$this->quality = $quality;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return "{$this->name}, {$this->sell_in}, {$this->quality}";
|
||||
}
|
||||
}
|
||||
24
php/tests/ApprovalTest.php
Normal file
24
php/tests/ApprovalTest.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
20
php/tests/GildedRoseTest.php
Normal file
20
php/tests/GildedRoseTest.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use GildedRose\GildedRose;
|
||||
use GildedRose\Item;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class GildedRoseTest extends TestCase
|
||||
{
|
||||
public function testFoo(): void
|
||||
{
|
||||
$items = [new Item('foo', 0, 0)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
$this->assertSame('fixme', $items[0]->name);
|
||||
}
|
||||
}
|
||||
373
php/tests/approvals/ApprovalTest.testTestFixture.approved.txt
Normal file
373
php/tests/approvals/ApprovalTest.testTestFixture.approved.txt
Normal file
@ -0,0 +1,373 @@
|
||||
OMGHAI!
|
||||
-------- day 0 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, 10, 20
|
||||
Aged Brie, 2, 0
|
||||
Elixir of the Mongoose, 5, 7
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 15, 20
|
||||
Backstage passes to a TAFKAL80ETC concert, 10, 49
|
||||
Backstage passes to a TAFKAL80ETC concert, 5, 49
|
||||
Conjured Mana Cake, 3, 6
|
||||
|
||||
-------- day 1 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, 9, 19
|
||||
Aged Brie, 1, 1
|
||||
Elixir of the Mongoose, 4, 6
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 14, 21
|
||||
Backstage passes to a TAFKAL80ETC concert, 9, 50
|
||||
Backstage passes to a TAFKAL80ETC concert, 4, 50
|
||||
Conjured Mana Cake, 2, 5
|
||||
|
||||
-------- day 2 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, 8, 18
|
||||
Aged Brie, 0, 2
|
||||
Elixir of the Mongoose, 3, 5
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 13, 22
|
||||
Backstage passes to a TAFKAL80ETC concert, 8, 50
|
||||
Backstage passes to a TAFKAL80ETC concert, 3, 50
|
||||
Conjured Mana Cake, 1, 4
|
||||
|
||||
-------- day 3 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, 7, 17
|
||||
Aged Brie, -1, 4
|
||||
Elixir of the Mongoose, 2, 4
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 12, 23
|
||||
Backstage passes to a TAFKAL80ETC concert, 7, 50
|
||||
Backstage passes to a TAFKAL80ETC concert, 2, 50
|
||||
Conjured Mana Cake, 0, 3
|
||||
|
||||
-------- day 4 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, 6, 16
|
||||
Aged Brie, -2, 6
|
||||
Elixir of the Mongoose, 1, 3
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 11, 24
|
||||
Backstage passes to a TAFKAL80ETC concert, 6, 50
|
||||
Backstage passes to a TAFKAL80ETC concert, 1, 50
|
||||
Conjured Mana Cake, -1, 1
|
||||
|
||||
-------- day 5 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, 5, 15
|
||||
Aged Brie, -3, 8
|
||||
Elixir of the Mongoose, 0, 2
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 10, 25
|
||||
Backstage passes to a TAFKAL80ETC concert, 5, 50
|
||||
Backstage passes to a TAFKAL80ETC concert, 0, 50
|
||||
Conjured Mana Cake, -2, 0
|
||||
|
||||
-------- day 6 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, 4, 14
|
||||
Aged Brie, -4, 10
|
||||
Elixir of the Mongoose, -1, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 9, 27
|
||||
Backstage passes to a TAFKAL80ETC concert, 4, 50
|
||||
Backstage passes to a TAFKAL80ETC concert, -1, 0
|
||||
Conjured Mana Cake, -3, 0
|
||||
|
||||
-------- day 7 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, 3, 13
|
||||
Aged Brie, -5, 12
|
||||
Elixir of the Mongoose, -2, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 8, 29
|
||||
Backstage passes to a TAFKAL80ETC concert, 3, 50
|
||||
Backstage passes to a TAFKAL80ETC concert, -2, 0
|
||||
Conjured Mana Cake, -4, 0
|
||||
|
||||
-------- day 8 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, 2, 12
|
||||
Aged Brie, -6, 14
|
||||
Elixir of the Mongoose, -3, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 7, 31
|
||||
Backstage passes to a TAFKAL80ETC concert, 2, 50
|
||||
Backstage passes to a TAFKAL80ETC concert, -3, 0
|
||||
Conjured Mana Cake, -5, 0
|
||||
|
||||
-------- day 9 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, 1, 11
|
||||
Aged Brie, -7, 16
|
||||
Elixir of the Mongoose, -4, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 6, 33
|
||||
Backstage passes to a TAFKAL80ETC concert, 1, 50
|
||||
Backstage passes to a TAFKAL80ETC concert, -4, 0
|
||||
Conjured Mana Cake, -6, 0
|
||||
|
||||
-------- day 10 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, 0, 10
|
||||
Aged Brie, -8, 18
|
||||
Elixir of the Mongoose, -5, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 5, 35
|
||||
Backstage passes to a TAFKAL80ETC concert, 0, 50
|
||||
Backstage passes to a TAFKAL80ETC concert, -5, 0
|
||||
Conjured Mana Cake, -7, 0
|
||||
|
||||
-------- day 11 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -1, 8
|
||||
Aged Brie, -9, 20
|
||||
Elixir of the Mongoose, -6, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 4, 38
|
||||
Backstage passes to a TAFKAL80ETC concert, -1, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -6, 0
|
||||
Conjured Mana Cake, -8, 0
|
||||
|
||||
-------- day 12 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -2, 6
|
||||
Aged Brie, -10, 22
|
||||
Elixir of the Mongoose, -7, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 3, 41
|
||||
Backstage passes to a TAFKAL80ETC concert, -2, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -7, 0
|
||||
Conjured Mana Cake, -9, 0
|
||||
|
||||
-------- day 13 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -3, 4
|
||||
Aged Brie, -11, 24
|
||||
Elixir of the Mongoose, -8, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 2, 44
|
||||
Backstage passes to a TAFKAL80ETC concert, -3, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -8, 0
|
||||
Conjured Mana Cake, -10, 0
|
||||
|
||||
-------- day 14 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -4, 2
|
||||
Aged Brie, -12, 26
|
||||
Elixir of the Mongoose, -9, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 1, 47
|
||||
Backstage passes to a TAFKAL80ETC concert, -4, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -9, 0
|
||||
Conjured Mana Cake, -11, 0
|
||||
|
||||
-------- day 15 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -5, 0
|
||||
Aged Brie, -13, 28
|
||||
Elixir of the Mongoose, -10, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, 0, 50
|
||||
Backstage passes to a TAFKAL80ETC concert, -5, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -10, 0
|
||||
Conjured Mana Cake, -12, 0
|
||||
|
||||
-------- day 16 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -6, 0
|
||||
Aged Brie, -14, 30
|
||||
Elixir of the Mongoose, -11, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, -1, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -6, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -11, 0
|
||||
Conjured Mana Cake, -13, 0
|
||||
|
||||
-------- day 17 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -7, 0
|
||||
Aged Brie, -15, 32
|
||||
Elixir of the Mongoose, -12, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, -2, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -7, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -12, 0
|
||||
Conjured Mana Cake, -14, 0
|
||||
|
||||
-------- day 18 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -8, 0
|
||||
Aged Brie, -16, 34
|
||||
Elixir of the Mongoose, -13, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, -3, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -8, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -13, 0
|
||||
Conjured Mana Cake, -15, 0
|
||||
|
||||
-------- day 19 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -9, 0
|
||||
Aged Brie, -17, 36
|
||||
Elixir of the Mongoose, -14, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, -4, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -9, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -14, 0
|
||||
Conjured Mana Cake, -16, 0
|
||||
|
||||
-------- day 20 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -10, 0
|
||||
Aged Brie, -18, 38
|
||||
Elixir of the Mongoose, -15, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, -5, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -10, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -15, 0
|
||||
Conjured Mana Cake, -17, 0
|
||||
|
||||
-------- day 21 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -11, 0
|
||||
Aged Brie, -19, 40
|
||||
Elixir of the Mongoose, -16, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, -6, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -11, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -16, 0
|
||||
Conjured Mana Cake, -18, 0
|
||||
|
||||
-------- day 22 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -12, 0
|
||||
Aged Brie, -20, 42
|
||||
Elixir of the Mongoose, -17, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, -7, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -12, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -17, 0
|
||||
Conjured Mana Cake, -19, 0
|
||||
|
||||
-------- day 23 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -13, 0
|
||||
Aged Brie, -21, 44
|
||||
Elixir of the Mongoose, -18, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, -8, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -13, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -18, 0
|
||||
Conjured Mana Cake, -20, 0
|
||||
|
||||
-------- day 24 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -14, 0
|
||||
Aged Brie, -22, 46
|
||||
Elixir of the Mongoose, -19, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, -9, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -14, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -19, 0
|
||||
Conjured Mana Cake, -21, 0
|
||||
|
||||
-------- day 25 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -15, 0
|
||||
Aged Brie, -23, 48
|
||||
Elixir of the Mongoose, -20, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, -10, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -15, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -20, 0
|
||||
Conjured Mana Cake, -22, 0
|
||||
|
||||
-------- day 26 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -16, 0
|
||||
Aged Brie, -24, 50
|
||||
Elixir of the Mongoose, -21, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, -11, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -16, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -21, 0
|
||||
Conjured Mana Cake, -23, 0
|
||||
|
||||
-------- day 27 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -17, 0
|
||||
Aged Brie, -25, 50
|
||||
Elixir of the Mongoose, -22, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, -12, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -17, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -22, 0
|
||||
Conjured Mana Cake, -24, 0
|
||||
|
||||
-------- day 28 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -18, 0
|
||||
Aged Brie, -26, 50
|
||||
Elixir of the Mongoose, -23, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, -13, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -18, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -23, 0
|
||||
Conjured Mana Cake, -25, 0
|
||||
|
||||
-------- day 29 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -19, 0
|
||||
Aged Brie, -27, 50
|
||||
Elixir of the Mongoose, -24, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, -14, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -19, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -24, 0
|
||||
Conjured Mana Cake, -26, 0
|
||||
|
||||
-------- day 30 --------
|
||||
name, sellIn, quality
|
||||
+5 Dexterity Vest, -20, 0
|
||||
Aged Brie, -28, 50
|
||||
Elixir of the Mongoose, -25, 0
|
||||
Sulfuras, Hand of Ragnaros, 0, 80
|
||||
Sulfuras, Hand of Ragnaros, -1, 80
|
||||
Backstage passes to a TAFKAL80ETC concert, -15, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -20, 0
|
||||
Backstage passes to a TAFKAL80ETC concert, -25, 0
|
||||
Conjured Mana Cake, -27, 0
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<buildpath>
|
||||
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
|
||||
<buildpathentry kind="src" path="src"/>
|
||||
<buildpathentry kind="src" path="test"/>
|
||||
<buildpathentry kind="con" path="org.eclipse.dltk.USER_LIBRARY/PEAR"/>
|
||||
</buildpath>
|
||||
@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>GildedRose.php</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.dltk.core.scriptbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
<nature>org.eclipse.php.core.PHPNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@ -1,10 +0,0 @@
|
||||
cakephp_app_path=
|
||||
cakephp_core_path=
|
||||
ciunit_config_file=
|
||||
ciunit_path=
|
||||
eclipse.preferences.version=1
|
||||
phpunit_config_file=/GildedRose.php/phpunit.xml
|
||||
preload_script=
|
||||
test_file_pattern=.*test\\.php$
|
||||
test_folders=/GildedRose.php/test
|
||||
testing_framework=PHPUnit
|
||||
@ -1,2 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
include_path=0;/GildedRose.php/test\u00050;/GildedRose.php/src\u00055;org.eclipse.dltk.USER_LIBRARY/PEAR
|
||||
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<fixed facet="php.component"/>
|
||||
<fixed facet="php.core.component"/>
|
||||
<installed facet="php.core.component" version="1"/>
|
||||
<installed facet="php.component" version="5.4"/>
|
||||
</faceted-project>
|
||||
@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/3.7/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
bootstrap="test/bootstrap.php"
|
||||
colors="false"
|
||||
strict="true"
|
||||
verbose="true">
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="AllTests">
|
||||
<directory suffix="_test.php">test</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
class GildedRose {
|
||||
|
||||
private $items;
|
||||
|
||||
function __construct($items) {
|
||||
$this->items = $items;
|
||||
}
|
||||
|
||||
function update_quality() {
|
||||
foreach ($this->items as $item) {
|
||||
if ($item->name != 'Aged Brie' and $item->name != 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
if ($item->quality > 0) {
|
||||
if ($item->name != 'Sulfuras, Hand of Ragnaros') {
|
||||
$item->quality = $item->quality - 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($item->quality < 50) {
|
||||
$item->quality = $item->quality + 1;
|
||||
if ($item->name == 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
if ($item->sell_in < 11) {
|
||||
if ($item->quality < 50) {
|
||||
$item->quality = $item->quality + 1;
|
||||
}
|
||||
}
|
||||
if ($item->sell_in < 6) {
|
||||
if ($item->quality < 50) {
|
||||
$item->quality = $item->quality + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($item->name != 'Sulfuras, Hand of Ragnaros') {
|
||||
$item->sell_in = $item->sell_in - 1;
|
||||
}
|
||||
|
||||
if ($item->sell_in < 0) {
|
||||
if ($item->name != 'Aged Brie') {
|
||||
if ($item->name != 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
if ($item->quality > 0) {
|
||||
if ($item->name != 'Sulfuras, Hand of Ragnaros') {
|
||||
$item->quality = $item->quality - 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$item->quality = $item->quality - $item->quality;
|
||||
}
|
||||
} else {
|
||||
if ($item->quality < 50) {
|
||||
$item->quality = $item->quality + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Item {
|
||||
|
||||
public $name;
|
||||
public $sell_in;
|
||||
public $quality;
|
||||
|
||||
function __construct($name, $sell_in, $quality) {
|
||||
$this->name = $name;
|
||||
$this->sell_in = $sell_in;
|
||||
$this->quality = $quality;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
return "{$this->name}, {$this->sell_in}, {$this->quality}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once 'gilded_rose.php';
|
||||
|
||||
echo "OMGHAI!\n";
|
||||
|
||||
$items = array(
|
||||
new Item('+5 Dexterity Vest', 10, 20),
|
||||
new Item('Aged Brie', 2, 0),
|
||||
new Item('Elixir of the Mongoose', 5, 7),
|
||||
new Item('Sulfuras, Hand of Ragnaros', 0, 80),
|
||||
new Item('Sulfuras, Hand of Ragnaros', -1, 80),
|
||||
new Item('Backstage passes to a TAFKAL80ETC concert', 15, 20),
|
||||
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)
|
||||
);
|
||||
|
||||
$app = new GildedRose($items);
|
||||
|
||||
$days = 2;
|
||||
if (count($argv) > 1) {
|
||||
$days = (int) $argv[1];
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $days; $i++) {
|
||||
echo("-------- day $i --------\n");
|
||||
echo("name, sellIn, quality\n");
|
||||
foreach ($items as $item) {
|
||||
echo $item . PHP_EOL;
|
||||
}
|
||||
echo PHP_EOL;
|
||||
$app->update_quality();
|
||||
}
|
||||
@ -1,2 +0,0 @@
|
||||
<?php
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__.'/../src');
|
||||
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once 'gilded_rose.php';
|
||||
|
||||
class GildedRoseTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function testFoo() {
|
||||
$items = array(new Item("foo", 0, 0));
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->update_quality();
|
||||
$this->assertEquals("fixme", $items[0]->name);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
Requirements
|
||||
------------
|
||||
|
||||
**PHP 7:**
|
||||
|
||||
This is usually bundled with your operating system, or fetchable using a package manager like `apt` or `homebrew`.
|
||||
|
||||
Windows users can find the latest version here: https://windows.php.net/download#php-7.3
|
||||
|
||||
If you want to compile from source code, that can be found here: https://www.php.net/downloads.php
|
||||
|
||||
**Composer:**
|
||||
|
||||
Composer is PHP's main package and dependency management tool.
|
||||
|
||||
It can be downloaded here: https://getcomposer.org/download/
|
||||
|
||||
Getting Started
|
||||
---------------
|
||||
|
||||
To begin the kata, install the dependencies and run `phpunit`:
|
||||
|
||||
```
|
||||
cd php7
|
||||
composer install
|
||||
vendor/bin/phpunit
|
||||
```
|
||||
|
||||
If the "install" command does not work, try running `composer update` instead.
|
||||
This will tell composer that it has permission to look for a newer version of
|
||||
its dependencies.
|
||||
|
||||
If things are still not cooperating, you can try this extreme approach:
|
||||
|
||||
```
|
||||
composer remove phpunit/phpunit
|
||||
composer require phpunit/phpunit
|
||||
```
|
||||
|
||||
To exercise the code outside of phpunit, for example to visually confirm that it is working,
|
||||
use the `texttest_fixture` script:
|
||||
|
||||
```
|
||||
php fixtures/texttest_fixture.php
|
||||
```
|
||||
|
||||
Tips
|
||||
----
|
||||
|
||||
PHPUnit has a very thorough reference manual. It would be particularly useful to explore the
|
||||
[Data Providers](https://phpunit.readthedocs.io/en/8.1/writing-tests-for-phpunit.html#data-providers) section.
|
||||
@ -1,10 +0,0 @@
|
||||
{
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
||||
1491
php7/composer.lock
generated
1491
php7/composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,19 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/3.7/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
colors="false"
|
||||
verbose="true">
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="AllTests">
|
||||
<directory suffix="Test.php">test</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
final class Item {
|
||||
|
||||
public $name;
|
||||
public $sell_in;
|
||||
public $quality;
|
||||
|
||||
function __construct($name, $sell_in, $quality) {
|
||||
$this->name = $name;
|
||||
$this->sell_in = $sell_in;
|
||||
$this->quality = $quality;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
return "{$this->name}, {$this->sell_in}, {$this->quality}";
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
class GildedRoseTest extends \PHPUnit\Framework\TestCase {
|
||||
public function testFoo() {
|
||||
$items = [new Item("foo", 0, 0)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
$this->assertEquals("fixme", $items[0]->name);
|
||||
}
|
||||
}
|
||||
@ -1,2 +0,0 @@
|
||||
<?php
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__.'/../src');
|
||||
Loading…
Reference in New Issue
Block a user