diff --git a/Facade/Computer.php b/Facade/Computer.php new file mode 100644 index 0000000..4f6c12d --- /dev/null +++ b/Facade/Computer.php @@ -0,0 +1,58 @@ +bios = $bios; + $this->opsys = $os; + } + + public function turnOn() + { + $this->bios->execute(); + $this->bios->waitForKeyPress(); + $this->bios->launch($this->opsys); + } + + public function turnOff() + { + $this->opsys->halt(); + $this->bios->powerDown(); + } + +} \ No newline at end of file diff --git a/Tests/Facade/FacadeTest.php b/Tests/Facade/FacadeTest.php new file mode 100644 index 0000000..85e3f95 --- /dev/null +++ b/Tests/Facade/FacadeTest.php @@ -0,0 +1,51 @@ +getMockBuilder('DesignPatterns\Facade\BiosInterface') + ->setMethods(array('launch', 'execute', 'waitForKeyPress')) + ->disableAutoload() + ->getMock(); + $operatingSys = $this->getMockBuilder('DesignPatterns\Facade\OsInterface') + ->setMethods(array('getName')) + ->disableAutoload() + ->getMock(); + $bios->expects($this->once()) + ->method('launch') + ->with($operatingSys); + $operatingSys + ->expects($this->once()) + ->method('getName') + ->will($this->returnValue('Linux')); + + $facade = new Computer($bios, $operatingSys); + return array(array($facade, $operatingSys)); + } + + /** + * @dataProvider getComputer + */ + public function testComputerOn(Computer $facade, $os) + { + // interface is simpler : + $facade->turnOn(); + // but I can access to lower component + $this->assertEquals('Linux', $os->getName()); + } + +} \ No newline at end of file