37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace demo\Structural\Facade\Tests;
|
|
|
|
use demo\Structural\Facade\OsInterface;
|
|
|
|
/**
|
|
* 创建自动化测试单元 FacadeTest 。
|
|
*/
|
|
class FacadeTest extends \PHPUnit\Framework\TestCase
|
|
{
|
|
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(['launch', 'execute', 'waitForKeyPress'])
|
|
->disableAutoload()
|
|
->getMock();
|
|
|
|
$bios->expects($this->once())
|
|
->method('launch')
|
|
->with($os);
|
|
|
|
$facade = new Facade($bios, $os);
|
|
|
|
// 门面接口很简单。
|
|
$facade->turnOn();
|
|
|
|
// 但你也可以访问底层组件。
|
|
$this->assertEquals('Linux', $os->getName());
|
|
}
|
|
} |