<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Drowned World &#187; PHPUnit</title>
	<atom:link href="http://www.drownedworld.co.uk/category/phpunit/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.drownedworld.co.uk</link>
	<description>Same kind of moon, same kind of jungle.</description>
	<lastBuildDate>Sun, 18 Jul 2010 21:09:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Zend Controller redirects and unit testing</title>
		<link>http://www.drownedworld.co.uk/2010/07/zend-controller-redirects-and-unit-testing/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.drownedworld.co.uk/2010/07/zend-controller-redirects-and-unit-testing/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 21:09:23 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHPUnit]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.drownedworld.co.uk/?p=243</guid>
		<description><![CDATA[This afternoon I found a bug in some old code that I&#8217;m refactoring and retrofitting unit tests into. Well, not a bug exactly but a Zend Framework controller quirk. It drove me absolutely nuts for ages until I went to &#8230; <a href="http://www.drownedworld.co.uk/2010/07/zend-controller-redirects-and-unit-testing/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This afternoon I found a bug in some old code that I&#8217;m refactoring and retrofitting unit tests into. Well, not a bug exactly but a Zend Framework controller quirk. It drove me absolutely nuts for ages until I went to Google and found a solution. Imagine the following example which is some methods from a class that extends the ControllerTestCase in the Zend_Test library:</p>
<pre>public function testEmptyUrlParameterRedirctsCorrectly()
{
     $this-&gt;dispatch('/user/profile/');

     $this-&gt;assertModule('user');
     $this-&gt;assertController('profile');
     $this-&gt;assertAction('index');

    $this-&gt;assertRedirectTo('/user');
    $this-&gt;assertResponseCode('302');
    $this-&gt;assertRedirect();
}

public function testInvalidUrlParameterRedirctsCorrectly()
{
     $this-&gt;dispatch('/user/profile/invalid-username');

     $this-&gt;assertModule('user');
     $this-&gt;assertController('profile');
     $this-&gt;assertAction('index');

    $this-&gt;assertRedirectTo('/user/invalid');
    $this-&gt;assertResponseCode('302');
    $this-&gt;assertRedirect();
}</pre>
<p>The controller is expecting a url like /user/profile/username. If the username is invalid or missing altogether we want to test that the page redirects elsewhere and displays any necessary feedback to the user. While this functionality had always seemed to work in the application, the unit tests were failing for some reason. After a bit of assert writing it turned out that the tests were returning a module/controller combination of default/error instead of user/profile. The error was nowhere to be seen in the application and it continued to redirect correctly as it always had.</p>
<p>A quick <a href="http://zend-framework-community.634137.n4.nabble.com/Zend-Test-skipping-over-redirects-td658760.html">read on Nabble</a> later and I came away with an interesting tip from Zend developer Matthew Weier O&#8217;Phinney.</p>
<blockquote><p>&#8220;Whenever you _forward() or redirect, you should  return immediately. As<br />
an example:</p>
<p>if (!$form-&gt;isValid($request-&gt;getPost()))  {<br />
return $this-&gt;_forward(&#8216;details&#8217;);<br />
}</p>
<p>If you don&#8217;t, the action continues to process. This  would definitely<br />
have an impact on <strong>redirects</strong> as  well.&#8221;</p></blockquote>
<p>Now, I&#8217;ve always written my redirects in the following way:</p>
<pre>$this-&gt;_redirect('user');</pre>
<p>But after adding the return statement into the legacy code, all the new controller tests passed. I&#8217;m not really sure what this implies for any other redirects that have yet to be unit tested as no errors have been thrown by the application logs. It may be possible that redirects only operate this way during unit tests and will return automatically during normal execution. I&#8217;ll investigate this soon unless anyone else has any insightful thoughts on the matter?</p>
<div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.drownedworld.co.uk/2010/07/zend-controller-redirects-and-unit-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter Lists</title>
		<link>http://www.drownedworld.co.uk/2009/10/twitter-lists/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.drownedworld.co.uk/2009/10/twitter-lists/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 09:36:20 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHPUnit]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.drownedworld.co.uk/?p=148</guid>
		<description><![CDATA[Twitter have introduced lists as a way to organise who you follow.  I&#8217;ve started building a PHP list that follows interesting sites and prominent members of the community. Check it out here: http://twitter.com/teengenerate/php]]></description>
			<content:encoded><![CDATA[<p>Twitter have introduced lists as a way to organise who you follow.  I&#8217;ve started building a PHP list that follows interesting sites and prominent members of the community. Check it out here:</p>
<p><a href="http://twitter.com/teengenerate/php">http://twitter.com/teengenerate/php</a></p>
<div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.drownedworld.co.uk/2009/10/twitter-lists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
