Example #1
0
 public function testShouldNotSave()
 {
     $model = new Model();
     $this->assertFalse($model->save());
     $model = m::mock('_stubProduct[fireModelEvent]');
     $model->shouldAllowMockingProtectedMethods();
     $model->shouldReceive('fireModelEvent')->once()->with('saving')->andReturn(false);
     $this->assertFalse($model->save());
     $model->shouldReceive('fireModelEvent')->once()->with('saving')->andReturn(true);
     $model->shouldReceive('fireModelEvent')->once()->with('creating')->andReturn(false);
     $this->assertFalse($model->save());
     $model->shouldReceive('fireModelEvent')->twice()->andReturn(true);
     $this->productsCollection->shouldReceive('save')->once()->andReturn(false);
     $this->assertFalse($model->save());
 }
Example #2
0
 /**
  * Save the model to the database if it's valid. This method also
  * checks for the presence of the localMock in order to call the save
  * method into the existing Mock in order not to touch the database.
  *
  * @param $force Force save even if the object is invalid
  * @return bool
  */
 public function save($force = false)
 {
     if ($this->localMock && $this->localMock->mockery_getExpectationsFor('save')) {
         return $this->localMock->save();
     }
     if ($force || $this->isValid()) {
         $this->hashAttributes();
         return parent::save();
     }
     return false;
 }