Example #1
0
 /**
  * @covers Cradle\Sql\Model::save
  * @covers Cradle\Sql\Model::isPrimarySet
  */
 public function testSave()
 {
     $instance = $this->object->save('foo');
     $this->assertInstanceOf('Cradle\\Sql\\Model', $instance);
     $instance = $this->object->setTable('foo')->save();
     $this->assertInstanceOf('Cradle\\Sql\\Model', $instance);
     $triggered = false;
     try {
         $this->object = new Model();
         $this->object->setFoobarTitle('Foo Bar 1')->setFoobarDate('January 12, 2015')->setFooDate(1234567890)->save();
     } catch (SqlException $e) {
         $triggered = true;
     }
     $this->assertTrue($triggered);
     $triggered = false;
     try {
         $this->object = new Model();
         $this->object->setFoobarTitle('Foo Bar 1')->setFoobarDate('January 12, 2015')->setFooDate(1234567890)->save('foo');
     } catch (SqlException $e) {
         $triggered = true;
     }
     $this->assertTrue($triggered);
     $triggered = false;
     try {
         $this->object = new Model();
         $this->object->setFoobarId(321)->setFoobarTitle('Foo Bar 1')->setFoobarDate('January 12, 2015')->setFooDate(1234567890)->save('foo', new AbstractSqlStub(), 'foobar_id');
     } catch (SqlException $e) {
         $triggered = true;
     }
     $this->assertFalse($triggered);
 }