首页 > 解决方案 > PHPUnit 继承测试

问题描述

我有一个父类和一个子类 - 加载了 spl_register_autoload()) 并且我正在尝试编写 PHPUnit 测试;我的继承有问题:当我运行测试时,会出现以下警告消息:

Warning: include(classes/PHPUnit\Composer\Autoload\ClassLoader.class.php): failed to open stream: No such file or directory in C:\wamp64\www\test\test\unit_tests\test\Employe9Test.php on line 36.

任何想法?

标签: phpphpunit

解决方案


从 Employe9Test.php 调用文件时找不到 ClassLoader.class.php 的相对路径

如果您的测试需要自动加载器,我可以建议您使用 phpunit 配置文件中的 bootstrap 属性吗?

<phpunit bootstrap="src/autoload.php">
  <testsuites>
    <testsuite name="money">
      <file>tests/IntlFormatterTest.php</file>
      <file>tests/MoneyTest.php</file>
      <file>tests/CurrencyTest.php</file>
    </testsuite>
  </testsuites>
</phpunit>

资源

这样,如果自动加载文件路径发生变化,您就不必在每个测试文件中调整/编辑自动加载文件路径。


推荐阅读