<?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>klenwell press &#187; Projects</title>
	<atom:link href="http://klenwell.com/press/category/projects/feed/" rel="self" type="application/rss+xml" />
	<link>http://klenwell.com/press</link>
	<description>A Developer's Broadsheet</description>
	<lastBuildDate>Fri, 13 Jan 2012 14:51:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.2</generator>
		<item>
		<title>Advance Model Testing in CakePhp</title>
		<link>http://klenwell.com/press/2009/09/model-testing-cakephp/</link>
		<comments>http://klenwell.com/press/2009/09/model-testing-cakephp/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 05:23:50 +0000</pubDate>
		<dc:creator>klenwell</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[cakephp]]></category>

		<guid isPermaLink="false">http://klenwell.com/press/?p=145</guid>
		<description><![CDATA[One of the most challenging issues I&#8217;ve found in developing with CakePhp is unit testing. Testing models, with its dependence on fixtures, is especially touchy. The documentation, while constantly improving, still seems at crucial points incomplete or inconsistent. In this post, I&#8217;d like to draw attention to a few pitfalls that I burned a few [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most challenging issues I&#8217;ve found in developing with CakePhp is unit testing.  Testing models, with its dependence on fixtures, is especially touchy.  The documentation, while constantly improving, still seems at crucial points incomplete or inconsistent.  In this post, I&#8217;d like to draw attention to a few pitfalls that I burned a few brain cycles in overcoming and offer some tips for unit testing models with fixtures.</p>
<h4>Cake Core Bugs</h4>
<p>There are a couple documented bugs that still outstanding as of release 1.2.4.8284.  If you are doing anything more than basic testing, one of these could bite you eventually:</p>
<p><a onclick="window.open(this.href,'_blank');return false;" href="https://trac.cakephp.org/ticket/6205">https://trac.cakephp.org/ticket/6205</a><br />
<a onclick="window.open(this.href,'_blank');return false;" href="https://trac.cakephp.org/ticket/6468">https://trac.cakephp.org/ticket/6468</a></p>
<p>Here is a patch file that fixes them:</p>
<pre class="brush: php">
# Fix issues with CakePhp model unit tests
# Tom at klenwell@gmail.com
# CakePhp Version: 1.2.4.8284

diff -r ead5d3b62da7 -r df04a99fec1b cake/libs/model/datasources/dbo_source.php
--- a/cake/libs/model/datasources/dbo_source.php	Mon Aug 10 21:16:09 2009 -0700
+++ b/cake/libs/model/datasources/dbo_source.php	Mon Sep 14 21:08:12 2009 -0700
@@ -2355,6 +2355,15 @@ class DboSource extends DataSource {
 			$column[&#039;default&#039;] = null;
 		}

+                // solves fixture problem
+                // see https://trac.cakephp.org/ticket/6205
+                if (($column[&#039;type&#039;] == &#039;datetime&#039; || $column[&#039;type&#039;] == &#039;timestamp&#039; ) &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp; isset($column[&#039;default&#039;]) &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp; $column[&#039;default&#039;] === &#039;&#039;) {
+                    $column[&#039;default&#039;] = null;
+                }
+                if ( $column[&#039;type&#039;] == &#039;timestamp&#039; &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp; $column[&#039;default&#039;] === &#039;CURRENT_TIMESTAMP&#039; )
+                    #pr($column);
+                    $column[&#039;default&#039;] = null;
+
 		if (isset($column[&#039;key&#039;]) &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp; $column[&#039;key&#039;] == &#039;primary&#039; &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp; $type == &#039;integer&#039;) {
 			$out .= &#039; &#039; . $this-&amp;amp;amp;gt;columns[&#039;primary_key&#039;][&#039;name&#039;];
 		} elseif (isset($column[&#039;key&#039;]) &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp; $column[&#039;key&#039;] == &#039;primary&#039;) {
@@ -2455,4 +2464,4 @@ class DboSource extends DataSource {
 		return &#039;string&#039;;
 	}
 }
-?&amp;amp;amp;gt;
\ No newline at end of file
+?&amp;amp;amp;gt;

diff -r ead5d3b62da7 -r df04a99fec1b cake/tests/lib/cake_test_fixture.php
--- a/cake/tests/lib/cake_test_fixture.php	Mon Aug 10 21:16:09 2009 -0700
+++ b/cake/tests/lib/cake_test_fixture.php	Mon Sep 14 21:08:12 2009 -0700
@@ -114,7 +114,12 @@ class CakeTestFixture extends Object {
 			}
 		}

-		if (!isset($this-&amp;amp;amp;gt;table)) {
+                // solves HABTM problem
+                // see https://trac.cakephp.org/ticket/6468
+                if (isset($model-&amp;amp;amp;gt;table)) {
+                        $this-&amp;amp;amp;gt;table = $model-&amp;amp;amp;gt;table;
+                }
+                elseif (!isset($this-&amp;amp;amp;gt;table)) {
 			$this-&amp;amp;amp;gt;table = Inflector::underscore(Inflector::pluralize($this-&amp;amp;amp;gt;name));
 		}

@@ -190,4 +195,4 @@ class CakeTestFixture extends Object {
 		return $return;
 	}
 }
-?&amp;amp;amp;gt;
\ No newline at end of file
+?&amp;amp;amp;gt;
</pre>
<h4>Fixtures</h4>
<p>The design and usage of fixtures still seems fickle.  For instance, the CakePhp docs and packaged test examples promote the explicit declaration of fields in fixtures.  I find this tedious.  Happily, it is also unnecessary, thanks to the import property.</p>
<p>To avoid this nuisance, use the import &#8216;model&#8217; or &#8216;table&#8217; setting to automatically load the table schema from the existing database.  See the example here:</p>
<p><a onclick="window.open(this.href,'_blank');return false;" href="http://code.google.com/p/cakewell/source/browse/app/tests/fixtures/simple_record_fixture.php">simple_record_fixture.php</a></p>
<p>A couple other tips for using fixtures:</p>
<p>1. Import all fixtures associated with a model in the unit test for that model<br />
2. If unit testing a plugin, the value in the fixtures property takes this format: <tt>plugin.$plugin_name.$model_name</tt><br />
3. Don&#8217;t forget to set up an empty database and include a test_suite setting in your database configuration file.</p>
<p>See these links for additional insight:<br />
<a onclick="window.open(this.href,'_blank');return false;" href="http://code.google.com/p/cakewell/source/browse/app/config/database.php.default">Cakewell Database Config File</a><br />
<a href="http://code.google.com/p/cakewell/source/browse/app/plugins/authwell/tests/cases/models/authwell_user.test.php" onclick="window.open(this.href,'_blank');return false;">Model Test with Fixtures</a><br />
<a onclick="window.open(this.href,'_blank');return false;" href="https://trac.cakephp.org/browser/trunk/cake/1.2.x.x/cake/tests/lib/cake_test_fixture.php">CakePhp cake_test_fixture.php</a></p>
<h4>HABTM Relationships</h4>
<p>To test models that have HABTM relationships with other models, it is necessary to create fixtures for both models having the HABTM relationship <em>and</em> a fixture to build the join table.  See these files from the Cakewell project for examples:</p>
<p><a onclick="window.open(this.href,'_blank');return false;" href="http://code.google.com/p/cakewell/source/browse/app/plugins/authwell/tests/fixtures/authwell_user_authwell_role_fixture.php">Authwell User-Role HABTM Fixture</a><br />
<a onclick="window.open(this.href,'_blank');return false;" href="http://code.google.com/p/cakewell/source/browse/app/plugins/authwell/tests/fixtures/authwell_role_authwell_privilege_fixture.php">Authwell Role-Privilege HABTM Fixture</a></p>
<p>The Cakewell Authwell plugin include a good example of a complex model unit test that is successfully configured.  It includes tests within the plugin directory that autoload a clean test database and successfully test models with HABTM associations.  The source can be found here:</p>
<p><a onclick="window.open(this.href,'_blank');return false;" href="http://code.google.com/p/cakewell/source/browse/#hg/app/plugins/authwell/tests">Authwell Plugin Test Directory</a></p>
]]></content:encoded>
			<wfw:commentRss>http://klenwell.com/press/2009/09/model-testing-cakephp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Project Cakewell</title>
		<link>http://klenwell.com/press/2009/08/project-cakewell/</link>
		<comments>http://klenwell.com/press/2009/08/project-cakewell/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 03:21:33 +0000</pubDate>
		<dc:creator>klenwell</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[cakephp]]></category>

		<guid isPermaLink="false">http://klenwell.com/press/?p=137</guid>
		<description><![CDATA[Project Cakewell is a CakePhp prototype application. Its main purpose is to document and demonstrate useful concepts and features of a web application built with the CakePhp framework. These include things like unit testing a component, creating a working fixture , and configuring your application to automatically detect the server environment and set the debug [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://cakewell.klenwell.com/" onclick="window.open(this.href,'_blank');return false;">Project Cakewell</a> is a <a href="http://cakephp.org/" onclick="window.open(this.href,'_blank');return false;">CakePhp</a> prototype application.  Its main purpose is to document and demonstrate useful concepts and features of a web application built with <a href="http://book.cakephp.org/view/13/Basic-Principles-of-CakePHP" onclick="window.open(this.href,'_blank');return false;">the CakePhp framework</a>.  These include things like unit testing a component, creating a working fixture , and configuring your application to automatically detect the server environment and set the debug level accordingly.</p>
<p>The code is open source and available at the Cakewell Google Code site at:</p>
<p><a href="http://code.google.com/p/cakewell/" onclick="window.open(this.href,'_blank');return false;">http://code.google.com/p/cakewell/</a></p>
<p>The live demo can be found at:</p>
<p><a href="http://cakewell.klenwell.com/ onclick="window.open(this.href,'_blank');return false;"">http://cakewell.klenwell.com/</a></p>
<p>I&#8217;ll add updates here as I progress.</p>
]]></content:encoded>
			<wfw:commentRss>http://klenwell.com/press/2009/08/project-cakewell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

