mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-17 05:11:18 +02:00
53 lines
1.6 KiB
PHP
53 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace DesignPatterns\Creational\FactoryMethod\Tests;
|
|
|
|
use DesignPatterns\Creational\FactoryMethod\FactoryMethod;
|
|
use DesignPatterns\Creational\FactoryMethod\GermanFactory;
|
|
use DesignPatterns\Creational\FactoryMethod\ItalianFactory;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class FactoryMethodTest extends TestCase
|
|
{
|
|
public function testCanCreateCheapVehicleInGermany()
|
|
{
|
|
$factory = new GermanFactory();
|
|
$result = $factory->create(FactoryMethod::CHEAP);
|
|
|
|
$this->assertInstanceOf('DesignPatterns\Creational\FactoryMethod\Bicycle', $result);
|
|
}
|
|
|
|
public function testCanCreateFastVehicleInGermany()
|
|
{
|
|
$factory = new GermanFactory();
|
|
$result = $factory->create(FactoryMethod::FAST);
|
|
|
|
$this->assertInstanceOf('DesignPatterns\Creational\FactoryMethod\CarMercedes', $result);
|
|
}
|
|
|
|
public function testCanCreateCheapVehicleInItaly()
|
|
{
|
|
$factory = new ItalianFactory();
|
|
$result = $factory->create(FactoryMethod::CHEAP);
|
|
|
|
$this->assertInstanceOf('DesignPatterns\Creational\FactoryMethod\Bicycle', $result);
|
|
}
|
|
|
|
public function testCanCreateFastVehicleInItaly()
|
|
{
|
|
$factory = new ItalianFactory();
|
|
$result = $factory->create(FactoryMethod::FAST);
|
|
|
|
$this->assertInstanceOf('DesignPatterns\Creational\FactoryMethod\CarFerrari', $result);
|
|
}
|
|
|
|
/**
|
|
* @expectedException \InvalidArgumentException
|
|
* @expectedExceptionMessage spaceship is not a valid vehicle
|
|
*/
|
|
public function testUnknownType()
|
|
{
|
|
(new ItalianFactory())->create('spaceship');
|
|
}
|
|
}
|