From cc765bde41a46b62a4166ecb8ace521defd003e9 Mon Sep 17 00:00:00 2001 From: Trismegiste Date: Fri, 10 May 2013 21:09:55 +0200 Subject: [PATCH] the REAL factory method pattern --- FactoryMethod/Bicycle.php | 20 +++++++++ FactoryMethod/FactoryMethod.php | 45 ++++++++++++++++++++ FactoryMethod/Ferrari.php | 20 +++++++++ FactoryMethod/GermanFactory.php | 32 +++++++++++++++ FactoryMethod/ItalianFactory.php | 32 +++++++++++++++ FactoryMethod/Porsche.php | 20 +++++++++ FactoryMethod/Vehicle.php | 16 ++++++++ Tests/FactoryMethod/FactoryMethodTest.php | 50 +++++++++++++++++++++++ 8 files changed, 235 insertions(+) create mode 100644 FactoryMethod/Bicycle.php create mode 100644 FactoryMethod/FactoryMethod.php create mode 100644 FactoryMethod/Ferrari.php create mode 100644 FactoryMethod/GermanFactory.php create mode 100644 FactoryMethod/ItalianFactory.php create mode 100644 FactoryMethod/Porsche.php create mode 100644 FactoryMethod/Vehicle.php create mode 100644 Tests/FactoryMethod/FactoryMethodTest.php diff --git a/FactoryMethod/Bicycle.php b/FactoryMethod/Bicycle.php new file mode 100644 index 0000000..772dcdf --- /dev/null +++ b/FactoryMethod/Bicycle.php @@ -0,0 +1,20 @@ +createVehicle($type); + $obj->setColor("#f00"); + + return $obj; + } + +} \ No newline at end of file diff --git a/FactoryMethod/Ferrari.php b/FactoryMethod/Ferrari.php new file mode 100644 index 0000000..f57d728 --- /dev/null +++ b/FactoryMethod/Ferrari.php @@ -0,0 +1,20 @@ +type as $oneType) { + $vehicle = $shop->create($oneType); + $this->assertInstanceOf('DesignPatterns\FactoryMethod\Vehicle', $vehicle); + } + } + + /** + * @dataProvider getShop + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage spaceship is not a valid vehicle + */ + public function testUnknownType(FactoryMethod\FactoryMethod $shop) + { + $shop->create('spaceship'); + } + +} \ No newline at end of file