UnitTest Skeleton and instanciation by factory methods

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

UnitTest Skeleton and instanciation by factory methods

Oliver Welter
Hello,
I tried to write UnitTests for a Controller based on ZendSkeletonModule.
In the module.config.php of the Module I use functions as factories for creating this controller and injecting a service.
This works within the context of the application but leads to the following exception within UnitTest execution:

Exception: Serialization of 'Closure' is not allowed

I tracked that down to the Listener and Manager initialization in the bootstrap.php which is provided within the ZendSkeltonModule but I have to few insights into the underlying dependencies and processes to figure where the serialization takes place and how to fix this issue.
From my point of view it could be a bug in the bootstrap.php

I'm using ZF 2.0.6, PHPUnit 3.7.10 and checked out ModuleSkeleton one week ago (no recent updates on github in the last months)

Please have a look at the attached files and thanks in advance.

Kind regards

Oliver Weltermodule.config.phpbootstrap.phpphpunit.xmlTestCase.phpAuthenticationControllerTest.php
Reply | Threaded
Open this post in threaded view
|

Re: UnitTest Skeleton and instanciation by factory methods

Marco Pivetta
Heya,

you should not backup globals while running the tests.

Also, don't put closures in your config files.

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On 8 January 2013 12:56, Oliver Welter <[hidden email]> wrote:

> Hello,
> I tried to write UnitTests for a Controller based on ZendSkeletonModule.
> In the module.config.php of the Module I use functions as factories for
> creating this controller and injecting a service.
> This works within the context of the application but leads to the following
> exception within UnitTest execution:
>
> Exception: Serialization of 'Closure' is not allowed
>
> I tracked that down to the Listener and Manager initialization in the
> bootstrap.php which is provided within the ZendSkeltonModule but I have to
> few insights into the underlying dependencies and processes to figure where
> the serialization takes place and how to fix this issue.
> From my point of view it could be a bug in the bootstrap.php
>
> I'm using ZF 2.0.6, PHPUnit 3.7.10 and checked out ModuleSkeleton one week
> ago (no recent updates on github in the last months)
>
> Please have a look at the attached files and thanks in advance.
>
> Kind regards
>
> Oliver Welter module.config.php
> <
> http://zend-framework-community.634137.n4.nabble.com/file/n4658689/module.config.php
> >
> bootstrap.php
> <
> http://zend-framework-community.634137.n4.nabble.com/file/n4658689/bootstrap.php
> >
> phpunit.xml
> <
> http://zend-framework-community.634137.n4.nabble.com/file/n4658689/phpunit.xml
> >
> TestCase.php
> <
> http://zend-framework-community.634137.n4.nabble.com/file/n4658689/TestCase.php
> >
> AuthenticationControllerTest.php
> <
> http://zend-framework-community.634137.n4.nabble.com/file/n4658689/AuthenticationControllerTest.php
> >
>
>
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/UnitTest-Skeleton-and-instanciation-by-factory-methods-tp4658689.html
> Sent from the Zend MVC mailing list archive at Nabble.com.
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: UnitTest Skeleton and instanciation by factory methods

Oliver Welter
Hi,
thanks for your quick answer.
I understand your point but regarding the official documentation using closures is appropriate (and also useful) in config files in terms of dependency management without the need of writing a real factory class.
Also the intention of the provided bootstrap.php in the skeleton should make writing UnitTests easier and take care of all the infrastructural issues.

Its not my intention to backup globals during the test this is - as far as I understand - done automatically by the provided bootstrap.php.

From my point of view there a different opportunities to handle this mismatch regarding productive and test context:

1. Using closures as factories should be marked as deprecated because of its technical constraints regarding UnitTests.
2. Provided bootstrap.php and used underlying functions should deal with this issue.
3. Use separate configuration files for productive and test context

For reducing redundancy and maintenance I would vote for opportunity 2.

Kind regards.

Oliver
Reply | Threaded
Open this post in threaded view
|

Re: UnitTest Skeleton and instanciation by factory methods

Marco Pivetta
Setting closures in config files is not suggested in the docs, and if it
is, it should be removed from there.
The problem is related only with the module config and the merged config.

I personally don't think the skeleton app needs a test bootstrapper. You
can have that in https://github.com/zendframework/ZendSkeletonModule/instead.

About your points:

1. no, closures in factories are a great feature and should not be removed.
Also, these are not the only involved closures here
2. this is a simple flag you can set in your phpunit.xml, not something in
bootstrap.php
3. not really maintainable

Hope that helps :)

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On 8 January 2013 14:14, Oliver Welter <[hidden email]> wrote:

> Hi,
> thanks for your quick answer.
> I understand your point but regarding the official documentation using
> closures is appropriate (and also useful) in config files in terms of
> dependency management without the need of writing a real factory class.
> Also the intention of the provided bootstrap.php in the skeleton should
> make
> writing UnitTests easier and take care of all the infrastructural issues.
>
> Its not my intention to backup globals during the test this is - as far as
> I
> understand - done automatically by the provided bootstrap.php.
>
> From my point of view there a different opportunities to handle this
> mismatch regarding productive and test context:
>
> 1. Using closures as factories should be marked as deprecated because of
> its
> technical constraints regarding UnitTests.
> 2. Provided bootstrap.php and used underlying functions should deal with
> this issue.
> 3. Use separate configuration files for productive and test context
>
> For reducing redundancy and maintenance I would vote for opportunity 2.
>
> Kind regards.
>
> Oliver
>
>
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/UnitTest-Skeleton-and-instanciation-by-factory-methods-tp4658689p4658691.html
> Sent from the Zend MVC mailing list archive at Nabble.com.
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>