OK, I found the problem. I didn't have the correct config loading in the test file. So I fixed that and it works.

I was beginning to think I really didn't know enough about PHPUnit and ZF2 to be able to write test. It turns out it's not that bad.

Kim, thanks for helping talk me through it!

Simon

On 2016/02/23 12:20, Kim Prince wrote:
Perhaps try commenting out the code in the factory itself and seeing if it
will run?

On Tue, Feb 23, 2016 at 2:05 PM, Simon Walter <[email protected]> wrote:

No. As I said, it works fine with Apache.

I am having problems with PHPUnit.

The service manager cannot create the instance when using PHPUnit.

I just can't understand why factories from one module work fine and then
factories from another module do not work.

Again, this problem only is with PHPUnit - leading me to believe that I
have some wrong with my Bootstrap.php file for PHPUnit.

What I do know is the the configurations from all the modules *are*
getting properly combined and are available in the environment PHPUnit is
calling functions from.

I also know that it has nothing to do with the class, because an existing
Zend class such as Zend\Mvc\Service\TranslatorServiceFactory is also not
able to be instantiated when placed in my module's factory config:

return array(
     'service_manager' => array(
         'factories' => array(
             'log' => 'Log\Service\Factory\Log',
             'trex' => 'Zend\Mvc\Service\TranslatorServiceFactory',
         ),
     )
);

Placing either in another module's config will work fine. Any ideas?

Thanks,

Simon


On 2016/02/23 11:03, Kim Prince wrote:

Any error messages in the apache log?  Are you trying to open a log for
writing in a non-writable directory (because you are using chdir when
bootstrapping the tests?)

On Tue, Feb 23, 2016 at 12:23 PM, Simon Walter <[email protected]> wrote:

(Sorry for double posting. I sent this to contrib earlier forgetting it's
the wrong place.)

Hi all,

I am having a problem where factories that I have declared in the config
files or Module.php files are not being created:

return array(
      'service_manager' => array(
          'factories' => array(
              'log' => 'Log\Service\Factory\Log'
          ),
      )
);

"Zend\ServiceManager\ServiceManager::get was unable to fetch or create
an instance for log"

My main "Application" module's factories work fine with PHPUnit. My new
"Log" module's factories do not. Both work fine when accessing via
Apache (index.php).

Any ideas?

Thanks,

Simon




--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]




--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]





--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to