<?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>naji-dev &#187; PHP</title>
	<atom:link href="http://www.naji-dev.de/category/webentwicklung/php-webentwicklung/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.naji-dev.de</link>
	<description>Einfach genial...</description>
	<lastBuildDate>Mon, 08 Mar 2010 22:34:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Database-Reload in Symfony-Tests</title>
		<link>http://www.naji-dev.de/2010/03/08/database-reload-in-symfony-tests/</link>
		<comments>http://www.naji-dev.de/2010/03/08/database-reload-in-symfony-tests/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 19:39:16 +0000</pubDate>
		<dc:creator>Naji</dc:creator>
				<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Webentwicklung]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://www.naji-dev.de/?p=267</guid>
		<description><![CDATA[Everytime i write unit or functional tests in symfony, i have following problem:
Sometimes my tests do not run deterministically because previous ran tests created data, which intefere with following tests. For example (a simple, not really smart one) think of a system which knows one (and only one) user. For my DAL i would test [...]]]></description>
			<content:encoded><![CDATA[<p>Everytime i write unit or functional tests in symfony, i have following problem:</p>
<p>Sometimes my tests do not run deterministically because previous ran tests created data, which intefere with following tests. For example (a simple, not really smart one) think of a system which knows one (and only one) user. For my DAL i would test a method like &#8220;createUser&#8221; or something. Later on i would create a functional test for a registration form. Now the correctness of the tests depend on the sequence, i run the tests. But this should not be this way! Every time i run a test, i have to know the data before i run a part of my software and i have to know how my software manipulates the data (speaking of the date after running my software). The only way i knew to ensure this state, was to run build-all-reload (as in Symfony 1.2 with Doctrine as ORM) to get a fresh database with the predefined fixtures.</p>
<p>Any software you develop will enlarge, and so the tests will, too. After a time you will get to the point, where you can not run a build-all-reload after each test for some reasons. So how about clearing the database before a test runs like the following?</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$browser</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ndTestFunctionalDoctrine<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> sfBrowser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span>
  <span style="color: #004000;">reloadData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>
  <span style="color: #004000;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1 - Make a test on a clean database with defined fixtures only'</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This is what <a href="http://www.naji-dev.de/pool/symfony/ndTestFunctionalDoctrine.class.phps">ndTestFunctionalDoctrine</a> offers to test-writing symfony-developers. The only thing you have to handle is: Run reloadData() in your code each time you run a test, which does not depend on the test direct before the current.</p>
<p>Like for functional tests i have a small helper, which can be put to the end of <strong>test/bootstrap/unit.php</strong>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">new</span> sfDatabaseManager<span style="color: #009900;">&#40;</span><span style="color: #000088;">$configuration</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// helper</span>
<span style="color: #000000; font-weight: bold;">function</span> reloadData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// try to drop the database (an exception is thrown,</span>
  <span style="color: #666666; font-style: italic;">// when the database does not exist)</span>
  try
  <span style="color: #009900;">&#123;</span>
    Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">dropDatabases</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// create database</span>
  Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">createDatabases</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// create tables</span>
  Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">createTablesFromModels</span><span style="color: #009900;">&#40;</span>sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_lib_dir'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/model'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// load fixtures</span>
  Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">loadData</span><span style="color: #009900;">&#40;</span>sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_data_dir'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/fixtures'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Analog to this, a version for propel could be build if doctrine is not the ORM of your choice. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.naji-dev.de/2010/03/08/database-reload-in-symfony-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Database-Reload in Symfony-Tests</title>
		<link>http://www.naji-dev.de/2010/03/08/database-reload-in-symfony-tests/</link>
		<comments>http://www.naji-dev.de/2010/03/08/database-reload-in-symfony-tests/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 19:39:16 +0000</pubDate>
		<dc:creator>Naji</dc:creator>
				<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Webentwicklung]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://www.naji-dev.de/?p=267</guid>
		<description><![CDATA[Everytime i write unit or functional tests in symfony, i have following problem:
Sometimes my tests do not run deterministically because previous ran tests created data, which intefere with following tests. For example (a simple, not really smart one) think of a system which knows one (and only one) user. For my DAL i would test [...]]]></description>
			<content:encoded><![CDATA[<p>Everytime i write unit or functional tests in symfony, i have following problem:</p>
<p>Sometimes my tests do not run deterministically because previous ran tests created data, which intefere with following tests. For example (a simple, not really smart one) think of a system which knows one (and only one) user. For my DAL i would test a method like &#8220;createUser&#8221; or something. Later on i would create a functional test for a registration form. Now the correctness of the tests depend on the sequence, i run the tests. But this should not be this way! Every time i run a test, i have to know the data before i run a part of my software and i have to know how my software manipulates the data (speaking of the date after running my software). The only way i knew to ensure this state, was to run build-all-reload (as in Symfony 1.2 with Doctrine as ORM) to get a fresh database with the predefined fixtures.</p>
<p>Any software you develop will enlarge, and so the tests will, too. After a time you will get to the point, where you can not run a build-all-reload after each test for some reasons. So how about clearing the database before a test runs like the following?</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$browser</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ndTestFunctionalDoctrine<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> sfBrowser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span>
  <span style="color: #004000;">reloadData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>
  <span style="color: #004000;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1 - Make a test on a clean database with defined fixtures only'</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This is what <a href="http://www.naji-dev.de/pool/symfony/ndTestFunctionalDoctrine.class.phps">ndTestFunctionalDoctrine</a> offers to test-writing symfony-developers. The only thing you have to handle is: Run reloadData() in your code each time you run a test, which does not depend on the test direct before the current.</p>
<p>Like for functional tests i have a small helper, which can be put to the end of <strong>test/bootstrap/unit.php</strong>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">new</span> sfDatabaseManager<span style="color: #009900;">&#40;</span><span style="color: #000088;">$configuration</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// helper</span>
<span style="color: #000000; font-weight: bold;">function</span> reloadData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// try to drop the database (an exception is thrown,</span>
  <span style="color: #666666; font-style: italic;">// when the database does not exist)</span>
  try
  <span style="color: #009900;">&#123;</span>
    Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">dropDatabases</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// create database</span>
  Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">createDatabases</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// create tables</span>
  Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">createTablesFromModels</span><span style="color: #009900;">&#40;</span>sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_lib_dir'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/model'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// load fixtures</span>
  Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">loadData</span><span style="color: #009900;">&#40;</span>sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_data_dir'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/fixtures'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Analog to this, a version for propel could be build if doctrine is not the ORM of your choice. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.naji-dev.de/2010/03/08/database-reload-in-symfony-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Database-Reload in Symfony-Tests</title>
		<link>http://www.naji-dev.de/2010/03/08/database-reload-in-symfony-tests/</link>
		<comments>http://www.naji-dev.de/2010/03/08/database-reload-in-symfony-tests/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 19:39:16 +0000</pubDate>
		<dc:creator>Naji</dc:creator>
				<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Webentwicklung]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://www.naji-dev.de/?p=267</guid>
		<description><![CDATA[Everytime i write unit or functional tests in symfony, i have following problem:
Sometimes my tests do not run deterministically because previous ran tests created data, which intefere with following tests. For example (a simple, not really smart one) think of a system which knows one (and only one) user. For my DAL i would test [...]]]></description>
			<content:encoded><![CDATA[<p>Everytime i write unit or functional tests in symfony, i have following problem:</p>
<p>Sometimes my tests do not run deterministically because previous ran tests created data, which intefere with following tests. For example (a simple, not really smart one) think of a system which knows one (and only one) user. For my DAL i would test a method like &#8220;createUser&#8221; or something. Later on i would create a functional test for a registration form. Now the correctness of the tests depend on the sequence, i run the tests. But this should not be this way! Every time i run a test, i have to know the data before i run a part of my software and i have to know how my software manipulates the data (speaking of the date after running my software). The only way i knew to ensure this state, was to run build-all-reload (as in Symfony 1.2 with Doctrine as ORM) to get a fresh database with the predefined fixtures.</p>
<p>Any software you develop will enlarge, and so the tests will, too. After a time you will get to the point, where you can not run a build-all-reload after each test for some reasons. So how about clearing the database before a test runs like the following?</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$browser</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ndTestFunctionalDoctrine<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> sfBrowser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$browser</span><span style="color: #339933;">-&gt;</span>
  <span style="color: #004000;">reloadData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>
  <span style="color: #004000;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1 - Make a test on a clean database with defined fixtures only'</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This is what <a href="http://www.naji-dev.de/pool/symfony/ndTestFunctionalDoctrine.class.phps">ndTestFunctionalDoctrine</a> offers to test-writing symfony-developers. The only thing you have to handle is: Run reloadData() in your code each time you run a test, which does not depend on the test direct before the current.</p>
<p>Like for functional tests i have a small helper, which can be put to the end of <strong>test/bootstrap/unit.php</strong>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">new</span> sfDatabaseManager<span style="color: #009900;">&#40;</span><span style="color: #000088;">$configuration</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// helper</span>
<span style="color: #000000; font-weight: bold;">function</span> reloadData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// try to drop the database (an exception is thrown,</span>
  <span style="color: #666666; font-style: italic;">// when the database does not exist)</span>
  try
  <span style="color: #009900;">&#123;</span>
    Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">dropDatabases</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// create database</span>
  Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">createDatabases</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// create tables</span>
  Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">createTablesFromModels</span><span style="color: #009900;">&#40;</span>sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_lib_dir'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/model'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// load fixtures</span>
  Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">loadData</span><span style="color: #009900;">&#40;</span>sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_data_dir'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/fixtures'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Analog to this, a version for propel could be build if doctrine is not the ORM of your choice. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.naji-dev.de/2010/03/08/database-reload-in-symfony-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	<img style='margin:0;padding:0;border:0;' width='1px' height='1px' src="http://www.naji-dev.de/wp-content/plugins/mystat/mystat.php?act=time_load&id=109726&rnd=313360141" /></channel>
</rss>
