Phpunit:测试时可捕获的致命错误


phpunit: catchable fatal error when testing

我正在Zend框架上工作,我已经设置了一切,但在单元测试中我得到一个致命的错误:

c: ' xampp '根' zend专辑'模块' '测试> phpunit)PHP可捕获的致命错误:参数1传递给Zend'ServiceManager'ServiceManager::__construct()必须是array类型,给定对象,在C:'xampp'htdocs' Zend' module'Album'test'Bootstrap.php第53行调用,并在C:'xampp'htdocs' Zend' vendorframework' Zend - ServiceManager' src'ServiceManager. PHP第144行定义

boot .php第52-58行:

    $config = ArrayUtils::merge($baseConfig, $testConfig);
    $serviceManager = new ServiceManager(new ServiceManagerConfig());
    $serviceManager->setService('ApplicationConfig', $config);
    $serviceManager->get('ModuleManager')->loadModules();
    static::$serviceManager = $serviceManager;
    static::$config = $config;

ServiceManager.php Line 144-148:

  public function __construct(array $config = [])
    {
       $this->creationContext = $this;
       $this->configure($config = []);
    }
请给点建议??
$serviceManager = new ServiceManager(new ServiceManagerConfig());

传递给Zend'ServiceManager'ServiceManager::__construct()的参数1必须是array, object given的类型

这个错误告诉你ServiceManager需要一个数组作为参数。您传递的参数是new ServiceManagerConfig(),它是一个对象。

版本不匹配

zendframework/zend-servicemanager ~2.0中,ServiceManager构造函数需要一个对象。

zendframework/zend-servicemanager ~3.0 ServiceManager构造函数需要一个数组

如果您正在使用zf框架应用程序,请确保您使用的是正确的版本。