PHPUnit Error: Class not found

被刻印的时光 ゝ 提交于 2019-12-04 18:59:50

Happening in 4.1 as well, possibly an issue in the bin/phpunit script:

$classLoader->unregister();

I worked around it by creating a tests/bootstrap.php file (and updating phpunit.xml.dist to use it):

<?php

$classLoader = require dirname(__DIR__).'/vendor/autoload.php';
$classLoader->register(true);

I have just had this problem. Not sure why, but I didn't have a phpunit.xml.dist in the root of my project. None of the examples shows this, but if you add bootstrap= and then include the autoloaded. It should start to find your classes.

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.0/phpunit.xsd"
     bootstrap="vendor/autoload.php"

>

In your phpunit.xml, you maybe need to specify the kernel and environment :

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         bootstrap="vendor/autoload.php"
>
    <php>
        <ini name="error_reporting" value="-1" />
        <env name="KERNEL_CLASS" value="App\Kernel" />
        <env name="APP_ENV" value="test" />
        <env name="APP_DEBUG" value="1" />
        <env name="SHELL_VERBOSITY" value="-1" />
  </php>
</phpunit>

I ended up with this problem because I forgot to run composer auto-dump -o after installing phpunit.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!