Skip to content

Instantly share code, notes, and snippets.

@mmenozzi
Created February 15, 2014 17:03
Show Gist options
  • Save mmenozzi/9022000 to your computer and use it in GitHub Desktop.
Save mmenozzi/9022000 to your computer and use it in GitHub Desktop.
<?php
/**
* @author Manuele Menozzi <[email protected]>
*/
include 'VendingMachine.php';
class VendingMachineTest extends PHPUnit_Framework_TestCase
{
/**
* @var VendingMachine
*/
private $vendingMachine;
public function setUp()
{
$this->vendingMachine = new VendingMachine();
}
public function testInsertCoin()
{
$this->vendingMachine->addCoin(0.1);
$this->vendingMachine->addCoin(0.5);
$this->vendingMachine->addCoin(0.05);
$this->assertEquals(0.65, $this->vendingMachine->getCurrentCredit());
$this->vendingMachine->addCoin(1);
$this->assertEquals(1.65, $this->vendingMachine->getCurrentCredit());
}
public function testSellItemAndReturn()
{
$this->vendingMachine->addCoin(0.1);
$this->vendingMachine->addCoin(0.5);
$this->vendingMachine->addCoin(0.05);
$this->vendingMachine->addCoin(1);
$this->vendingMachine->sellItem('coffe');
// Ipotizziamo che il caffè costi 0,38 €
$this->assertEquals(1.27, $this->vendingMachine->getCurrentCredit());
$return = $this->vendingMachine->returnCredit();
$this->assertEquals(1.27, $return);
$this->assertEquals(0, $this->vendingMachine->getCurrentCredit());
}
public function testMachineDoesNotAcceptInvalidCoin()
{
$this->vendingMachine->addCoin(0.01);
$this->assertEquals(0, $this->vendingMachine->getCurrentCredit());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment