Unit testing & ServiceManager's global state

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

Unit testing & ServiceManager's global state

dmitrybelyakov
Hello, 

I'm working on porting our beta-based zf2 code to the stable version and came across an issue with application initialization problem: in our test bootstrap we do Zend\Mvc\Application::init($config) 
but then ServiceManager preserves it's state between tests, wich is a problem. 

I wonder if anyone can suggest a way to properly bootstrap for testing. 

Dmitry.
Reply | Threaded
Open this post in threaded view
|

Re: Unit testing & ServiceManager's global state

Marco Pivetta
You can use my example test bootstrapper:

https://github.com/Ocramius/OcraDiCompiler/blob/master/tests/OcraDiCompilerTest/ServiceManagerTestCase.php

I think I ported it also in the Doctrine modules, cannot remind it right now.

Marco Pivetta

http://twitter.com/Ocramius     

http://marco-pivetta.com    



On 6 September 2012 15:28, Dmitry Belyakov <[hidden email]> wrote:
Hello, 

I'm working on porting our beta-based zf2 code to the stable version and came across an issue with application initialization problem: in our test bootstrap we do Zend\Mvc\Application::init($config) 
but then ServiceManager preserves it's state between tests, wich is a problem. 

I wonder if anyone can suggest a way to properly bootstrap for testing. 

Dmitry.

Reply | Threaded
Open this post in threaded view
|

Re: Unit testing & ServiceManager's global state

Dmitry Belyakov

Hi Marco,

Thanks a lot for your response :)

It's almost the same thing I tried to do, but it does also fail. The problem is with $moduleManager->loadModules()
when it tries to load more then once (like for the next test in suite) then it will explode saying the ModuleManager expects 
module config to be an array, but received a boolean. Unless you replace all require_onces with plain requires. 
Like you do in /src/OcraDiCompiler/Module.php

Thats ok, unless you forget to replace it somewhere.
It might be better if we could just drop ServiceManager's internal cache somehow between tests.

Dmitry.


On Thursday, September 6, 2012 at 5:31 PM, Marco Pivetta wrote:

You can use my example test bootstrapper:

https://github.com/Ocramius/OcraDiCompiler/blob/master/tests/OcraDiCompilerTest/ServiceManagerTestCase.php

I think I ported it also in the Doctrine modules, cannot remind it right now.

Marco Pivetta

http://twitter.com/Ocramius     

http://marco-pivetta.com    



On 6 September 2012 15:28, Dmitry Belyakov <[hidden email]> wrote:
Hello, 

I'm working on porting our beta-based zf2 code to the stable version and came across an issue with application initialization problem: in our test bootstrap we do Zend\Mvc\Application::init($config) 
but then ServiceManager preserves it's state between tests, wich is a problem. 

I wonder if anyone can suggest a way to properly bootstrap for testing. 

Dmitry.


Reply | Threaded
Open this post in threaded view
|

Re: Unit testing & ServiceManager's global state

dmitrybelyakov

Hi Marco,

Thanks a lot for your response :)

It's almost the same thing I tried to do, but it does also fail. The problem is with $moduleManager->loadModules()
when it tries to load more then once (like for the next test in suite) then it will explode saying the ModuleManager expects 
module config to be an array, but received a boolean. Unless you replace all require_onces with plain requires. 
Like you do in /src/OcraDiCompiler/Module.php

Thats ok, unless you forget to replace it somewhere.
It might be better if we could just drop ServiceManager's internal cache somehow between tests.

Dmitry.


On Thursday, September 6, 2012 at 6:36 PM, Dmitry Belyakov wrote:


Hi Marco,

Thanks a lot for your response :)

It's almost the same thing I tried to do, but it does also fail. The problem is with $moduleManager->loadModules()
when it tries to load more then once (like for the next test in suite) then it will explode saying the ModuleManager expects 
module config to be an array, but received a boolean. Unless you replace all require_onces with plain requires. 
Like you do in /src/OcraDiCompiler/Module.php

Thats ok, unless you forget to replace it somewhere.
It might be better if we could just drop ServiceManager's internal cache somehow between tests.

Dmitry.


On Thursday, September 6, 2012 at 5:31 PM, Marco Pivetta wrote:

You can use my example test bootstrapper:

https://github.com/Ocramius/OcraDiCompiler/blob/master/tests/OcraDiCompilerTest/ServiceManagerTestCase.php

I think I ported it also in the Doctrine modules, cannot remind it right now.

Marco Pivetta

http://twitter.com/Ocramius     

http://marco-pivetta.com    



On 6 September 2012 15:28, Dmitry Belyakov <[hidden email]> wrote:
Hello, 

I'm working on porting our beta-based zf2 code to the stable version and came across an issue with application initialization problem: in our test bootstrap we do Zend\Mvc\Application::init($config) 
but then ServiceManager preserves it's state between tests, wich is a problem. 

