<?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>webbricks &#187; AppModel</title>
	<atom:link href="http://blog.grzegorzpawlik.com/tag/appmodel/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.grzegorzpawlik.com</link>
	<description>Doświadczenie, to coś, co zdobywamy tuż po chwili w której było nam potrzebne ...</description>
	<lastBuildDate>Tue, 07 Feb 2012 10:09:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Testowanie AppModel</title>
		<link>http://blog.grzegorzpawlik.com/2009/12/testowanie-appmodel/</link>
		<comments>http://blog.grzegorzpawlik.com/2009/12/testowanie-appmodel/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 13:41:44 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[AppModel]]></category>

		<guid isPermaLink="false">http://blog.grzegorzpawlik.com/?p=583</guid>
		<description><![CDATA[Mam kilka metod w AppModel, potrzebowałem pokryć je testami. Różni się to nieco od testowania zwykłych modeli. Najpierw analogicznie do innych testów stworzyłem app_model.test.php: App::import("model", "AppModel"); class AppModelTest extends CakeTestCase { var $name = "AppModel"; function start() { parent::start(); $this->AppModel &#8230; <a href="http://blog.grzegorzpawlik.com/2009/12/testowanie-appmodel/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Mam kilka metod w AppModel, potrzebowałem pokryć je testami. Różni się to nieco od testowania zwykłych modeli.</p>
<p>Najpierw analogicznie do innych testów stworzyłem app_model.test.php:</p>
<pre>
App::import("model", "AppModel");

class AppModelTest extends CakeTestCase {
   var $name = "AppModel";

   function start() {
      parent::start();
      $this->AppModel = ClassRegistry::init("AppModel");
   }
</pre>
<p>Problem w tym, że dostaniesz wtedy Missing Database (&#8220;app_models&#8221;).</p>
<p>Nie możesz w AppModel ustawić atrybutu useTable na false, bo wszystkie modele go dziedziczą. Tzn. jest to możliwe, ale w takim wypadku we wszystkich modelach, które jednak są połączone z tabelami w bazie należałoby explicite podać $useTable = &#8216;nazwa_tabeli&#8217;</p>
<p>Odeszlibyśmy wtedy od <a href="http://en.wikipedia.org/wiki/Convention_over_configuration">Convention over Configuration</a>, poza tym za dużo roboty. Ale można zastosować trick. Stworzyć klasę, która &#8220;zasłoni&#8221; naszą AppModel, ale będzie działać tak samo (nazywa się to <del datetime="2009-12-16T13:31:41+00:00">Mock Classes, albo</del> <a href="http://en.wikipedia.org/wiki/Mock_object">Mock Objects</a><del datetime="2009-12-16T13:31:41+00:00">, albo i tak, i tak</del> na pewno ;)):</p>
<pre>
App::import("model", "AppModel");

class DummyAppModel extends AppModel {
  var $useTable = false;
}

class AppModelTest extends CakeTestCase {
   var $name = "AppModel";

   function start() {
      parent::start();
      $this->AppModel = ClassRegistry::init("DummyAppModel");
   }
</pre>
<p>I będzie działać :)</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.grzegorzpawlik.com/2009/12/testowanie-appmodel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

