<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-689898573354229302</id><updated>2011-04-22T00:42:34.155+01:00</updated><category term='cakephp'/><title type='text'>one year eating cake</title><subtitle type='html'>my adventures on a 12 month project developing with CakePHP</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://oneyeareatingcake.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/689898573354229302/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://oneyeareatingcake.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Zoyen</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-689898573354229302.post-2921944942905866586</id><published>2008-11-25T15:50:00.000Z</published><updated>2008-11-25T16:55:00.036Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='cakephp'/><title type='text'>CakePHP Unit Test Model Woes :(</title><content type='html'>&lt;span style="font-family:arial;"&gt;I've been struggling for a couple of days now to build a very simple 'model' unit test.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;CakePHPs "&lt;/span&gt;&lt;a style="font-family: arial;" href="http://book.cakephp.org/view/22/CakePHP-Conventions"&gt;Convention over Configuration&lt;/a&gt;&lt;span style="font-family:arial;"&gt;" should help me out here and so should the &lt;/span&gt;&lt;a style="font-family: arial;" href="http://book.cakephp.org/"&gt;Cookbook&lt;/a&gt;&lt;span style="font-family:arial;"&gt;. Convention over configuration means that there won't be lots of config files to edit or changes to make to any core files of the framework as long as I stick to the CakePHP conventions.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;With Unit Tests though, it's quite hard to uncover the what the conventions are. The filename conventions described in the Cookbook (1.2)  differ from, for example, the fixture files created using Bake. Also the guys at &lt;/span&gt;&lt;a style="font-family: arial;" href="http://debuggable.com/"&gt;Debuggable &lt;/a&gt;&lt;span style="font-family:arial;"&gt;have re-factored and simplified the &lt;/span&gt;&lt;a style="font-family: arial;" href="http://debuggable.com/posts/testing-models-in-cakephp---now-let%27s-get-rid-of-the-unnecessary-modeltest-classes-%21:4890ed55-be28-4d4a-ba4c-7fd64834cda3#comment-492aedab-164c-421c-a1a8-4d854834cda3"&gt;building of model tests&lt;/a&gt;&lt;span style="font-family:arial;"&gt; as well as sharing a &lt;/span&gt;&lt;a style="font-family: arial;" href="http://debuggable.com/posts/fixturize-shell---generate-your-fixtures-automatically:48c12ad0-2350-4b5a-94d4-5f424834cda3"&gt;fixturize script&lt;/a&gt;&lt;span style="font-family:arial;"&gt; that automates the building of fixtures. &lt;/span&gt;&lt;span style="font-family:arial;"&gt;&lt;br /&gt;&lt;br /&gt;All great stuff!&lt;/span&gt;&lt;span style="font-family:arial;"&gt;&lt;br /&gt;If only I could get the simplest test up and running :(&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I have a table 'users' in both my 'default' and 'test' databases:&lt;br /&gt;&lt;pre name="code" class="Sql"&gt;&lt;br /&gt;DROP TABLE IF EXISTS `users`;&lt;br /&gt;CREATE TABLE `users` (&lt;br /&gt;`id` INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,&lt;br /&gt;`email` varchar(255) NOT NULL,&lt;br /&gt;`password` varchar(200) NOT NULL,&lt;br /&gt;`status` tinyint(1) NOT NULL default '1',&lt;br /&gt;`created` datetime NOT NULL,&lt;br /&gt;`modified` datetime NOT NULL,&lt;br /&gt;PRIMARY KEY  (`id`)&lt;br /&gt;) ENGINE=InnoDB  DEFAULT CHARSET=latin1;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;in my 'default' DB the table contains some sample records:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="sql"&gt;&lt;br /&gt;INSERT INTO `users`&lt;br /&gt;VALUES     ('1', 'andy@xyz.com', MD5('xyz'), '1', NOW(), NOW()),&lt;br /&gt;   ('2', 'joe@joe.com', MD5('abc'), '1', NOW(), NOW()),&lt;br /&gt;   ('3', 'badboy@badboy.com', MD5('123'), '0', NOW(), NOW());&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;br /&gt;My User model (user.php):&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&amp;lt?php&lt;br /&gt;class User extends AppModel {&lt;br /&gt; var $name = 'User';&lt;br /&gt; &lt;br /&gt; function enabledUsers($fields = null) {&lt;br /&gt;  $conditions = array(&lt;br /&gt;   $this-&gt;name . '.status' =&gt; 1&lt;br /&gt;  );&lt;br /&gt;  return $this-&gt;findAll($conditions, $fields);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I used Debuggable's Fixturize script to build my fixture (user_fixture.php):&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&amp;lt?php&lt;br /&gt;&lt;br /&gt;class UserFixture extends CakeTestFixture {&lt;br /&gt; var $name = 'User';&lt;br /&gt; var $records = array(&lt;br /&gt;  array(&lt;br /&gt;   'id' =&gt; '1',&lt;br /&gt;   'email' =&gt; 'andy@xyz.com',&lt;br /&gt;   'password' =&gt; 'd16fb36f0911f878998c136191af705e',&lt;br /&gt;   'status' =&gt; '1',&lt;br /&gt;   'created' =&gt; '2008-11-24 17:38:25',&lt;br /&gt;   'modified' =&gt; '2008-11-24 17:38:25',&lt;br /&gt;  ),&lt;br /&gt;  array(&lt;br /&gt;   'id' =&gt; '2',&lt;br /&gt;   'email' =&gt; 'joe@joe.com',&lt;br /&gt;   'password' =&gt; '900150983cd24fb0d6963f7d28e17f72',&lt;br /&gt;   'status' =&gt; '1',&lt;br /&gt;   'created' =&gt; '2008-11-24 17:38:25',&lt;br /&gt;   'modified' =&gt; '2008-11-24 17:38:25',&lt;br /&gt;  ),&lt;br /&gt;  array(&lt;br /&gt;   'id' =&gt; '3',&lt;br /&gt;   'email' =&gt; 'badboy@badboy.com',&lt;br /&gt;   'password' =&gt; '202cb962ac59075b964b07152d234b70',&lt;br /&gt;   'status' =&gt; '0',&lt;br /&gt;   'created' =&gt; '2008-11-24 17:38:25',&lt;br /&gt;   'modified' =&gt; '2008-11-24 17:38:25',&lt;br /&gt;  ),&lt;br /&gt; );&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here is the Unit Test itself (user.test.php):&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&amp;lt?php&lt;br /&gt;App::import('Model', 'User');&lt;br /&gt;&lt;br /&gt;class UserTestCase extends CakeTestCase {&lt;br /&gt; var $fixtures = array( 'user' );&lt;br /&gt; &lt;br /&gt; function setUp() {&lt;br /&gt;    $this-&gt;User = ClassRegistry::init('User');&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt; function testEnabledUsers() {&lt;br /&gt;  $this-&gt;loadFixtures('User');&lt;br /&gt;    &lt;br /&gt;  $result = $this-&gt;User-&gt;enabledUsers(array('id', 'email'));&lt;br /&gt;  $expected = array(&lt;br /&gt;   array('UserTest' =&gt; array( 'id' =&gt; 1, 'email' =&gt; 'andy@xyz.com' )),&lt;br /&gt;   array('UserTest' =&gt; array( 'id' =&gt; 2, 'email' =&gt; 'joe@joe.com' ))&lt;br /&gt;  );&lt;br /&gt;  $this-&gt;assertEqual($result, $expected);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And here are the errors I get when I run the test:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;ul class="tests"&gt;&lt;li class="fail"&gt; &lt;span&gt;Error&lt;/span&gt;&lt;div class="msg"&gt;Unexpected PHP error [Undefined property: UserFixture::$fields] severity [E_NOTICE] in [C:\xampp\htdocs\cake\cake\tests\lib\cake_test_fixture.php line 158]&lt;/div&gt; &lt;div&gt;C:\xampp\htdocs\cake\reuser\tests\cases\models\\user.test.php -&gt; UserTestCase -&gt; start&lt;/div&gt; &lt;/li&gt;&lt;li class="fail"&gt; &lt;span&gt;Error&lt;/span&gt;&lt;div class="msg"&gt;Unexpected PHP error [mysqli_query() [&lt;a href="http://www.blogger.com/%27http://php.net/function.mysqli-query%27"&gt;function.mysqli-query&lt;/a&gt;]: Empty query] severity [E_WARNING] in [C:\xampp\htdocs\cake\cake\libs\model\datasources\dbo\dbo_mysqli.php line 146]&lt;/div&gt; &lt;div&gt;C:\xampp\htdocs\cake\reuser\tests\cases\models\\user.test.php -&gt; UserTestCase -&gt; start&lt;/div&gt; &lt;/li&gt;&lt;li class="fail"&gt; &lt;span&gt;Failed&lt;/span&gt;&lt;div class="msg"&gt;Equal expectation fails with member [0] as key list [User] does not match key list [UserTest] at [C:\xampp\htdocs\cake\reuser\tests\cases\models\user.test.php line 19]&lt;/div&gt; &lt;div&gt;C:\xampp\htdocs\cake\reuser\tests\cases\models\\user.test.php -&gt; UserTestCase -&gt; testEnabledUsers&lt;/div&gt; &lt;/li&gt;&lt;li class="fail"&gt; &lt;span&gt;Error&lt;/span&gt;&lt;div class="msg"&gt;Unexpected PHP error [Undefined property: UserFixture::$fields] severity [E_NOTICE] in [C:\xampp\htdocs\cake\cake\tests\lib\cake_test_fixture.php line 158]&lt;/div&gt; &lt;div&gt;C:\xampp\htdocs\cake\reuser\tests\cases\models\\user.test.php -&gt; UserTestCase -&gt; end&lt;/div&gt; &lt;/li&gt;&lt;li class="fail"&gt; &lt;span&gt;Error&lt;/span&gt;&lt;div class="msg"&gt;Unexpected PHP error [mysqli_query() [&lt;a href="http://www.blogger.com/%27http://php.net/function.mysqli-query%27"&gt;function.mysqli-query&lt;/a&gt;]: Empty query] severity [E_WARNING] in [C:\xampp\htdocs\cake\cake\libs\model\datasources\dbo\dbo_mysqli.php line 146]&lt;/div&gt; &lt;div&gt;C:\xampp\htdocs\cake\reuser\tests\cases\models\\user.test.php -&gt; UserTestCase -&gt; end&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family:arial;"&gt;Wow! :( &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;I've had a poke around in some of the core files putting debug statements all over to try and understand why this doesn't work. But I guess I've come the full circle now back to the "Convention over Configuration". This is the most basic of Unit Tests on a simple findAll function in the most basic of models. The reason this is not working has to be that I'm breaking the convention somewhere. Maybe in file naming or in the way I'm including the fixture?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;I'd be very grateful if someone could get me out of this mess by pointing out what I've got wrong.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Thanks,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Andy&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/689898573354229302-2921944942905866586?l=oneyeareatingcake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneyeareatingcake.blogspot.com/feeds/2921944942905866586/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=689898573354229302&amp;postID=2921944942905866586' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/689898573354229302/posts/default/2921944942905866586'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/689898573354229302/posts/default/2921944942905866586'/><link rel='alternate' type='text/html' href='http://oneyeareatingcake.blogspot.com/2008/11/cakephp-unit-test-model-woes.html' title='CakePHP Unit Test Model Woes :('/><author><name>Zoyen</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-689898573354229302.post-8348156104386336698</id><published>2008-11-25T15:36:00.000Z</published><updated>2008-11-25T15:42:51.560Z</updated><title type='text'>Here we go...</title><content type='html'>As a part time computer science student I now have just under 12 months to submit my final year project.&lt;br /&gt;&lt;br /&gt;I'll be following an agile, Scrum based, test-driven development methodology to build an amazing web application!&lt;br /&gt;&lt;br /&gt;To help me on my way I've reviewed and then selected a PHP framework:&lt;br /&gt;&lt;br /&gt;My choice &lt;a href="http://cakephp.org/"&gt;CakePHP&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Wish me luck :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/689898573354229302-8348156104386336698?l=oneyeareatingcake.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneyeareatingcake.blogspot.com/feeds/8348156104386336698/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=689898573354229302&amp;postID=8348156104386336698' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/689898573354229302/posts/default/8348156104386336698'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/689898573354229302/posts/default/8348156104386336698'/><link rel='alternate' type='text/html' href='http://oneyeareatingcake.blogspot.com/2008/11/here-we-go.html' title='Here we go...'/><author><name>Zoyen</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