I wonder if anyone can suggest a way to properly bootstrap for testing. 

Dmitry.



Reply | Threaded
Open this post in threaded view
|

Re: Unit testing & ServiceManager's global state

Marco Pivetta
This post has NOT been accepted by the mailing list yet.
You have to use a new module manager each time you want to load modules more than once...

Marco Pivetta

http://twitter.com/Ocramius     

http://marco-pivetta.com    



On 6 September 2012 16:39, dmitrybelyakov [via Zend Framework Community] <[hidden email]> wrote:

Hi Marco,

Thanks a lot for your response :)

It's almost the same thing I tried to do, but it does also fail. The problem is with $moduleManager->loadModules()
when it tries to load more then once (like for the next test in suite) then it will explode saying the ModuleManager expects 
module config to be an array, but received a boolean. Unless you replace all require_onces with plain requires. 
Like you do in /src/OcraDiCompiler/Module.php

Thats ok, unless you forget to replace it somewhere.
It might be better if we could just drop ServiceManager's internal cache somehow between tests.

Dmitry.


On Thursday, September 6, 2012 at 6:36 PM, Dmitry Belyakov wrote:


Hi Marco,

Thanks a lot for your response :)

It's almost the same thing I tried to do, but it does also fail. The problem is with $moduleManager->loadModules()
when it tries to load more then once (like for the next test in suite) then it will explode saying the ModuleManager expects 
module config to be an array, but received a boolean. Unless you replace all require_onces with plain requires. 
Like you do in /src/OcraDiCompiler/Module.php

Thats ok, unless you forget to replace it somewhere.
It might be better if we could just drop ServiceManager's internal cache somehow between tests.

Dmitry.


On Thursday, September 6, 2012 at 5:31 PM, Marco Pivetta wrote:

You can use my example test bootstrapper:

https://github.com/Ocramius/OcraDiCompiler/blob/master/tests/OcraDiCompilerTest/ServiceManagerTestCase.php

I think I ported it also in the Doctrine modules, cannot remind it right now.

Marco Pivetta

http://twitter.com/Ocramius     

http://marco-pivetta.com    



On 6 September 2012 15:28, Dmitry Belyakov <[hidden email]> wrote:
Hello, 

I'm working on porting our beta-based zf2 code to the stable version and came across an issue with application initialization problem: in our test bootstrap we do Zend\Mvc\Application::init($config) 
but then ServiceManager preserves it's state between tests, wich is a problem. 

I wonder if anyone can suggest a way to properly bootstrap for testing. 

Dmitry.






If you reply to this email, your message will be added to the discussion below:
http://zend-framework-community.634137.n4.nabble.com/Unit-testing-ServiceManager-s-global-state-tp4656713p4656723.html
To start a new topic under ZF Contributor, email [hidden email]
To unsubscribe from ZF Contributor, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Unit testing & ServiceManager's global state

Marco Pivetta
In reply to this post by Dmitry Belyakov
This probably looks better:

https://github.com/doctrine/DoctrineModule/blob/master/tests/DoctrineModuleTest/ServiceManagerTestCase.php

Marco Pivetta

http://twitter.com/Ocramius     

http://marco-pivetta.com    



On 6 September 2012 16:36, Dmitry Belyakov <[hidden email]> wrote:

Hi Marco,

Thanks a lot for your response :)

It's almost the same thing I tried to do, but it does also fail. The problem is with $moduleManager->loadModules()
when it tries to load more then once (like for the next test in suite) then it will explode saying the ModuleManager expects 
module config to be an array, but received a boolean. Unless you replace all require_onces with plain requires. 
Like you do in /src/OcraDiCompiler/Module.php

Thats ok, unless you forget to replace it somewhere.
It might be better if we could just drop ServiceManager's internal cache somehow between tests.

Dmitry.


On Thursday, September 6, 2012 at 5:31 PM, Marco Pivetta wrote:

You can use my example test bootstrapper:

https://github.com/Ocramius/OcraDiCompiler/blob/master/tests/OcraDiCompilerTest/ServiceManagerTestCase.php

I think I ported it also in the Doctrine modules, cannot remind it right now.

Marco Pivetta

http://twitter.com/Ocramius     

http://marco-pivetta.com    



On 6 September 2012 15:28, Dmitry Belyakov <[hidden email]> wrote:
Hello, 

I'm working on porting our beta-based zf2 code to the stable version and came across an issue with application initialization problem: in our test bootstrap we do Zend\Mvc\Application::init($config) 
but then ServiceManager preserves it's state between tests, wich is a problem. 

I wonder if anyone can suggest a way to properly bootstrap for testing. 

Dmitry.



Reply | Threaded
Open this post in threaded view
|

RE: Unit testing & ServiceManager's global state

