Problems testing with PHPUnit and factories

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems testing with PHPUnit and factories

Simon Walter
(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: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Problems testing with PHPUnit and factories

Kim Prince
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 <[hidden email]> 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: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Problems testing with PHPUnit and factories

Simon Walter
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 <[hidden email]> 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: [hidden email]
>> Info: http://framework.zend.com/archives
>> Unsubscribe: [hidden email]
>>
>>
>>


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


Reply | Threaded
Open this post in threaded view
|

Re: Problems testing with PHPUnit and factories

Kim Prince
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 <[hidden email]> 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 <[hidden email]> 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: [hidden email]
>>> Info: http://framework.zend.com/archives
>>> Unsubscribe: [hidden email]
>>>
>>>
>>>
>>>
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Problems testing with PHPUnit and factories

jeremiah
In reply to this post by Simon Walter
Can you post a gist of your Bootstrap file? It sounds like your missing module isn't registered with your autoloader.

Jeremiah

> On Feb 22, 2016, at 7:05 PM, Simon Walter <[hidden email]> 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 <[hidden email]> 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: [hidden email]
>>> Info: http://framework.zend.com/archives
>>> Unsubscribe: [hidden email]
>
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>

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


Reply | Threaded
Open this post in threaded view
|

Re: Problems testing with PHPUnit and factories

Simon Walter
In reply to this post by Kim Prince
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 <[hidden email]> 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 <[hidden email]> 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: [hidden email]
>>>> Info: http://framework.zend.com/archives
>>>> Unsubscribe: [hidden email]
>>>>
>>>>
>>>>
>>>>
>> --
>> List: [hidden email]
>> Info: http://framework.zend.com/archives
>> Unsubscribe: [hidden email]
>>
>>
>>


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