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'); }
<?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(); }