mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-11 20:02:09 +00:00
Move php to php5 and add a php7 example that uses composer
This commit is contained in:
parent
d86e26b192
commit
d1b6306324
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ bin
|
|||||||
obj
|
obj
|
||||||
*.sln.DotSettings.user
|
*.sln.DotSettings.user
|
||||||
.vs
|
.vs
|
||||||
|
vendor
|
||||||
|
|||||||
10
php7/composer.json
Normal file
10
php7/composer.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^8.1"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"App\\": "src/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1491
php7/composer.lock
generated
Normal file
1491
php7/composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
38
php7/fixtures/texttest_fixture.php
Normal file
38
php7/fixtures/texttest_fixture.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
|
use App\GildedRose;
|
||||||
|
use App\Item;
|
||||||
|
|
||||||
|
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->updateQuality();
|
||||||
|
}
|
||||||
13
php7/phpunit.xml
Normal file
13
php7/phpunit.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?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>
|
||||||
|
</phpunit>
|
||||||
63
php7/src/GildedRose.php
Normal file
63
php7/src/GildedRose.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
class GildedRose {
|
||||||
|
|
||||||
|
private $items = [];
|
||||||
|
|
||||||
|
function __construct($items) {
|
||||||
|
$this->items = $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateQuality() {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
21
php7/src/Item.php
Normal file
21
php7/src/Item.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
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}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
14
php7/test/GildedRoseTest.php
Normal file
14
php7/test/GildedRoseTest.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
|
class GildedRoseTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
public function testFoo() {
|
||||||
|
$items = array(new Item("foo", 0, 0));
|
||||||
|
$gildedRose = new GildedRose($items);
|
||||||
|
$gildedRose->updateQuality();
|
||||||
|
$this->assertEquals("fixme", $items[0]->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
2
php7/test/bootstrap.php
Normal file
2
php7/test/bootstrap.php
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<?php
|
||||||
|
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__.'/../src');
|
||||||
Loading…
Reference in New Issue
Block a user