Merge pull request #3 from codecop/master

Ported GildedRose to PHP
This commit is contained in:
Emily Bache 2014-04-02 21:43:04 +02:00
commit 4891dcd3a2
9 changed files with 164 additions and 0 deletions

7
php/.buildpath Normal file
View File

@ -0,0 +1,7 @@
<?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>

28
php/.project Normal file
View File

@ -0,0 +1,28 @@
<?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>

View File

@ -0,0 +1,10 @@
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

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
include_path=0;/GildedRose.php/test\u00050;/GildedRose.php/src\u00055;org.eclipse.dltk.USER_LIBRARY/PEAR

View File

@ -0,0 +1,7 @@
<?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>

15
php/phpunit.xml Normal file
View File

@ -0,0 +1,15 @@
<?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>

79
php/src/gilded_rose.php Normal file
View File

@ -0,0 +1,79 @@
<?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}";
}
}

2
php/test/bootstrap.php Normal file
View File

@ -0,0 +1,2 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__.'/../src');

View File

@ -0,0 +1,14 @@
<?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);
}
}