コード例 #1
0
ファイル: car_test.php プロジェクト: ymnl007/designpatterns
 public function testCreate()
 {
     $this->assertInstanceOf('Car', CarsFactory::create('bmw'));
     $this->assertInstanceOf('Car', CarsFactory::create('mercedes'));
     $this->assertInstanceOf('Car', CarsFactory::create('ferari'));
     $this->setExpectedException('CarException');
     CarsFactory::create('susita');
 }
コード例 #2
0
ファイル: car_usage.php プロジェクト: ymnl007/designpatterns
<?php

require_once "car.php";
try {
    $myCar = CarsFactory::create('bmw');
    echo $myCar->getDetails();
    //will throw exception since this car not exists
    //$myBmw = CarsFactory::create('susita');
} catch (CarException $e) {
    echo $e->getMessage();
}