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)); }
<?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); }