In this instance you should use
$wish = factory(Model::class)->make();
make() does not persist the model in the DB while create() does
i want to simply test my model to see if it can be created or not here is what i tried :
public function it_test_insert_model(){
// $this->actingAs(User::class);
$wish = factory(Model::class)->create();
$this->post('/model/create',$wish->toArray());
$this->assertEquals(1,Model::all()->count());
}
now my problem is every time it fails because it should equal the the numbers of models i have in my table . is there any way to just create one and test if it was created and then remove it ??? because now every time it remains in database . i just want to test if the model is able to be created or not .
thanks
I don't know. For some reason, the record is not being created, I was wanted to know that the request was being made to the correct endpoint.
Can you dump the response:
public function it_test_insert_model(){
$this->post('/model/create', factory(Model::class)->raw())
->dump();
$this->assertEquals(1,Model::count());
}
See if there is some exception output; and if there is, turn off exception handling to see the nature of the exception:
public function it_test_insert_model(){
$this->withoutExceptionHandling();
$this->post('/model/create', factory(Model::class)->raw());
$this->assertEquals(1,Model::count());
}
Please or to participate in this conversation.