<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>John Kleijn - TDD</title>
    <link>http://www.johnkleijn.nl/</link>
    <description>Cogito ergo sum, baby</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.5.2 - http://www.s9y.org/</generator>
    <pubDate>Fri, 07 May 2010 10:52:07 GMT</pubDate>

    <image>
        <url>http://www.johnkleijn.nl/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: John Kleijn - TDD - Cogito ergo sum, baby</title>
        <link>http://www.johnkleijn.nl/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>Why you can't (or shouldn't) unserialize exceptions</title>
    <link>http://www.johnkleijn.nl/2010/Why-you-cant-or-shouldnt-unserialize-exceptions</link>
            <category>TDD</category>
    
    <comments>http://www.johnkleijn.nl/2010/Why-you-cant-or-shouldnt-unserialize-exceptions#comments</comments>
    <wfw:comment>http://www.johnkleijn.nl/wfwcomment.php?cid=32</wfw:comment>

    <slash:comments>1</slash:comments>
    <wfw:commentRss>http://www.johnkleijn.nl/rss.php?version=2.0&amp;type=comments&amp;cid=32</wfw:commentRss>
    

    <author>nospam@example.com (John Kleijn)</author>
    <content:encoded>
    &lt;p class=&quot;whiteline&quot;&gt;Sorry for not posting much, I&#039;m insanely busy, but I can squeeze in a quick post. I already lost lots of time on the topic of this post, so I might as well take 10 minutes more and explain.
&lt;/p&gt;&lt;p class=&quot;whiteline&quot;&gt;I develop using TDD, using PHPUnit. I (usually) use Zend Framework in combination with Doctrine. To be a 100% sure tests are completely isolated, PHPUnit has a nice feature called &quot;Process Isolation&quot;, which means as much as that every test is run in its own environment. To get the result of the test into the main environment, PHPUnit serializes and unserializes the &quot;test result&quot; object. Which is fine, I couldn&#039;t think of another way to do it.
&lt;/p&gt;&lt;p class=&quot;whiteline&quot;&gt;But, this test result object may include failures, in which case the exception(s) are attached. Which is a problem. A few lines of code is worth a thousand words, so here you go:
&lt;/p&gt;&lt;p class=&quot;break&quot;&gt;jkleijn@goliath:~$ php -a&lt;/p&gt;&lt;p class=&quot;whiteline&quot;&gt;Interactive shell
&lt;/p&gt;&lt;p class=&quot;break&quot;&gt;php &gt; class Argument { function __wakeup() { throw new LogicException; }}&lt;/p&gt;&lt;p class=&quot;break&quot;&gt;php &gt; class Subject { function fail($argument){ throw new InvalidArgumentException; }}&lt;/p&gt;&lt;p class=&quot;break&quot;&gt;php &gt; try { $s = new Subject; $s-&gt;fail(new Argument); } catch(Exception $e) { unserialize(serialize($e)); }&lt;/p&gt;&lt;p class=&quot;break&quot;&gt;PHP Warning:  Uncaught exception &#039;LogicException&#039; in php shell code:1&lt;/p&gt;&lt;p class=&quot;break&quot;&gt;Stack trace:&lt;/p&gt;&lt;p class=&quot;break&quot;&gt;#0 [internal function]: Argument-&gt;__wakeup()&lt;/p&gt;&lt;p class=&quot;break&quot;&gt;#1 php shell code(1): unserialize(&#039;O:24:&quot;InvalidAr...&#039;)&lt;/p&gt;&lt;p class=&quot;break&quot;&gt;#2 {main}&lt;/p&gt;&lt;p class=&quot;break&quot;&gt;  thrown in php shell code on line 1&lt;/p&gt;&lt;p class=&quot;whiteline&quot;&gt;php &gt; 
&lt;/p&gt;&lt;p class=&quot;whiteline&quot;&gt;As you can see, unserializing the exception triggers the __wakeup() method in the argument that was passed to the failing method. The problem with that is that an Exception object in PHP includes a full backtrace, which, amongst other things, includes arguments to function or method calls. No issue if the arguments are scalar values or a simple array, but an object may not like being serialized, per se.
&lt;/p&gt;&lt;p class=&quot;whiteline&quot;&gt;Such is the case with Doctrine_Record and Doctrine_Collection objects. They can be unserialized, but require that a database connection has been made first, or they will throw: Uncaught exception &#039;Doctrine_Connection_Exception&#039; with message &#039;There is no open connection&#039;. Which obviously is not a precondition one would want to have for running test cases. It kinda defeats having test isolation in the first place.
&lt;/p&gt;&lt;p class=&quot;whiteline&quot;&gt;The good news is that this is only an issue if a test fails, so as long as your test passes, you&#039;re fine. The bad news is that in order to find out WHY your test failed, you have to hack a file dump of the serialized test result, to find the exception message and origin. Which is a nuisance at best.
&lt;/p&gt; 
    </content:encoded>

    <pubDate>Fri, 07 May 2010 12:52:07 +0200</pubDate>
    <guid isPermaLink="false">http://www.johnkleijn.nl/2010/32</guid>
    <category>exceptions</category>
<category>phpunit</category>
<category>test isolation</category>

</item>
<item>
    <title>NetBeans is TDD unfriendly!</title>
    <link>http://www.johnkleijn.nl/2010/NetBeans-is-TDD-unfriendly!</link>
            <category>TDD</category>
    
    <comments>http://www.johnkleijn.nl/2010/NetBeans-is-TDD-unfriendly!#comments</comments>
    <wfw:comment>http://www.johnkleijn.nl/wfwcomment.php?cid=30</wfw:comment>

    <slash:comments>3</slash:comments>
    <wfw:commentRss>http://www.johnkleijn.nl/rss.php?version=2.0&amp;type=comments&amp;cid=30</wfw:commentRss>
    

    <author>nospam@example.com (John Kleijn)</author>
    <content:encoded>
    &lt;p class=&quot;break&quot;&gt;I am getting soo tired of Zend Studio for Eclipse. On large projects, or rather projects with large libs (e.g. Zend Framework and Doctrine) code suggest and &quot;building&quot; is just too slow. It is since about a month impossible to blame hardware imitations either. &lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.johnkleijn.nl/2010/NetBeans-is-TDD-unfriendly!#extended&quot;&gt;Continue reading &quot;NetBeans is TDD unfriendly!&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Mon, 29 Mar 2010 12:18:16 +0200</pubDate>
    <guid isPermaLink="false">http://www.johnkleijn.nl/2010/30</guid>
    <category>ide</category>
<category>netbeans</category>
<category>phpunit</category>
<category>tdd</category>
<category>zend studio</category>

</item>

</channel>
</rss>
