Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8541379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:49:06+00:00 2026-06-11T11:49:06+00:00

I have a new module for which I’m writing tests. The module contains a

  • 0

I have a new module for which I’m writing tests.
The module contains a class which implements ServiceLocatorAwareInterface because it needs to create other objects using the DI container. Everything works fine when running in the skeleton app, but when running module tests i get the following:

Zend\Di\Exception\RuntimeException: Invalid instantiator of type “NULL” for “Zend\ServiceManager\ServiceLocatorInterface”

Researching a little bit I find that the DI container tries to create a new object of type “ServiceLocatorAwareInterface”, which is of course wrong.

Digging a little more in the tests bootstrap, I find that adding the following line solves the problem, as in the DI now knows what class to instantiate for that interface.

$di->instanceManager()->addTypePreference('Zend\ServiceManager\ServiceLocatorInterface', new \Zend\ServiceManager\ServiceManager());

I’m not sure whether this is the best solution to the problem, as the ServiceManager passed by me is a dummy one.

Does anyone have any other ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:49:07+00:00Added an answer on June 11, 2026 at 11:49 am

    Yes, you are going in the right direction. (See the preferences documentation)

    Not many people are using DI these days in favor of the ServiceManager (myself included), but if the config for DI remains similar to how it was during the ZF2 betas, you should be able to add a “preferences” section to your DI config like so:

    'di' => array(
        'instance' => array(
            'preferences' => array(
                'My_Interface' => 'My_Implementation_Or_Alias',
            ) 
        )
    )
    

    This configuration block can replace your call to $di->instanceManager()->addTypePreference()


    Looking through the current docs, and mimicking the example here, you may have success defining the DI config as shown below using the ZF2 official release:

    $di = new Zend\Di\Di;
    $di->configure(new Zend\Di\Config(array(
        'instance' => array(
            'preferences' => array(
                'My_Interface' => 'My_Implementation_Or_Alias',
            ) 
        )
    )));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been given a new project module which involves fuzzy logic. It is
I have created new aspx file within a module which I am going to
I currently have a simple menu_alter hook in a new module I'm building which
I have created a module which adds a new node(with user info) if a
I have play-framework application that uses one module which I've created by play new-module
I have used the module Mail::Webmail::Gmail to read the new messages in my Gmail
I am a bit new to the Devel::Cover module, but have found it very
I have these two modules : package G1; sub new { my $class =
I have a class in my Prism/CAL application which generates a form for users
I have a device driver module which does a register_chardev(). In the driver open()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.