A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearUnit Testing HTTP-actions - page 1
User InfoPosts
Unit Testing HTTP-actions#1
I(m writing Yet Another PHP Framework, and now that I(ve coded a good deal of stuff, I(m starting to think about unit tests (yes, I know, bad form).

Some actions make the framework to modify HTTP behavior, such as create cookies, redirect the browser. Another major feature is that the the visited URI can affect the way the framework should behave.

In a nutshell, I need to be able to test stuff that affect, or are affected by, the environment, and not only the return values of functions/methods. How can I do this the easiest?

posted date: 2009-04-12 04:13:00


Re: Unit Testing HTTP-actions#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-12 04:13:01


Re: Unit Testing HTTP-actions#3
So it sounds as though you are writing integration tests and not unit tests (by definition anything which touches the environment is an integration test).Would this be easier to test through the stack through the browser? If so have a look at a browser automation framework, maybe something like http://wtr.rubyforge.org/

posted date: 2009-04-12 04:18:00


Re: Unit Testing HTTP-actions#4
In a nutshell, I need to be able to test stuff that affect, or are affected by, the environment, and not only the return values of functions/methods. How can I do this the easiest?If the environment can be simulated easily and can be represented completely with a small amount of state, then you should look into mock testing. Mock tests help you write tests without the mess of having to use real domain objects, if you can get away with simply making sure that things were called in the right order. Here(s a good overview of the principles.If that(s not the case, then you(re talking about an integration test, which is significantly more expensive. Integration tests help you see if your system is cohesively formed and usually run with a live, full-stack copy of your application. Here(s some more reading on integration tests.

posted date: 2009-04-12 04:20:00


Re: Unit Testing HTTP-actions#5
You should make HTTP requests to the server in your unit tests, and then check that cookies and headers are set correctly in the response. In PHP, I would use Zend_Http_Client. Documentation can be found here, in the package Zend_Http.

posted date: 2009-04-12 04:25:00


Re: Unit Testing HTTP-actions#6
I find the Simpletest web/form tester is easier than the PHPunit tools for this. I've actually had both main authors, side by side and asked them if they could integrate ST's WT into PHPUnit. Here's hoping.

posted date: 2009-04-12 04:37:00


Re: Unit Testing HTTP-actions#7
Or when you need to also test JavaScript on your pages and do some cross-browser testing, then you might want to take a look at Selenium.

posted date: 2009-04-12 04:51:00


Re: Unit Testing HTTP-actions#8
The environment is not easy to completely represent. Besides, if I manually generate stimuli, I'd rather not take the chance of generating the wrong things (i.e. not formatting stuff correctly.)

posted date: 2009-04-12 06:46:00


Re: Unit Testing HTTP-actions#9
But, yes, if you want to call it integration tests (I'm not 100% on the clear on the nuances between test and test. I just want to make sure everything's running as intended), It's all good. What I'm interested in, though, is the 'how', not as much the 'what'.

posted date: 2009-04-12 06:48:00


Re: Unit Testing HTTP-actions#10
(yes, I know, bad form).Yes. If you had started with the tests, you would have written your framework in a way, such that external dependencies could be mocked out. What you can do now, is to replace all calls to functions that manipulate global state, with a call to a global proxy object. You can then mock this out during tests. One particular troublesome change of global state, is calls to exit/die. You could try to replace this with an exception in your mock.

posted date: 2009-04-12 06:50:00


Re: Unit Testing HTTP-actions#11
That's weird - I'm pretty sure I stumbled upon SimpleTest before, but never got the impression it's this involved. This very much might be what I'm after. Thanks for the link, this requires more detailed investigation. Stand by for "accepted answer".

posted date: 2009-04-12 06:51:00


Re: Unit Testing HTTP-actions#12
I thought of this (Zend Framework seems to do that). But isn't there a point of possible failure between the proxy object and its signals to the actual environment? I still would need to test that, wouldn't I?

posted date: 2009-04-12 08:19:00


select page: « 1 2 »
Copyright ©2008-2017 www.momige.com, all rights reserved.