PHP7 SimpleFactory

This commit is contained in:
Dominik Liebler
2016-09-22 15:05:25 +02:00
parent f4c9af503b
commit 370ce4dd93
9 changed files with 275 additions and 443 deletions

View File

@@ -4,40 +4,11 @@ namespace DesignPatterns\Creational\SimpleFactory\Tests;
use DesignPatterns\Creational\SimpleFactory\SimpleFactory;
/**
* SimpleFactoryTest tests the Simple Factory pattern.
*/
class SimpleFactoryTest extends \PHPUnit_Framework_TestCase
{
protected $factory;
protected function setUp()
public function testCanCreateBicycle()
{
$this->factory = new SimpleFactory();
}
public function getType()
{
return array(
array('bicycle'),
array('other'),
);
}
/**
* @dataProvider getType
*/
public function testCreation($type)
{
$obj = $this->factory->createVehicle($type);
$this->assertInstanceOf('DesignPatterns\Creational\SimpleFactory\VehicleInterface', $obj);
}
/**
* @expectedException \InvalidArgumentException
*/
public function testBadType()
{
$this->factory->createVehicle('car');
$bicycle = (new SimpleFactory())->createBicycle();
$this->assertInstanceOf('DesignPatterns\Creational\SimpleFactory\Bicycle', $bicycle);
}
}