mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-02-24 17:52:25 +01:00
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace DesignPatterns\Tests\FactoryMethod;
|
|
|
|
use DesignPatterns\FactoryMethod\FactoryMethod;
|
|
use DesignPatterns\FactoryMethod\GermanFactory;
|
|
use DesignPatterns\FactoryMethod\ItalianFactory;
|
|
|
|
/**
|
|
* FactoryMethodTest tests the factory method pattern
|
|
*/
|
|
class FactoryMethodTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
|
|
protected $type = array(
|
|
FactoryMethod::CHEAP,
|
|
FactoryMethod::FAST
|
|
);
|
|
|
|
public function getShop()
|
|
{
|
|
return array(
|
|
array(new GermanFactory()),
|
|
array(new ItalianFactory())
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider getShop
|
|
*/
|
|
public function testCreation(FactoryMethod $shop)
|
|
{
|
|
// this test method acts as a client for the factory. We don't care
|
|
// about the factory, all we know is it can produce vehicle
|
|
foreach ($this->type as $oneType) {
|
|
$vehicle = $shop->create($oneType);
|
|
$this->assertInstanceOf('DesignPatterns\FactoryMethod\VehicleInterface', $vehicle);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dataProvider getShop
|
|
* @expectedException \InvalidArgumentException
|
|
* @expectedExceptionMessage spaceship is not a valid vehicle
|
|
*/
|
|
public function testUnknownType(FactoryMethod $shop)
|
|
{
|
|
$shop->create('spaceship');
|
|
}
|
|
}
|