<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Zendcasts Forum / ZC39 – Writing Doctrine Unit Tests with Zend_Test]]></title>
		<link>http://www.zendcasts.com/forum/viewtopic.php?id=106</link>
		<description><![CDATA[The most recent posts in ZC39 – Writing Doctrine Unit Tests with Zend_Test.]]></description>
		<lastBuildDate>Sun, 21 Nov 2010 12:55:20 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Re: ZC39 – Writing Doctrine Unit Tests with Zend_Test]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=1186#p1186</link>
			<description><![CDATA[<p>@Wallgate<br />a better solution for this is to create a loader class where u do the<br />Zend_Application bootstrapping.<br />Then u can create a testhelper class for unittests witch extends PHPUnit_Framework_TestCase&#160; and another testhelper<br />for controllertests&#160; witch extends Zend_Test_PHPUnit_ControllerTestCase.<br />In your setUp method just use something like this.<br /></p><div class="codebox"><pre><code>        $loader = new Loader();
        $this-&gt;application = $loader-&gt;loadApplication();
        $this-&gt;bootstrap = $loader-&gt;getBootstrap();</code></pre></div><p>Best regards<br />Christian</p>]]></description>
			<author><![CDATA[dummy@example.com (boarder212)]]></author>
			<pubDate>Sun, 21 Nov 2010 12:55:20 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=1186#p1186</guid>
		</item>
		<item>
			<title><![CDATA[Re: ZC39 – Writing Doctrine Unit Tests with Zend_Test]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=1166#p1166</link>
			<description><![CDATA[<p>I think I found out what&#039;s wrong with my source code. Everything works fine if your testcases extend ControllerTestCase class. But if you try to extend PHPUnit_Framework_TestCase it ends up crushing since you&#039;ve got no Zend_Application instantiated and therefore no autoloader initialized (apart from the Doctrine&#039;s one). Thanks for pointing me at a bug like this.</p><p>Actually there&#039;s a solution shown in the last of Zend Casts (which deals with creating two instances of Zend_Application). Gotta stick to that until there is a better way doing it.</p>]]></description>
			<author><![CDATA[dummy@example.com (Wallgate)]]></author>
			<pubDate>Fri, 12 Nov 2010 09:17:25 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=1166#p1166</guid>
		</item>
		<item>
			<title><![CDATA[Re: ZC39 – Writing Doctrine Unit Tests with Zend_Test]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=1162#p1162</link>
			<description><![CDATA[<p>No, just from Zend Studio.</p>]]></description>
			<author><![CDATA[dummy@example.com (StefC30)]]></author>
			<pubDate>Thu, 11 Nov 2010 22:42:51 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=1162#p1162</guid>
		</item>
		<item>
			<title><![CDATA[Re: ZC39 – Writing Doctrine Unit Tests with Zend_Test]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=1161#p1161</link>
			<description><![CDATA[<p>Sorry, I never worked with Zend Studio. But technically there are all the neccesary require_once statements if you of course put your classes in right places. Have you tried running your tests from the command line?</p>]]></description>
			<author><![CDATA[dummy@example.com (Wallgate)]]></author>
			<pubDate>Thu, 11 Nov 2010 16:41:02 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=1161#p1161</guid>
		</item>
		<item>
			<title><![CDATA[Re: ZC39 – Writing Doctrine Unit Tests with Zend_Test]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=1159#p1159</link>
			<description><![CDATA[<p>Hello,</p><p>This source code doesn&#039;t work.</p><p>When I set up a new Zend Framework project from these sources and run PHPUnit test with Zend Studio, I get several errors :</p><p>First, the Zend_Test_PHPUnit_ControllerTestCase class is not known : “Fatal error: Class ‘Zend_Test_PHPUnit_ControllerTestCase’ not found in D:\…\tests\application\models\UserTest.php”.<br />Ok, I add a require_once ‘Zend/Test/PHPUnit/ControllerTestCase.php’; in my UserTest.php file.</p><p>So, I no longer have this error, but a new error for the model on $u = new User(); : “Class ‘User’ not found in D:\…\tests\application\models\UserTest.php”.</p><p>I can still not add a require_once for each class of my project.<br />The bootstrap does not even use.</p><p>Do you have any idea of the origin of this problem ?<br />Is this related to the use of Zend Studio ?<br />Is there anything else to add or modify to run this project ?</p><p>Thank you in advance for your help.</p><p>Best regards.</p><p>Stéphan.</p>]]></description>
			<author><![CDATA[dummy@example.com (StefC30)]]></author>
			<pubDate>Thu, 11 Nov 2010 09:34:05 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=1159#p1159</guid>
		</item>
		<item>
			<title><![CDATA[Re: ZC39 – Writing Doctrine Unit Tests with Zend_Test]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=1156#p1156</link>
			<description><![CDATA[<p>Hi.</p><p>I&#039;m trying to integrate ZF and Doctrine in a testable way, and I have some trouble which comes back to what Sebastian Montero wrote. What I fail to see is a way of bootstrapping my test suite so it could be used for testing both controllers and models.</p><p>In this screencast Zend_Application is instantiated in /tests/application/bootstrap.php so the CLI code runs only once. Yet in ZC-25 which covers controller testing it&#039;s instantiated in setUp method of a ControllerTestCase class.</p><p>The problem is that if you create an instance of Zend_Application in bootstrap.php and then you try to test your controllers it&#039;s all messed up. Though everything works fine in browser, running $this-&gt;dispatch(&#039;/uri&#039;) ends up with &quot;No default module&quot; error, and when you fix that it cannot find your controller plugins and then it has trouble finding layout resource and so on and so forth. So you basically have to bootstrap your application twice which is no good.</p><p>On the other hand, you can move everything into your setUp method. But then you&#039;ll have &#039;build-all-reload&#039; CLI command running for every single test method which also is a bad thing.</p><p>What I do is I actually run &#039;build-all-reload&#039; before instantiating the application:<br /></p><div class="codebox"><pre class="vscroll"><code>&lt;?php

define(&#039;APPLICATION_PATH&#039;, realpath(dirname(__FILE__) . &#039;/../../application&#039;));

define(&#039;APPLICATION_ENV&#039;, &#039;testing&#039;);

set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . &#039;/../library&#039;),
    realpath(APPLICATION_PATH . &#039;/models&#039;),
    get_include_path(),
)));


require_once &#039;Zend/Application.php&#039;;
require_once &#039;Zend/Config/Ini.php&#039;;
require_once &#039;Doctrine.php&#039;;
require_once &#039;ControllerTestCase.php&#039;;


$config = new Zend_Config_Ini(APPLICATION_PATH.&#039;/configs/application.ini&#039;, APPLICATION_ENV);
$dbConfig       = $config-&gt;db-&gt;toArray();
$doctrineConfig = $config-&gt;doctrine-&gt;toArray();

spl_autoload_register(array(&#039;Doctrine&#039;, &#039;autoload&#039;));

$manager = Doctrine_Manager::getInstance();
$manager-&gt;setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_AGGRESSIVE);
$manager-&gt;setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL);
$manager-&gt;setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL);
$manager-&gt;setAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER, true);

$dsn = sprintf(&quot;mysql://%s:%s@%s/%s&quot;,
    $dbConfig[&#039;username&#039;],
    $dbConfig[&#039;password&#039;],
    $dbConfig[&#039;host&#039;],
    $dbConfig[&#039;dbname&#039;]
);

$connection = $manager-&gt;connection($dsn);
$connection-&gt;setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true);

$cli = new Doctrine_Cli($doctrineConfig);
@$cli-&gt;run(array(&#039;Doctrine&#039;, &#039;build-all-reload&#039;, &#039;force&#039;));</code></pre></div><p>And then I create an instance of Zend_Application normally:<br /></p><div class="codebox"><pre><code>&lt;?php

require_once &#039;Zend/Test/PHPUnit/ControllerTestCase.php&#039;;

abstract class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
    protected $application = NULL;

    public function setUp()
    {
        $this-&gt;bootstrap = array($this, &#039;appBootstrap&#039;);
        parent::setUp();
    }

    public function appBootstrap()
    {
        $this-&gt;application = new Zend_Application(
            APPLICATION_ENV,
            APPLICATION_PATH . &#039;/configs/application.ini&#039;
        );
        $this-&gt;application-&gt;bootstrap();
    }
}</code></pre></div><p>I wonder what you guys think about it and if there&#039;s a better way doing this.</p>]]></description>
			<author><![CDATA[dummy@example.com (Wallgate)]]></author>
			<pubDate>Wed, 10 Nov 2010 05:14:42 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=1156#p1156</guid>
		</item>
		<item>
			<title><![CDATA[Re: ZC39 – Writing Doctrine Unit Tests with Zend_Test]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=803#p803</link>
			<description><![CDATA[<p>ridiculous indeed...</p>]]></description>
			<author><![CDATA[dummy@example.com (Jon Lebensold)]]></author>
			<pubDate>Sat, 17 Apr 2010 21:26:01 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=803#p803</guid>
		</item>
		<item>
			<title><![CDATA[Re: ZC39 – Writing Doctrine Unit Tests with Zend_Test]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=801#p801</link>
			<description><![CDATA[<p>you&#039;re joking wright? and if not, do you know if there are ways to fix this besides renaming the models? tnx for ur time on this and your excellent screencasts <img src="http://www.zendcasts.com/forum/img/smilies/wink.png" width="15" height="15" alt="wink" /></p><p>It seems like this is the issue, I&#039;ve created another table, generated the model for it and tested it successfully.<br />by the way, the new class name is: &#039;<strong>P</strong>roject&#039;</p>]]></description>
			<author><![CDATA[dummy@example.com (yusufdestina)]]></author>
			<pubDate>Fri, 16 Apr 2010 17:11:59 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=801#p801</guid>
		</item>
		<item>
			<title><![CDATA[Re: ZC39 – Writing Doctrine Unit Tests with Zend_Test]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=800#p800</link>
			<description><![CDATA[<p>hey Yusuf,</p><p>I&#039;ve read several reports a silly bug where models that start with letters before &quot;D&quot; aren&#039;t loaded... I&#039;m not sure if that&#039;s your issue though...</p>]]></description>
			<author><![CDATA[dummy@example.com (Jon Lebensold)]]></author>
			<pubDate>Fri, 16 Apr 2010 15:36:24 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=800#p800</guid>
		</item>
		<item>
			<title><![CDATA[Re: ZC39 – Writing Doctrine Unit Tests with Zend_Test]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=799#p799</link>
			<description><![CDATA[<p>in one of your first videos about zf and doctrine you had a models folder and then the models files and a Base directory with the generated classes for the models.</p><p>in the application.ini you defined some settings:<br /></p><div class="codebox"><pre><code>doctrine.generate_models_options.pearStyle = true
doctrine.generate_models_options.generateTableClasses = false
doctrine.generate_models_options.generateBaseClasses = true
doctrine.generate_models_options.baseClassPrefix = &quot;Base_&quot;
doctrine.generate_models_options.baseClassesDirectory =
doctrine.generate_models_options.classPrefixFiles = false
doctrine.generate_models_options.classPrefix = &quot;Model_&quot;</code></pre></div><p>If I try to integrate phpunit testing with the setup explained in previous tutorials and the one you provide in this video<br />example:<br /></p><div class="codebox"><pre><code>class ArticleTest extends Zend_Test_PHPUnit_ControllerTestCase {
.
.
.
public function testFindAll() {
        $article = new Model_Article();
        $obj = $article-&gt;findAll($this-&gt;lang);
        $this-&gt;assertTrue( count($obj) &gt; 0);
    }</code></pre></div><p>I get this error:<br /></p><div class="codebox"><pre><code>PHPUnit 3.4.9 by Sebastian Bergmann.

PHP Fatal error:  Class &#039;Model_Article&#039; not found in C:\server\www\zend_site\t
ests\application\models\ArticleTest.php on line 23</code></pre></div><p>What am I doing wrong?</p>]]></description>
			<author><![CDATA[dummy@example.com (yusufdestina)]]></author>
			<pubDate>Fri, 16 Apr 2010 13:54:57 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=799#p799</guid>
		</item>
		<item>
			<title><![CDATA[Re: ZC39 – Writing Doctrine Unit Tests with Zend_Test]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=664#p664</link>
			<description><![CDATA[<p>hey boodito, if its a memory issue, try bumping up your limit in the php.ini file!</p>]]></description>
			<author><![CDATA[dummy@example.com (Jon Lebensold)]]></author>
			<pubDate>Thu, 18 Feb 2010 23:48:22 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=664#p664</guid>
		</item>
		<item>
			<title><![CDATA[Re: ZC39 – Writing Doctrine Unit Tests with Zend_Test]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=658#p658</link>
			<description><![CDATA[<p>Hey,<br />When I run the tests, I get the following error:</p><p>PHPUnit 3.4.8 by Sebastian Bergmann.</p><p>.</p><p>Time: 46 seconds, Memory: 32.00Mb</p><p>OK (1 test, 6 assertions)</p><p>Generating code coverage report, this may take a moment.<br />Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 35 bytes) in /usr/share/php/PHPUnit/Util/Report/Node/File.php on line 644</p><p>Call Stack:<br />&#160; &#160; 0.0006&#160; &#160; &#160; 62840&#160; &#160;1. {main}() /usr/bin/phpunit:0<br />&#160; &#160; 0.1008&#160; &#160; 4498284&#160; &#160;2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:54<br />&#160; &#160; 0.1008&#160; &#160; 4499016&#160; &#160;3. PHPUnit_TextUI_Command-&gt;run() /usr/share/php/PHPUnit/TextUI/Command.php:146<br />&#160; &#160;42.4558&#160; &#160;21921616&#160; &#160;4. PHPUnit_TextUI_TestRunner-&gt;doRun() /usr/share/php/PHPUnit/TextUI/Command.php:213<br />&#160; &#160;46.2234&#160; &#160;30628640&#160; &#160;5. PHPUnit_Util_Report::render() /usr/share/php/PHPUnit/TextUI/TestRunner.php:478<br />&#160; &#160;46.2948&#160; &#160;31323220&#160; &#160;6. PHPUnit_Util_Report::addItems() /usr/share/php/PHPUnit/Util/Report.php:118<br />&#160; &#160;46.2986&#160; &#160;31358240&#160; &#160;7. PHPUnit_Util_Report::addItems() /usr/share/php/PHPUnit/Util/Report.php:154<br />&#160; &#160;46.3014&#160; &#160;31385764&#160; &#160;8. PHPUnit_Util_Report::addItems() /usr/share/php/PHPUnit/Util/Report.php:154<br />&#160; &#160;46.5328&#160; &#160;33319972&#160; &#160;9. PHPUnit_Util_Report_Node_Directory-&gt;addFile() /usr/share/php/PHPUnit/Util/Report.php:146<br />&#160; &#160;46.5328&#160; &#160;33321944&#160; 10. PHPUnit_Util_Report_Node_File-&gt;__construct() /usr/share/php/PHPUnit/Util/Report/Node/Directory.php:147<br />&#160; &#160;46.5329&#160; &#160;33322732&#160; 11. PHPUnit_Util_Report_Node_File-&gt;loadFile() /usr/share/php/PHPUnit/Util/Report/Node/File.php:168<br />&#160; &#160;46.5332&#160; &#160;33365436&#160; 12. token_get_all() /usr/share/php/PHPUnit/Util/Report/Node/File.php:644</p><br /><p>Any idea??</p>]]></description>
			<author><![CDATA[dummy@example.com (boodito)]]></author>
			<pubDate>Thu, 18 Feb 2010 11:05:16 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=658#p658</guid>
		</item>
		<item>
			<title><![CDATA[Re: ZC39 – Writing Doctrine Unit Tests with Zend_Test]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=569#p569</link>
			<description><![CDATA[<p>Thank you for your reply.</p><p>And how about using doctrine mock drivers or sqlite memory database? to solve that problem.</p><p>Thanks!</p>]]></description>
			<author><![CDATA[dummy@example.com (Sebastian Montero)]]></author>
			<pubDate>Fri, 22 Jan 2010 20:43:35 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=569#p569</guid>
		</item>
		<item>
			<title><![CDATA[Re: ZC39 – Writing Doctrine Unit Tests with Zend_Test]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=568#p568</link>
			<description><![CDATA[<p>Hey Sebastian,</p><p>you can certainly do it in that manner, however as you start writing hundreds of tests,&#160; you might find nuking your db every time to slow you down. To do it though, you could just modify your startUp and tearDown methods for the model tests.</p>]]></description>
			<author><![CDATA[dummy@example.com (Jon Lebensold)]]></author>
			<pubDate>Fri, 22 Jan 2010 18:25:14 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=568#p568</guid>
		</item>
		<item>
			<title><![CDATA[Re: ZC39 – Writing Doctrine Unit Tests with Zend_Test]]></title>
			<link>http://www.zendcasts.com/forum/viewtopic.php?pid=565#p565</link>
			<description><![CDATA[<p>Hi, in this example the database is recreated at the begining of the tests, shouldn&#039;t it be recreated for each test? so that tests aren&#039;t affected by previous ones.</p><p>thanks</p>]]></description>
			<author><![CDATA[dummy@example.com (Sebastian Montero)]]></author>
			<pubDate>Thu, 21 Jan 2010 01:16:34 +0000</pubDate>
			<guid>http://www.zendcasts.com/forum/viewtopic.php?pid=565#p565</guid>
		</item>
	</channel>
</rss>

