Support the ongoing development of Laravel.io →
posted 10 years ago
Testing
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

gayanhewa gayanhewa Joined 26 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.