protected function _executeTestsNormal($di)
 {
     $robot = new Robots();
     $success = $robot->save(array('type' => 'mechanical', 'year' => 2018));
     $this->assertEquals($success, false);
     $this->assertEquals($robot->type, 'mechanical');
     $this->assertEquals($robot->year, 2018);
     $robot = new Robots();
     $robot->assign(array('type' => 'mechanical', 'year' => 2018));
     $this->assertEquals($robot->type, 'mechanical');
     $this->assertEquals($robot->year, 2018);
     //not assigns nonexistent fields
     $robot = new Robots();
     $robot->assign(array('field1' => 'mechanical', 'field2' => 2018));
     $this->assertEquals(empty($robot->field1), true);
     $this->assertEquals(empty($robot->field2), true);
     //white list
     $robot = new Robots();
     $robot->assign(array('type' => 'mechanical', 'year' => 2018), null, array('type'));
     $this->assertEquals($robot->type, 'mechanical');
     $this->assertEquals(empty($robot->year), true);
     //white list
     $robot = new Robots();
     $robot->assign(array('typeFromClient' => 'mechanical', 'yearFromClient' => 2018), array('typeFromClient' => 'type', 'yearFromClient' => 'year'), array('type'));
     $this->assertEquals($robot->type, 'mechanical');
     $this->assertEquals(empty($robot->year), true);
 }
 protected function _executeTestsNormal($di)
 {
     $robot = new Robots();
     $success = $robot->save(array('type' => 'mechanical', 'year' => 2018));
     $this->assertEquals($success, false);
     $this->assertEquals($robot->type, 'mechanical');
     $this->assertEquals($robot->year, 2018);
     $robot = new Robots();
     $robot->assign(array('type' => 'mechanical', 'year' => 2018));
     $this->assertEquals($robot->type, 'mechanical');
     $this->assertEquals($robot->year, 2018);
 }
Beispiel #3
0
 public function saveAction()
 {
     $this->db->begin();
     $robot = new Robots();
     $robot->name = "WALL·E";
     $robot->created_at = date("Y-m-d");
     if ($robot->save() == false) {
         $this->db->rollback();
         return;
     }
     $robotPart = new RobotParts();
     $robotPart->robots_id = $robot->id;
     $robotPart->type = "head";
     if ($robotPart->save() == false) {
         $this->db->rollback();
         return;
     }
     $this->db->commit();
 }
Beispiel #4
0
<?php

$robotPart = new RobotParts();
$robotPart->type = "head";
$robot = new Robots();
$robot->name = "WALL·E";
$robot->created_at = date("Y-m-d");
$robot->robotPart = $robotPart;
$robot->save();
//Creates an implicit transaction to store both records
<?php

$robot = new Robots();
$robot->type = 'mechanical';
$robot->name = 'Astro Boy';
$robot->year = 1952;
if ($robot->save() == false) {
    echo "Umh, We can't store robots right now ";
    foreach ($robot->getMessages() as $message) {
        echo $message;
    }
} else {
    echo "Great, a new robot was saved successfully!";
}
Beispiel #6
0
<?php

$robot = new Robots();
$robot->save($_POST);
Beispiel #7
0
<?php

$robot = new Robots();
$robot->save($_POST, array('name', 'type'));
Beispiel #8
0
<?php

$robot = new Robots();
$robot->save(array("type" => "mechanical", "name" => "Astro Boy", "year" => 1952));