(not design) pattern : simple factory

This commit is contained in:
Trismegiste
2013-05-10 20:22:43 +02:00
parent 87d4c9277d
commit 9b7330795d
5 changed files with 159 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Tests\SimpleFactory;
use DesignPatterns\SimpleFactory\ConcreteFactory;
/**
* SimpleFactoryTest tests the Simple Factory pattern
*
* @author flo
*/
class SimpleFactoryTest extends \PHPUnit_Framework_TestCase
{
protected $factory;
protected function setUp()
{
$this->factory = new ConcreteFactory();
}
public function getType()
{
return array(
array('bicycle'),
array('other')
);
}
/**
* @dataProvider getType
*/
public function testCreation($type)
{
$obj = $this->factory->createVehicle($type);
$this->assertInstanceOf('DesignPatterns\SimpleFactory\Vehicle', $obj);
}
/**
* @expectedException \InvalidArgumentException
*/
public function testBadType()
{
$this->factory->createVehicle('car');
}
}