I am working on mocking a save function in Laravel for testing. I have a saving()
event that I am trying to test. I have tried using Eloquent::shouldReceive('save')
but it gives a fatal error: Fatal error: Cannot instantiate abstract class Illuminate\Database\Eloquent\Model
.
This is my test so far:
public function testRemoveAttributesOnSave(){
Eloquent::shouldReceive('save')->once()->andReturn(true);
$this->model->attributeA=1;
$this->model->attributeB=2;
$this->model->save();
$this->assertTrue(!isset($this->model->attributeB));
}
What I want to write is self explanatory on the test. I am trying to handle the validation in the model, and protect some attributes from being included after saving.
If I am going about this wrong, please let me know.