예제 #1
0
 public function testLight()
 {
     $lamp = new Light();
     $switchUp = new FlipUpCommand($lamp);
     $switchDown = new FlipDownCommand($lamp);
     $s = new Switcher();
     $this->assertEquals('The light is off', $s->storeAndExecute($switchDown));
     $this->assertEquals('The light is on', $s->storeAndExecute($switchUp));
 }
예제 #2
0
<?php

require 'light.php';
$lamp = new Light();
$switchUp = new FlipUpCommand($lamp);
$switchDown = new FlipDownCommand($lamp);
$s = new Switcher();
$case = "off";
if ($case == "on") {
    echo $s->storeAndExecute($switchUp);
} else {
    echo $s->storeAndExecute($switchDown);
}