I created a small project with a composer.json
and have this set up:
"autoload": {
"psr-4": {
"MyApp\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"MyApp\\Tests\\": "tests/"
}
},
phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
ClientCrawler.php
namespace MyApp;
class ClientCrawler
{
}
ClientCrawlerTest.php
namespace MyApp\Tests;
use MyApp\ClientCrawler;
use PHPUnit\Framework\TestCase;
class ClientCrawlerTest extends TestCase
{
public function testCheckClient()
{
$this->assertTrue(true);
$crawler = new ClientCrawler();
}
}
Test Command (PhpStorm)
C:\xampp\php\php.exe D:\phpunit\phpunit.phar --no-configuration --filter MyApp\\Tests\\ClientCrawlerTest --test-suffix ClientCrawlerTest.php C:\Users\MYNAME\PhpstormProjects\CodingPractice\tests --teamcity --cache-result-file=C:\Users\MYNAME\PhpstormProjects\CodingPractice\.phpunit.result.cache
Result
Error: Class "MyApp\ClientCrawler" not found
Things I tried
composer dump-autoload
- Deleted vendor and
composer install
(with anotherdump-autoload
) - Deleted the
.phpunit.result.cache
- Restarted PhpStorm
Where am I wrong?