mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-06 23:16:33 +02:00
PHP7 Facade
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user