Current approach for the testing :
// With an annotation @expectedException Exception
DB::transaction(function(){
$order = new Order();
$order->user_id = 9999; // No fk constraint. So I can use a random number to i can be 100% sure there was no record created.
$order->total = 100;
$order->save();
throw new Exception('Error occured , so don\'t hit the database');
});
I can only confirm that the DB transaction works as expected and that the method throws an exception as expected and the records are never saved. Has to be verified by another unit test that verifies that the query didnt create a record in the database.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community