mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-05 14:37:27 +02:00
test with mockup
This commit is contained in:
51
Tests/Facade/FacadeTest.php
Normal file
51
Tests/Facade/FacadeTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* DesignPatternPHP
|
||||
*/
|
||||
|
||||
namespace DesignPatterns\Tests\Facade;
|
||||
|
||||
use DesignPatterns\Facade\Computer;
|
||||
use DesignPatterns\Facade\Installer;
|
||||
|
||||
/**
|
||||
* FacadeTest shows example of facades
|
||||
*/
|
||||
class FacadeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function getComputer()
|
||||
{
|
||||
$bios = $this->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());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user