mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-29 03:00:15 +02:00
a unit test for the builder pattern
This commit is contained in:
46
Tests/Builder/DirectorTest.php
Normal file
46
Tests/Builder/DirectorTest.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DesignPatternPHP
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace DesignPatterns\Tests\Builder;
|
||||||
|
|
||||||
|
use DesignPatterns\Builder\Director;
|
||||||
|
use DesignPatterns\Builder\CarBuilder;
|
||||||
|
use DesignPatterns\Builder\BikeBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DirectorTest tests the builder pattern
|
||||||
|
*/
|
||||||
|
class DirectorTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $director;
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$this->director = new Director();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBuilder()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(new CarBuilder()),
|
||||||
|
array(new BikeBuilder())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Here we test the build process. Notice that the client don't know
|
||||||
|
* anything about the contrete builder.
|
||||||
|
*
|
||||||
|
* @dataProvider getBuilder
|
||||||
|
*/
|
||||||
|
public function testBuild(\DesignPatterns\Builder\Builder $builder)
|
||||||
|
{
|
||||||
|
$newVehicle = $this->director->build($builder);
|
||||||
|
$this->assertInstanceOf('DesignPatterns\Builder\Parts\Vehicle', $newVehicle);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user