Roediger, Tim

Not to take away anything from Marco’s great work, but I happened to refactor the tests for DoctrineMongoODMModule yesterday. It reboots the ServiceManager for each test, if you want to take a look.

 

Tim Roediger

 

From: Marco Pivetta [mailto:[hidden email]]
Sent: Friday, 7 September 2012 1:36 AM
To: Dmitry Belyakov
Cc: [hidden email]
Subject: Re: [zf-contributors] Unit testing & ServiceManager's global state

 

This probably looks better:

https://github.com/doctrine/DoctrineModule/blob/master/tests/DoctrineModuleTest/ServiceManagerTestCase.php

Marco Pivetta

http://twitter.com/Ocramius     

http://marco-pivetta.com    


On 6 September 2012 16:36, Dmitry Belyakov <[hidden email]> wrote:

 

Hi Marco,

 

Thanks a lot for your response :)

 

It's almost the same thing I tried to do, but it does also fail. The problem is with $moduleManager->loadModules()

when it tries to load more then once (like for the next test in suite) then it will explode saying the ModuleManager expects 

module config to be an array, but received a boolean. Unless you replace all require_onces with plain requires. 

Like you do in /src/OcraDiCompiler/Module.php

 

Thats ok, unless you forget to replace it somewhere.

It might be better if we could just drop ServiceManager's internal cache somehow between tests.

 

Dmitry.

 

 

On Thursday, September 6, 2012 at 5:31 PM, Marco Pivetta wrote:

You can use my example test bootstrapper:

https://github.com/Ocramius/OcraDiCompiler/blob/master/tests/OcraDiCompilerTest/ServiceManagerTestCase.php

I think I ported it also in the Doctrine modules, cannot remind it right now.

Marco Pivetta

http://twitter.com/Ocramius     

http://marco-pivetta.com    


On 6 September 2012 15:28, Dmitry Belyakov <[hidden email]> wrote:

Hello, 

I'm working on porting our beta-based zf2 code to the stable version and came across an issue with application initialization problem: in our test bootstrap we do Zend\Mvc\Application::init($config) 
but then ServiceManager preserves it's state between tests, wich is a problem. 

I wonder if anyone can suggest a way to properly bootstrap for testing. 

Dmitry.

 

 

 

Reply | Threaded
Open this post in threaded view
|

Re: Unit testing & ServiceManager's global state

Dmitry Belyakov

Hi Tim,

That's pretty much the same, so I'm gonna stick to that approach for now.

Thanks!
Dmitry.



On Friday, September 7, 2012 at 1:48 AM, Roediger, Tim wrote:

Not to take away anything from Marco’s great work, but I happened to refactor the tests for DoctrineMongoODMModule yesterday. It reboots the ServiceManager for each test, if you want to take a look.

 

Tim Roediger

 

From: Marco Pivetta [[hidden email]]
Sent: Friday, 7 September 2012 1:36 AM
To: Dmitry Belyakov
Cc: [hidden email]
Subject: Re: [zf-contributors] Unit testing & ServiceManager's global state

 

This probably looks better:

https://github.com/doctrine/DoctrineModule/blob/master/tests/DoctrineModuleTest/ServiceManagerTestCase.php

Marco Pivetta

http://twitter.com/Ocramius     

http://marco-pivetta.com    


On 6 September 2012 16:36, Dmitry Belyakov <[hidden email]> wrote:

 

Hi Marco,

 

Thanks a lot for your response :)

 

It's almost the same thing I tried to do, but it does also fail. The problem is with $moduleManager->loadModules()

when it tries to load more then once (like for the next test in suite) then it will explode saying the ModuleManager expects 

module config to be an array, but received a boolean. Unless you replace all require_onces with plain requires. 

Like you do in /src/OcraDiCompiler/Module.php

 

Thats ok, unless you forget to replace it somewhere.

It might be better if we could just drop ServiceManager's internal cache somehow between tests.

 

Dmitry.

 

 

On Thursday, September 6, 2012 at 5:31 PM, Marco Pivetta wrote:

You can use my example test bootstrapper:

https://github.com/Ocramius/OcraDiCompiler/blob/master/tests/OcraDiCompilerTest/ServiceManagerTestCase.php

I think I ported it also in the Doctrine modules, cannot remind it right now.

Marco Pivetta

http://twitter.com/Ocramius     

http://marco-pivetta.com    


On 6 September 2012 15:28, Dmitry Belyakov <[hidden email]> wrote:

Hello, 

I'm working on porting our beta-based zf2 code to the stable version and came across an issue with application initialization problem: in our test bootstrap we do Zend\Mvc\Application::init($config) 
but then ServiceManager preserves it's state between tests, wich is a problem. 

I wonder if anyone can suggest a way to properly bootstrap for testing. 

Dmitry.