2

I am working on Zend framework , i have set up everything but in the unit testing i get a fatal error:

c:\xampp\htdocs\zend\module\Album\test>phpunit PHP Catchable fatal error: Arugment 1 passed to Zend\ServiceManager\ServiceManager::__construct() must be of the type array, object given, called in C:\xampp\htdocs\zend\module\Album\test\Bootstrap.php on line 53 and defined in c:\xampp\htdocs\zend\vendorframework\zend-servicemanager\src\ServiceManager.php on line 144

Bootstrap.php Line 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 = []);
    }

Some advice please???

1 Answer 1

1
$serviceManager = new ServiceManager(new ServiceManagerConfig());

Arugment 1 passed to Zend\ServiceManager\ServiceManager::__construct() must be of the type array, object given

The error is telling you that ServiceManager expects an array as an argument. The argument you are passing is new ServiceManagerConfig(), which is an object.

It's a version mis-match.

In zendframework/zend-servicemanager ~2.0 the ServiceManager constructor requires an object.

In zendframework/zend-servicemanager ~3.0 the ServiceManager constructor requires an array.

If you are using the zf skeleton application, make sure you are using the correct version.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for your reply... so what do I need to change to fix this mis-match ??
If you're using composer then make sure it's requiring the version you want. It looks like you probably need version ~2.0, but it really depends on your project.
I have followed these steps , and i cannot find out where i went wrong framework.zend.com/manual/2.0/en/user-guide/unit-testing.html
Make sure you are reading the latest docs for version framework.zend.com/manual/2.4/en/user-guide/overview.html. Somehow you managed to install version 3 of zend-servicemanager when the docs seem to be based on version 2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.