ApolloBLN's avatar

Laravel 6 Testing phpunit wont work anymore

Just made a new fresh Laravel 6 project and added 1 test. When I run phpunit even when the test is empty totally:

/** @test */
public function a_user_can_see_threads()
{


}

results in:

  1. Tests\Feature\ViewThreadsTest::a_user_can_see_threads Mockery\Exception\BadMethodCallException: Received Mockery_1_Illuminate_Console_OutputStyle::askQuestion(), but no expectations were specified

I was currently doing the "build a forum with laravel TDD" and my test are running well from within phpstorm when I trigger the run command, but when I run phpunit from the command line all test fail again in the same manner. Tried already: php artisan config:clear & php artisan config:cache . Same errors

0 likes
17 replies
ApolloBLN's avatar

LogicException : Unable to prepare route [api/user] for serialization. Uses Closure.

bugsysha's avatar

Do you run it through terminal or some IDE?

ApolloBLN's avatar

Im using phpstorm and run it within the terminal, same as in the lecture.

bugsysha's avatar

Strange that happens. Like you are running route:cache?

bugsysha's avatar

So you open terminal in PhpStorm and type phpunit?

ApolloBLN's avatar

yea I tried both php artisan config:cache php artisan config:clear , doesn't male a difference

ismaile's avatar
ismaile
Best Answer
Level 30

Do you run the following command in your terminal: ./vendor/bin/phpunit ?

1 like
bugsysha's avatar

Have you tried by manually specifying phpunit.xml? I think it is -c option.

ApolloBLN's avatar

Do you run the following command in your terminal: ./vendor/bin/phpunit ?

hm this seems to work for some reason. what's the issue here?? I thought running phpunit globally is fine!?

I was just running "phpunit" and its in my PATH variables installed globally through composer.

bugsysha's avatar

That is exactly what I was suspecting. I guess it is not picking configuration and working directory.

ApolloBLN's avatar

so is the solution to always use ./vendor/bin/phpunit locally? or is there a main fix ?

bugsysha's avatar

I think that most of the guys are using an alias which is relative to the folder you are in. But why not use PhpStorm to run tests? It is more readable, and almost not slower at all if you have decent computer.

ApolloBLN's avatar

I like to use phpstorm since I have a hotkey for running the test for the current file I'm in but I didn't find a way to run all the test in several files, so I was trying to use the command line instead. thanks for the fast replies guys. much appreciated.

The stack overflow thread is also interesting.I'll keep it in mind

bugsysha's avatar

If your cursor is not in the test method but in the test class same hotkey will run all tests on that test class. You can select a folder to run more tests. Also select the tests folder and run the hotkey and it will run all tests you have.

1 like
ApolloBLN's avatar

Ah, great. didn't know that about the folder selection. Thats super handy. Well got smarter overall now. thanks a lot - now I have multiple working ways

Please or to participate in this conversation.