Phpunit Silverstripe 4蓝宝石级罐头';找不到

Phpunit Silverstripe 4蓝宝石级罐头';找不到,phpunit,silverstripe,silverstripe-4,Phpunit,Silverstripe,Silverstripe 4,我已经从SilverStripe 3升级到4,现在我的phpUnit测试无法运行,因为它们找不到我的任何自定义类 自动装弹机肯定少了什么东西 我有一个像这样的简单测试 use SilverStripe\Dev\SapphireTest; class EntityTest extends SapphireTest { var $Entity; function setUp()/* The :void return type declaration that should be

我已经从SilverStripe 3升级到4,现在我的phpUnit测试无法运行,因为它们找不到我的任何自定义类

自动装弹机肯定少了什么东西

我有一个像这样的简单测试

  use SilverStripe\Dev\SapphireTest;

class EntityTest extends SapphireTest
{
    var $Entity;
    function setUp()/* The :void return type declaration that should be here would cause a BC issue */
    {
        parent::setUp(); // TODO: Change the autogenerated stub
        $this->Entity = new \My\API\Client\Model\Entity();
    }

    function testMethods(){

        $this->assertMethodExist($this->Entity,'setName');
    }


    function assertMethodExist($class, $method) {
        $oReflectionClass = new ReflectionClass($class);
        assertThat("method exist", true, $oReflectionClass->hasMethod($method));
    }
}
跑步时,我得到: $php vendor/phpunit/phpunit/phpunit mysite/tests/EntityTest.php


致命错误:未找到类“SilverStripe\Dev\SapphireTest”

您可能缺少测试引导。SS4仍然依赖SilverStripe类清单来注册可用的类(不仅仅是PSR-4自动加载器),因此您需要将其包括在内。请尝试以下任一方法:

$ vendor/bin/phpunit --bootstrap vendor/silverstripe/framework/tests/bootstrap.php mysite/tests
或者在根项目中创建
phpunit.xml
文件:

<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
</phpunit>


您也可以使用CMS模块中的等效文件,但在开始将testsuite集成到CI提供程序之前,您可能看不到任何差异。

我在SilverStripe 4.1中遇到了类似的问题,以下是我发现(并解决)的问题

1) 从4.1开始,您需要使用--prefersource而不是--preferdist来获取测试代码。现在,分布式包中省略了测试代码,请参见

2) phpunit必须在版本^5.7的require dev中-我有一个不同的值,这就是自动加载问题的原因

我创建了一个测试模块供参考,请参见

干杯

戈登