hiraq's avatar

Lumen Unit Test - Strange Behaviors

Actually, i've report this issue at lumen-framework github , but there are no answers at all..

I'm always do unit test with laravel, and now when i try lumen micro framework, i cannot test all unit tests together, and i see there is like a cache between tests. Unit test only work for first test, and the others will fail.

Anyone has same experience with me? Or i'm just alone here?

0 likes
6 replies
bobbybouwmann's avatar

In your first test you register the user. In the second test you generate a user as well. Since you use the database you need to reset the database as well! Maybe that is the problem. I think that if you do something like this in TestCase.php it should work

public function setUp()
{
    parent::setUp();
    Artisan::call('migrate');
}

public function tearDown()
{
    Artisan::call('migrate:reset');
    parent::tearDown();
}

Can you try and fetch all the users during your second test? Just to check if the user or multiple users exists or not?

alfrednutile's avatar

What is the error or just a fail? The only big issue I have run into for Lumen and Larvel was if you use require_once in a route file more than once you get 404 errors for a number of routes if you run all the tests. Just had to set it to require.

hiraq's avatar

@bobbybouwmann , yes of course i have did that and it's still not works, you can check my codes in lumen's issues there, i put my codes there. Second and the last test use the same behavior like first test, or maybe something like that, but i'm not sure why or how. All tests working fine if i run my test one by one, when i run all tests together all failed.

@alfrednutile , no, i'm not use require_once or require in my routes

bobbybouwmann's avatar

Well the problem seems to me that you already have a filled database and the database isn't cleared after that..

hiraq's avatar

@fesja , i've replied your message there

@bobbybouwmann , no bro, it's not about database. I've test setUp and tearDown methods, and they are still triggered, so this mean, each time test start lumen do migration, and after each test finished, lumen reset the migration, so the data should be cleared properly.

Please or to participate in this conversation.