<?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>Jacob Santos &#187; unit test</title>
	<atom:link href="http://jacobsantos.com/tags/unit-test/feed/" rel="self" type="application/rss+xml" />
	<link>http://jacobsantos.com</link>
	<description>Rumblings, rants, essays, stories by Jacob Santos about Web Site Development, Persistent Browser-Based Games, personal journal, and Programming.</description>
	<lastBuildDate>Fri, 03 Feb 2012 01:06:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3-aortic-dissection</generator>
		<item>
		<title>Unit Tests Work! A Look at WordPress</title>
		<link>http://jacobsantos.com/2008/web-applications/unit-tests-work-a-look-at-wordpress/</link>
		<comments>http://jacobsantos.com/2008/web-applications/unit-tests-work-a-look-at-wordpress/#comments</comments>
		<pubDate>Tue, 26 Aug 2008 01:11:19 +0000</pubDate>
		<dc:creator>santosj</dc:creator>
				<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[unit test]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.santosj.name/?p=446</guid>
		<description><![CDATA[<a href="http://jacobsantos.com/2008/web-applications/unit-tests-work-a-look-at-wordpress/" title="Unit Tests Work! A Look at WordPress"></a>Unit Testing works! The best part? It is fun. At least at the expense of someone else. I pick on WordPress because it is the system that I&#8217;m building unit tests for. I&#8217;m going to look at different bugs that &#8230;<p class="read-more"><a href="http://jacobsantos.com/2008/web-applications/unit-tests-work-a-look-at-wordpress/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://jacobsantos.com/2008/web-applications/unit-tests-work-a-look-at-wordpress/" title="Unit Tests Work! A Look at WordPress"></a><p>Unit Testing works! The best part? It is fun. At least at the expense of someone else. I pick on WordPress because it is the system that I&#8217;m building unit tests for. I&#8217;m going to look at different bugs that were solved and may have been found because of unit testing.</p>
<h3>add_filter() in plugins.php</h3>
<p>Was <a href="http://trac.wordpress.org/ticket/3875">Reported</a>. Tested and solved by unit testing.</p>
<p><strong>Problem</strong></p>
<p>Usage with objects is broken, even with the current version (2.2.2) and trunk. The problem is from using serialize on classes, which when added, after the properties change, cannot be removed. This is because the class &#8220;state&#8221; has changed and will serialize to a different string than what was added.</p>
<p><strong>Solutions</strong></p>
<ol>
<li>The fix, that won&#8217;t affect all plugins that use classes, is to explicitly check for objects and add a new property to that class that can be later referenced. It works, but it is slow, almost 3x as slow as serialize. Wasn&#8217;t tested on PHP 4 systems, but in theory, if it works on PHP 5, it should work for PHP 4.</li>
<li>All plugin authors, which choose to use classes to include __sleep() method in their class, which cache the state at the beginning and return that state. This would provide consistency, but would require work for all plugin authors and would force WordPress blog administrators to upgrade their plugins.</li>
<li>Don&#8217;t use classes as plugins or use another class for storing properties.</li>
</ol>
<h3>apply_filters() in plugins.php</h3>
<p>Was <a href="http://trac.wordpress.org/changeset/5857">patched</a> and was only confirmed by unit tests.</p>
<p><strong>Problem</strong></p>
<p>If you remove a filter that is part of the same tag inside the apply_filter loop, it will ignore the rest of the hooks. (from <a href="http://trac.wordpress.org/ticket/4625">ticket</a>).</p>
<p>Interestly, the problem was in there places, but only fixed in two. Also interesting is that the functionality was duplicated in three different places instead of creating a function and using that instead.</p>
<p><strong>Solution</strong></p>
<p>See ticket.</p>
<h3>merge_filters() in plugins.php</h3>
<p>Was <a href="http://trac.wordpress.org/ticket/4715">reported</a>.</p>
<p><strong>Problem</strong></p>
<p>Array_merge will append (the desired result) $wp_filter['all'] to $wp_filter[$tag] and completely destroy the priority that was set for $wp_filter[$tag] (most likely not the desired result). </p>
<p>From this I can gather that a person won&#8217;t be able to remove a hook that was added. I can also figure that nothing and no one uses $wp_filter['all'] because it would destroy the priority for every hook. Or it works and I&#8217;m crazy.</p>
<p>My tests prove that 1) array_merge destroys the priority, and 2) if I had tested for it, it would have proven that you wouldn&#8217;t be able to remove a previous hook afterwards (conjecture, will need to add it into the test).</p>
<p>Thanks to Sam Angove, from wp-hackers, there are several bugs in the formatting.php file, so at least it proves that Unit Testing is justified. If it is justified with only two Unit tests with over 50%, I think it also says a lot for other projects.</p>
<p>Unit Testing is awesome, <a href="http://www.phpunit.de">PHPUnit</a> and <a href="http://simpletest.org/">SimpleTest</a> is awesome. What else more do you need?</p>

