i think the problem is that you have in your machine a global phpunit installation.
when you do phpunit it references that installation and phpunit "global" does not know where to find your vendor/autoload.php, so it can't find the class.
Here you have 3 solution that you can try:
- use your global installation giving it the --bootstrap flag like so, it might work, depending on the local phpunit version:
phpunit --bootstrap="vendor/autoload.php"
- use the project phpunit composer installation:
./vendor/bin/phpunit
- add a phpunit.xml config file in the root directory of your project, try this one that i use.
adding the config file both wile work
phpunitand./vendor/bin/phpunit
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>
for the solutions, there no good or bad one, try whatever fits your worflow.
you can verify the 2 installations of phpunit by running.
- check the global.
phpunit --version - check the local project version
./vendor/bin/phpunit --version
hope it helps.