public function testDispenseToSoldOutStateTwoBalls()
 {
     $machine = new GumballMachine(2);
     $state = new WinnerState($machine);
     $expected = "You are a winner! You get two gumballs for your quarter\nA gumball comes rolling out the slot...\nA gumball comes rolling out the slot...\nOops, out of gumballs!";
     $this->assertEquals($expected, $state->dispense());
     $this->assertInstanceOf('Kondrat\\DesignPatterns\\State\\ConcreteState\\SoldOutState', $machine->getState());
 }
 public function testDispenseToSoldOutState()
 {
     $machine = new GumballMachine(1);
     $state = new SoldState($machine);
     $expected = "A gumball comes rolling out the slot...\nOops, out of gumballs!\n";
     $this->assertEquals($expected, $state->dispense());
     $this->assertInstanceOf('Kondrat\\DesignPatterns\\State\\ConcreteState\\SoldOutState', $machine->getState());
 }
Beispiel #3
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Kondrat\DesignPatterns\State\GumballMachine;
$machine = new GumballMachine(5);
echo "<pre>";
echo $machine;
echo "\n";
echo $machine->insertQuarter();
echo $machine->turnCrank();
echo "\n";
echo $machine;
echo "\n";
echo $machine->insertQuarter();
echo $machine->ejectQuarter();
echo $machine->turnCrank();
echo "\n";
echo $machine;
echo "\n";
echo $machine->insertQuarter();
echo $machine->turnCrank();
echo $machine->insertQuarter();
echo $machine->turnCrank();
echo $machine->ejectQuarter();
echo "\n";
echo $machine;
echo "\n";
echo $machine->insertQuarter();
echo $machine->insertQuarter();
echo $machine->turnCrank();
echo $machine->insertQuarter();
 public function testInitialState()
 {
     $this->assertInstanceOf('Kondrat\\DesignPatterns\\State\\ConcreteState\\NoQuarterState', $this->machine->getState());
     $machine = new GumballMachine(0);
     $this->assertInstanceOf('Kondrat\\DesignPatterns\\State\\ConcreteState\\SoldOutState', $machine->getState());
 }