mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-09-24 05:21:36 +02:00
47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace DesignPatterns\Structural\Facade\Tests;
|
|
|
|
use DesignPatterns\Structural\Facade\Facade as Computer;
|
|
use DesignPatterns\Structural\Facade\OsInterface;
|
|
|
|
/**
|
|
* FacadeTest shows example of facades.
|
|
*/
|
|
class FacadeTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public function getComputer()
|
|
{
|
|
$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();
|
|
$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, OsInterface $os)
|
|
{
|
|
// interface is simpler :
|
|
$facade->turnOn();
|
|
// but I can access to lower component
|
|
$this->assertEquals('Linux', $os->getName());
|
|
}
|
|
}
|