コード例 #1
0
 function testFoo()
 {
     $items = array(new Item("foo", 0, 0));
     $gildedRose = new GildedRose($items);
     $gildedRose->update_quality();
     $this->assertEquals("fixme", $items[0]->name);
 }
コード例 #2
0
 public function test()
 {
     $received = "";
     $items = $this->makeItems();
     $sut = new GildedRose($items);
     for ($day = 1; $day <= 100; $day++) {
         $received .= $this->formatItemsForDay($day, $items);
         $sut->updateQuality();
     }
     $receivedExpected = $this->compareToApproved($received);
     if (!$receivedExpected) {
         $this->writeReceivedFile($received);
     }
     $this->assertTrue($receivedExpected, "Did not match approved results. Compare files '" . self::GILDED_ROSE_APPROVED_FILE . "' and '" . self::GILDED_ROSE_RECEIVED_FILE . "'");
 }
コード例 #3
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), 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();
}
 /**
  * @param $item
  */
 private function updateQualityForItem($item)
 {
     $rose = new GildedRose(array($item));
     $rose->updateQuality();
 }
コード例 #5
0
<?php

require_once 'GildedRose.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), 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();
}
コード例 #6
0
 function testConjuredItems()
 {
     $items = array(new Item('Conjured Mana Cake', 3, 8), new Item('Conjured Mana Cake', 1, 8), new Item('Conjured Mana Cake', 0, 3));
     $gildedRose = new GildedRose($items);
     // test assertions
     $gildedRose->update_quality();
     // Conjured items degrade 2 in a normal day
     $this->assertEquals(2, $items[0]->sell_in);
     $this->assertEquals(6, $items[0]->quality);
     // check for a degrade of 2 that will increase to 4 upon expiration
     $this->assertEquals(0, $items[1]->sell_in);
     $this->assertEquals(6, $items[1]->quality);
     // ensure can't return negative sell_in values, and non-negative qualities
     $this->assertEquals(0, $items[2]->sell_in);
     $this->assertEquals(0, $items[2]->quality);
     // second iteration to test progressions
     $gildedRose->update_quality();
     // Conjured items degrade 2 in a normal day
     $this->assertEquals(1, $items[0]->sell_in);
     $this->assertEquals(4, $items[0]->quality);
     // check for a degrade of 2 that will increase to 4 upon expiration
     $this->assertEquals(0, $items[1]->sell_in);
     $this->assertEquals(2, $items[1]->quality);
     // ensure can't return negative sell_in values, and non-negative qualities
     $this->assertEquals(0, $items[2]->sell_in);
     $this->assertEquals(0, $items[2]->quality);
 }