【问题标题】:phpunit: catchable fatal error when testingphpunit:测试时可捕获的致命错误
【发布时间】:2017-02-09 16:16:30
【问题描述】:

我正在使用 Zend 框架,我已经设置了所有东西,但是在单元测试中我遇到了一个致命错误:

c:\xampp\htdocs\zend\module\Album\test>phpunit PHP Catchable 致命错误:传递给 Zend\ServiceManager\ServiceManager::__construct() 的参数 1 必须是数组类型,给定对象,在 C:\xampp\htdocs\zend\module\Album\test\Bootstrap.php 中调用第 53 行并在第 144 行的 c:\xampp\htdocs\zend\vendorframework\zend-servicemanager\src\ServiceManager.php 中定义

Bootstrap.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 第 144-148 行:

  public function __construct(array $config = [])
    {
       $this->creationContext = $this;
       $this->configure($config = []);
    }

请给点建议???

【问题讨论】:

    标签: php zend-framework phpunit


    【解决方案1】:
    $serviceManager = new ServiceManager(new ServiceManagerConfig());
    

    传递给 Zend\ServiceManager\ServiceManager::__construct() 的参数 1 必须是数组类型,给定对象

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

    这是版本不匹配。

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

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

    如果您使用的是zf skeleton application,请确保您使用的是正确的版本。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-06
    • 1970-01-01
    • 2015-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多