I am writing unit tests that require that I either use or mock getRequest->getHeader('referer') within Zend framework where there is a condition on the referer to determine whether or not a new session is set based on its value.
What would be the best way to test this properly?
Should I simply mock the controller and call the header request like $controller->getRequest->getHeader('referer') or do I need to mock the request object?
Obviously since this is a unit test, were just mocking this behavior to ensure the code works correctly, so I'm not even sure how you would simulate a url request header.
You should inject your own request object into the framework. I suggest using Zend_Controller_Request_HttpTestCase as it gives you complete flexibility over setting all the various properties (headers, query, body, uri, cookies, etc). You'll be able to set your own referer and test how your application reacts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With