<p><strong>Possibly Related Posts:</strong></p>
<ul>
<li><a href="http://jacobsantos.com/2009/web-applications/wordpress-plugin-and-theme-scope/">WordPress Plugin and Theme Scope</a></li>
<li><a href="http://jacobsantos.com/2009/web-applications/what-ive-learned-from-wordpress/">What I&#8217;ve Learned From WordPress</a></li>
<li><a href="http://jacobsantos.com/2009/web-applications/why-do-i-feel-like-an-asshole-when-criticizing-wordpress/">Why Do I Feel Like an Asshole When Criticizing WordPress?</a></li>
<li><a href="http://jacobsantos.com/2009/web-applications/php5-straw-man-argument/">PHP5 Straw Man Argument</a></li>
<li><a href="http://jacobsantos.com/2008/web-applications/wordpress-27-changes-class-for-plugins/">WordPress 2.7 Changes Class for Plugins</a></li>
</ul><br />
]]></content:encoded>
			<wfw:commentRss>http://jacobsantos.com/2008/web-applications/unit-tests-work-a-look-at-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Does this mean PHP projects should grow up too?</title>
		<link>http://jacobsantos.com/2007/general/does-this-mean-php-projects-should-grow-up-too/</link>
		<comments>http://jacobsantos.com/2007/general/does-this-mean-php-projects-should-grow-up-too/#comments</comments>
		<pubDate>Tue, 09 Oct 2007 23:52:05 +0000</pubDate>
		<dc:creator>santosj</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[unit test]]></category>

		<guid isPermaLink="false">http://www.santosj.name/programming/php-related/php/does-this-mean-php-projects-should-grow-up-too/</guid>
		<description><![CDATA[<a href="http://jacobsantos.com/2007/general/does-this-mean-php-projects-should-grow-up-too/" title="Does this mean PHP projects should grow up too?"></a>The content in Joshua Eichorn post about certification and test automation has been on my mind with the development of WordPress and others. Padraic Brady has been discussing Unit Testing and test automation for a while now. With good reason, &#8230;<p class="read-more"><a href="http://jacobsantos.com/2007/general/does-this-mean-php-projects-should-grow-up-too/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://jacobsantos.com/2007/general/does-this-mean-php-projects-should-grow-up-too/" title="Does this mean PHP projects should grow up too?"></a><p>The content in Joshua Eichorn post about <a href="http://blog.joshuaeichorn.com/archives/2007/10/09/im-certifiable/">certification and test automation</a> has been on my mind with the development of WordPress and others. <a href="http://blog.astrumfutura.com">Padraic Brady</a> has been discussing <a href="http://en.wikipedia.org/wiki/Unit_testing">Unit Testing</a> and test automation for a while now. With good reason, it should be part of every project.</p>
<p>I had to learn the hard way, but once you get into the swing of writing tests, it slowly starts to make sense. It makes a lot of sense. Something that bothered me about WordPress were regressions. WTF? Well, if there were unit tests and acceptance tests, the probability of that happening would decrease tremendously. Depending on the quality of the tests of course.</p>
<p>The good news is that WordPress is growing up also and has initial development of <a href="http://svn.automattic.com/wordpress-tests">functional test automation</a>. Shouldn&#8217;t every open source PHP project take the step forward in maturity and include the step of writing tests? Cheers for those projects that already have done this.</p>
<p>However, this isn&#8217;t the fault of the core developers of these projects. Writing tests may be boring and fun (I would be interested to find out why this is), but the core developers want to use their time to develop awesome and probably slightly broken features. If that is the case and users care, then I think it would be useful to write the tests instead of complaining. If not, then all is well, because users will eventually discover the bug after accessing the branches of code from a much higher level.</p>
<p>Cheers to any project that actually reads this post and follows through, if not already doing so. Although that outcome will most likely be coincidental, in any case. It is unlikely any project would change without user involvement.</p>

<p><strong>Possibly Related Posts:</strong></p>
<ul>
<li><a href="http://jacobsantos.com/2011/general/bullet-e-book-library-management-and-content-server/">Bullet: E-Book Library Management and Content Server</a></li>
<li><a href="http://jacobsantos.com/2011/general/using-zendframework-2-beta1-for-directory-project/">Using ZendFramework 2 beta1 For Directory Project</a></li>
<li><a href="http://jacobsantos.com/2011/general/the-way-of-kings-and-cosmere-theory/">The Way of Kings and Cosmere Theory</a></li>
<li><a href="http://jacobsantos.com/2011/general/in-time-movie-premise-flawed/">&#8220;In Time&#8221; Movie Premise Flawed</a></li>
<li><a href="http://jacobsantos.com/2011/general/completing-http-library-for-php/">Completing HTTP Library For PHP</a></li>
</ul><br />
]]></content:encoded>
			<wfw:commentRss>http://jacobsantos.com/2007/general/does-this-mean-php-projects-should-grow-up-too/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Unit Tests for WordPress</title>
		<link>http://jacobsantos.com/2007/projects/unit-tests-for-wordpress/</link>
		<comments>http://jacobsantos.com/2007/projects/unit-tests-for-wordpress/#comments</comments>
		<pubDate>Tue, 04 Sep 2007 01:00:17 +0000</pubDate>
		<dc:creator>santosj</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[article]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[planning]]></category>
		<category><![CDATA[unit test]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.santosj.name/projects/unit-tests-for-wordpress/</guid>
		<description><![CDATA[<a href="http://jacobsantos.com/2007/projects/unit-tests-for-wordpress/" title="Unit Tests for WordPress"></a>I think for as much coverage as possible the following should be done for encompassing the whole of WordPress using tests. The PHPUnit version 3.2.0 should include many new features that should allow for better testing WordPress in environments more &#8230;<p class="read-more"><a href="http://jacobsantos.com/2007/projects/unit-tests-for-wordpress/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://jacobsantos.com/2007/projects/unit-tests-for-wordpress/" title="Unit Tests for WordPress"></a><p>I think for as much coverage as possible the following should be done for encompassing the whole of WordPress using tests. The PHPUnit version 3.2.0 should include many new features that should allow for better testing WordPress in environments more true to XP programming techniques. Along with PHPUnit, I have been meaning to build a site for statistics, but I think it will come later when I have more tests done.</p>
<ol>
<li>Unit Tests and Characterization Tests.</li>
<li>Hook Tests</li>
<li>Database Tests</li>
<li>Acceptance Tests</li>
</ol>
<h3>Unit Tests and Characterization Tests</h3>
<p>There aren&#8217;t very many functions or library files that allow for true Unit Testing, so I would rather combine the two tests, instead of trying to keep them separate. This would allow for coders writing tests to not worry about whether the function can be unit tested or have characterization tests. Comments should be made for the methods on what is tested to let others know if the test is an unit test or characterization test to the knowledge of the author.</p>
<p>All actions and filters will have to be disabled while running the tests to allow for just testing the functions. Testing the hooks would be done separately. Looking through some of the bug reports, it seems that some hooks are required to test for some obscure bugs. This should be done in the next section.</p>
<p>The unit tests and characterizations tests should be run by themselves, separate in execution from the rest of the tests. I have also been meaning to remove dependencies on my changes. I think that since the last WordPress commit, that is no longer an issue.</p>
<h3>Hook Tests</h3>
<p>Remove all filters and actions and manually add the hook workflow to test the result. This would require mock functions that duplicate the functions or running the full version of WordPress, except for the output.</p>
<p>Testing the hooks has more to do with regressions and refactoring of hooks, since hooks should work as long as the plugin test passes.</p>
<h3>Database Tests</h3>
<p>PHPUnit 3.2.0 will include DBUnit which will allow using a snapshot of the database and test output using that instead of a real database. This should be extremely helpful in testing Database Queries.</p>
<h3>Acceptance Tests</h3>
<p>Test the blog site to make sure that everything appears correctly.</p>

<p><strong>Possibly Related Posts:</strong></p>
<ul>
<li><a href="http://jacobsantos.com/2011/projects/calibre-improvements/">Calibre Improvements</a></li>
<li><a href="http://jacobsantos.com/2011/projects/dragonu-bug-tracker-dev-milestone-1/">DragonU Bug Tracker Dev &#8211; Milestone 1</a></li>
<li><a href="http://jacobsantos.com/2009/projects/dragon-mvc/">Dragon MVC</a></li>
<li><a href="http://jacobsantos.com/2009/projects/why-i-contributed-to-wordpress/">Why I Contributed to WordPress</a></li>
<li><a href="http://jacobsantos.com/2009/projects/dragonu-db-component/">DragonU DB Component</a></li>
</ul><br />
]]></content:encoded>
			<wfw:commentRss>http://jacobsantos.com/2007/projects/unit-tests-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

