Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPUnit - Testing Last Insert ID

Tags:

php

phpunit

Can someone pls tell me how do I cover the following exception case in my PhpUnit test?

$DB->Insert(db query here...);

$lastInsertID = $DB->InsertID();

if (!$lastInsertID) {
    throw new Exception('Unable to insert new record');
}

Thanks in advance

like image 978
user2909892 Avatar asked Jan 17 '26 00:01

user2909892


1 Answers

you could mock $DB->Insert to return false

like image 134
po_taka Avatar answered Jan 19 '26 14:01

po_taka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!