Exemplo n.º 1
0
 public static function createAndSaveRawModelWithOneToOneRelation()
 {
     include_once __DIR__ . '/../scripts/tested_models.php';
     $testBrand = new \Brand();
     $testBrand->nameBrand = 'Acme';
     $testBrand->noteBrand = 10;
     $testBrand->save();
     $car = new \Car();
     $car->nameCar = 'AcmeCarcreateAndSaveRawModelWithOneToOneRelation';
     $car->noteCar = '10';
     $car->setBrand($testBrand);
     $car->save();
     $req = \PicORM\Model::getDataSource()->prepare('SELECT count(*) as nb FROM cars WHERE idBrand = ? AND idCar = ?');
     $req->execute(array($testBrand->idBrand, $car->idCar));
     $resultBDD = $req->fetch(\PDO::FETCH_ASSOC);
     return array(array($testBrand, $car, $resultBDD));
 }
Exemplo n.º 2
0
 /**
  * @test
  */
 public function shouldBeAbleToMerge()
 {
     // given
     $car = new Car();
     $car->deleteTableData()->yesImSure();
     $car->setBrand("Volkswagen");
     $car->setModel("Polo 1.6 TDI");
     $car->commit();
     $this->addCarProperty($car->getId(), "Hk", "75");
     $this->addCarProperty($car->getId(), "Mileage", "42000");
     $this->addCarProperty($car->getId(), "Year", "2010");
     $cars = new CarsWithProperties();
     // when
     $values = $cars->getValues();
     $firstCar = $values[0];
     // then
     $this->assertNotNull($firstCar['properties']);
 }
Exemplo n.º 3
0
    $tag3->save();
    // setting car's tags
    $car->setTag(array($tag, $tag2, $tag3));
    // getting car's tags
    $car->getTag();
    // getting car's tags with custom parameters
    // parameters are same as find() method
    $car->getTag($where, $order, $limitStart, $limitStop);
    // unset relation between $car and $tag2
    $car->unsetTag($tag2);
    // creating some cars
    $car = new Car();
    $car->nameCar = "205 GTi";
    $car->setBrand($brand);
    $car->save();
    $car2 = new Car();
    $car2->nameCar = "206";
    $car2->setBrand($brand);
    $car2->save();
    $car3 = new Car();
    $car3->nameCar = "207";
    $car3->setBrand($brand);
    $car3->save();
    // affecting new cars to $tag2
    $tag2->setCar(array($car, $car2, $car3));
} catch (PicORM\Exception $e) {
    // !!!! disable showing PicORM\Exception for production because it contains SQL query !!!!
    echo '<strong>' . $e->getMessage() . '</strong>';
} catch (Exception $e) {
    echo '<strong>' . $e->getMessage() . '</strong>';
}