PHP7 Facade

This commit is contained in:
Dominik Liebler
2016-09-23 10:19:17 +02:00
parent e6c67c5da5
commit b556436fa2
7 changed files with 698 additions and 413 deletions

View File

@@ -2,47 +2,34 @@
namespace DesignPatterns\Structural\Facade\Tests;
use DesignPatterns\Structural\Facade\Facade as Computer;
use DesignPatterns\Structural\Facade\Facade;
use DesignPatterns\Structural\Facade\OsInterface;
/**
* FacadeTest shows example of facades.
*/
class FacadeTest extends \PHPUnit_Framework_TestCase
{
public function getComputer()
public function testComputerOn()
{
/** @var OsInterface|\PHPUnit_Framework_MockObject_MockObject $os */
$os = $this->createMock('DesignPatterns\Structural\Facade\OsInterface');
$os->method('getName')
->will($this->returnValue('Linux'));
$bios = $this->getMockBuilder('DesignPatterns\Structural\Facade\BiosInterface')
->setMethods(array('launch', 'execute', 'waitForKeyPress'))
->disableAutoload()
->getMock();
$operatingSys = $this->getMockBuilder('DesignPatterns\Structural\Facade\OsInterface')
->setMethods(array('getName'))
->disableAutoload()
->getMock();
->setMethods(['launch', 'execute', 'waitForKeyPress'])
->disableAutoload()
->getMock();
$bios->expects($this->once())
->method('launch')
->with($operatingSys);
$operatingSys
->expects($this->once())
->method('getName')
->will($this->returnValue('Linux'));
->method('launch')
->with($os);
$facade = new Computer($bios, $operatingSys);
$facade = new Facade($bios, $os);
return array(array($facade, $operatingSys));
}
/**
* @param Computer $facade
* @param OsInterface $os
* @dataProvider getComputer
*/
public function testComputerOn(Computer $facade, OsInterface $os)
{
// interface is simpler :
// the facade interface is simple
$facade->turnOn();
// but I can access to lower component
// but you can also access the underlying components
$this->assertEquals('Linux', $os->getName());
}
}