<?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; Symfony</title>
	<atom:link href="http://www.naji-dev.de/tag/symfony/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>Multiple Symfony Installationen</title>
		<link>http://www.naji-dev.de/2009/12/27/multiple-symfony-installationen/</link>
		<comments>http://www.naji-dev.de/2009/12/27/multiple-symfony-installationen/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 18:51:29 +0000</pubDate>
		<dc:creator>Naji</dc:creator>
				<category><![CDATA[Webentwicklung]]></category>
		<category><![CDATA[Multiple Installation]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.naji-dev.de/?p=245</guid>
		<description><![CDATA[Da die Installation mit Hilfe von PEAR nur eine einzige Version von Symfony zulässt, wählen wir den Weg über das svn-repository (natürlich könnte man an dieser Stelle auch die tar.gz Archive von der Seite nehmen).
Wir legen also einen Ordner symfony unter /usr/share/php an und checken die einzelnen Versionen von Symfony aus. Für meine Projekte benötige [...]]]></description>
			<content:encoded><![CDATA[<p>Da die Installation mit Hilfe von PEAR nur eine einzige Version von Symfony zulässt, wählen wir den Weg über das svn-repository (natürlich könnte man an dieser Stelle auch die tar.gz Archive von der Seite nehmen).</p>
<p>Wir legen also einen Ordner <strong>symfony</strong> unter <strong>/usr/share/php</strong> an und checken die einzelnen Versionen von Symfony aus. Für meine Projekte benötige ich <strong>1.2</strong>, <strong>1.3</strong> und <strong>1.4</strong>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>php
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> symfony
<span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> http:<span style="color: #000000; font-weight: bold;">//</span>svn.symfony-project.com<span style="color: #000000; font-weight: bold;">/</span>branches<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.2</span><span style="color: #000000; font-weight: bold;">/</span> symfony12
<span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> http:<span style="color: #000000; font-weight: bold;">//</span>svn.symfony-project.com<span style="color: #000000; font-weight: bold;">/</span>branches<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.3</span><span style="color: #000000; font-weight: bold;">/</span> symfony13
<span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> http:<span style="color: #000000; font-weight: bold;">//</span>svn.symfony-project.com<span style="color: #000000; font-weight: bold;">/</span>branches<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.4</span><span style="color: #000000; font-weight: bold;">/</span> symfony14</pre></td></tr></table></div>

<p>Jetzt <strong>könnten</strong> wir mit</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>symfony <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>php<span style="color: #000000; font-weight: bold;">/</span>symfony<span style="color: #000000; font-weight: bold;">/</span>symfony14<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>symfony</pre></td></tr></table></div>

<p>fest auf die neuste Version von Symfony linken. Allerdings ist das nicht die beste Variante, da man eventuell in einem Symfony-Projekt einer anderen Version arbeitet &#8211; was uns zu der Umständlichkeit von <strong>./symfony</strong> führt. Für mich persönlich ist das nicht akzeptabel, weil ich das einfach immer falsch mache.</p>
<p>Bei dem Anlegen eines Symfony-Projekts wird ein kleines php-Script angelegt, das die in <strong>config/ProjectConfiguration.class.php</strong> hinterlegte Symfony-Version nutzt. Also wird ein kleines Script benötigt, das diese Gegebenheit ausnutzt. Folgendes Script kommt also in <strong>/usr/bin/symfony</strong>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/env php</span>
&nbsp;</pre></td></tr></table></div>

<p>Befindet man sich in einem Symfony-Projekt-Ordner benutzt das Script das im Ordner hinterlegte <strong>symfony</strong>, andernfalls eine Fallback-Variante <em>(in diesem Fall Symfony in Version <strong>1.4</strong>)</em>.</p>
<p>Somit haben wir den vollen Komfort erlangt &#8211; falls es noch schöner geht, hinterlasst doch einen Kommentar <img src='http://www.naji-dev.de/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Falls man aber explizit eine Symfony-Version benötigt <i>(zum Beispiel beim Anlegen eines neuen Projekts, die nicht der Standard-Version &#8211; also der Fallback-Version unseres Scripts &#8211; entspricht)</i>, sind folgende Symlinks noch nützlich:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>symfony12 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>php<span style="color: #000000; font-weight: bold;">/</span>symfony<span style="color: #000000; font-weight: bold;">/</span>symfony12<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>symfony
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>symfony13 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>php<span style="color: #000000; font-weight: bold;">/</span>symfony<span style="color: #000000; font-weight: bold;">/</span>symfony13<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>symfony
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>symfony14 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>php<span style="color: #000000; font-weight: bold;">/</span>symfony<span style="color: #000000; font-weight: bold;">/</span>symfony14<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>symfony</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.naji-dev.de/2009/12/27/multiple-symfony-installationen/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=109701&rnd=396266008" /></channel>
</rss>
