Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DPCreations's avatar

php artisan "Command "test" is not defined."

Hello,

I’ve always used the phpunit to execute my tests, and just recently stumbled upon the php artisan test command, and it looks like it has some benefits to it. However, when I try to run it, I get the response

Command "test" is not defined.

It might be worth adding that I'm on version 7.14.1, and my other projects on the same version doesn't have this issue.

Does anybody know what this might be?

0 likes
9 replies
Nakov's avatar

And does running php artisan list lists the test command in the available commands part?

Try running composer dump-autoload in case you upgraded recently.

DPCreations's avatar

Thanks for your reply. I already tried composer dump-autoload, with no luck.

In fact, the test command doesn't show up in the list. It had me thinking, a while ago I had a command called test:run (before I was aware of this artisan command), but it has been removed now. Could this be causing my current issue?

fylzero's avatar

@dpcreations I would delete your vendor directory and try running composer install to see if that helps.

I don't think your old command would conflicting because it would be found if it was. If that makes sense.

1 like
Nakov's avatar
Nakov
Best Answer
Level 73

I don't think so. Just make sure that you are really running the 7.14 version as you say by running php artisan --version because on my project I have 7.7.1 and the command is there.

Make sure you update all the dependencies as well.

https://laravel.com/docs/7.x/testing#artisan-test-runner

2 likes
DPCreations's avatar

Alright, so I pulled up the composer.json file from my other project, and compared my dependencies. For some reason, I was missing nunomaduro/collision.

Thanks both for your replies, they got me in the right direction.

3 likes
chengkangzai's avatar

Just come across this randomly...

if you do composer install -o --no-dev, you will not be able to run php artisan test

i will never say I tried to run php artisan test on production

4 likes
mSnus's avatar

Just to confirm that composer install ... --no-dev removes the test command (in my case it was composer install --optimize-autoloader --no-dev). This is fixed with composer install

4 likes
kariachintan's avatar

I am still facing this issue, I am on Laravel Framework 8.83.2 and nunomaduro/collision v5.11.0

I am getting the above error. Not sure what am I missing?

2 likes
Jeto's avatar

In case it can help someone in the future: I solved this by deleting the bootstrap/cache/packages.php file (there's probably an artisan command that clears it as well, but I did it manually in my case).

Please or to participate in this conversation.