/** * @test */ public function shouldBeAbleToPopulateByJSON() { // given $car = new Car(1); $this->assertEquals(1, $car->getId()); $json = $car; $array = json_decode($json, true); // when $array['brand'] = 'BMW'; $car->setValues($array); $car->commit(); $newCar = new Car(1); // then $this->assertEquals('BMW', $newCar->getBrand()); }
include "Vehicle.php"; class Car extends Vehicle { private $noOfDoors; private $color; private $brand; public function __construct($cc, $hp, $noOfDoors, $color, $brand) { echo "<br/>Hi from car constructor"; parent::__construct('Car', $cc, $hp); $this->noOfDoors = $noOfDoors; $this->color = $color; $this->brand = $brand; } public function getColor() { return $this->color; } public function getNoOfDoors() { return $this->noOfDoors; } public function getBrand() { return $this->brand; } } $v = new Car(1.3, 100, 4, 'Golden', 'BMW'); echo "<br/>Type is " . $v->getType() . ", CC : " . $v->getCc() . ", HP : " . $v->getHp() . ", Color : " . $v->getColor() . ", Brand : " . $v->getBrand();
/** * @test */ public function shouldBeAbleToDefineDefaultData() { // given $car = new Car(); $car->drop()->yesImSure(); $car->createTable(); new Car(); $db = LudoDB::getInstance(); $row = $db->one("select count(id) as num from car"); // then $this->assertEquals(7, $row['num']); $car = new Car(1); $this->assertEquals('Opel', $car->getBrand()); }