Class 'PHPUnit_Framework_TestCase' not found

这一生的挚爱 提交于 2019-11-27 23:47:54

There is a difference between namespace structure between PHPUnit <6 and PHPUnit 6.

You may consider the following solution for backward compatibility:

// backward compatibility
if (!class_exists('\PHPUnit\Framework\TestCase') &&
    class_exists('\PHPUnit_Framework_TestCase')) {
    class_alias('\PHPUnit_Framework_TestCase', '\PHPUnit\Framework\TestCase');
}

The old PHPUnit versions use \PHPUnit_Framework_TestCase but the new one uses \PHPUnit\Framework\TestCase. With the backward compatibility applied you can use the class name that is compatible with the new version of PHPUnit (i.e. \PHPUnit\Framework\TestCase) and it is going to work also with older versions.

Update In order to cover support for PHP 5.3 you have to remove a \ character before the alias class, i.e.

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