mohammadkaab's avatar

Migrate:rollback Is not working when test stop

Hi guys I have met a really new strange problem, Actually, I have started writing tests for my code (EtoE), now when I want to see the response of the API I need to put dd and check if the API contains the response or not. The problem Is that when DD stops the code. on the next tests, it'll throw an error that XTable already exists which this means that when my DD stopped the code then migration rollback has not worked.

So any clue of how to solve this issue?

0 likes
5 replies
JohnBraun's avatar

Do you use the RefreshDatabase trait on your TestCase class?

munazzil's avatar

Have you tried with below command?

 php artisan migrate:fresh
Eeetm's avatar

you can check response pragmatically, like you'r expecting certain data [ status, xyz ]

you can check data contain status or xyz

if( array_key_exists("status", $data) && array_key_exists("xyz", $data) ) {
    echo 'response is expected';
} else {
    echo 'response is unexpected';
}

Now, you don't have to dd every response hence Migrate:rollback works Perfectly.

mohammadkaab's avatar

Actually, the problem with using refresh, is that it doesn't remove views from database and that was the problem actually. I've just made my refresh and i'm calling it in every setup. But this problem seems only happening in mysql.

Tray2's avatar

You should never need to use dd in a test unless you are debugging. There are assertions for about everything and you can write your own custom code to assert that a test gives the expected response or not.

Instead of ´dd´ you can use `var_du or `print that way you don't kill your execution.

1 like

Please or to participate in this conversation.