<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
    <channel>
        <title>Alexandre Salomé</title>
        <description>Blog posts from the alexandre-salome.fr</description>
        <link>http://alexandre-salome.fr/</link>
                <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/AlexandreSalome" /><feedburner:info uri="alexandresalome" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
            <title>Test your commands in Symfony2</title>
            <pubDate>Mon, 26 Dec 2011 00:00:00 +0100</pubDate>
            <link>http://feedproxy.google.com/~r/AlexandreSalome/~3/HRwMuTd43eI/Test-your-commands-in-Symfony2</link>
            <guid isPermaLink="false">http://alexandre-salome.fr/blog/Test-your-commands-in-Symfony2</guid>
            <description>&lt;div class="document"&gt;


&lt;p&gt;Console application is very useful when dealing with a web application. For example, in a personal project I'm currently working on, I created a bunch of commands to setup some parts:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;php app/console myproject:user-create &lt;span class="s2"&gt;&amp;quot;Alexandre Salomé&amp;quot;&lt;/span&gt; alex &lt;span class="s1"&gt;&amp;#39;alex@example.org&amp;#39;&lt;/span&gt;
User created
&lt;span class="nv"&gt;$ &lt;/span&gt;php app/console myproject:user-role-add alex admin
User role created
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The problem is that we don't really know how to test them. If you inject dependencies into it, you can test dependencies and rely on a thin-enough command class.&lt;/p&gt;
&lt;p&gt;But if you have more logic in it, you should better test it.&lt;/p&gt;
&lt;div class="section" id="unit-or-functional"&gt;
&lt;h2&gt;Unit or functional?&lt;/h2&gt;
&lt;p&gt;To unit-test it, you have to know which dependencies are required. In Symfony2, to execute a Command, you need to have a kernel and a container in it. If your command relies on services, each service need to be mocked, too.&lt;/p&gt;
&lt;p&gt;In my opinion, it's too much services to be unit tested. So let's go ahead for a functional test.&lt;/p&gt;
&lt;p&gt;Functional tests will launch the application in the &amp;quot;test&amp;quot; environment, like &lt;tt class="docutils literal"&gt;WebTestCase&lt;/tt&gt;. Also, we will extend this class for the CLI tests.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="code-please"&gt;
&lt;h2&gt;Code, please&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="nx"&gt;Acme\Bundle\DemoBundle\Test&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;Symfony\Bundle\FrameworkBundle\Test\WebTestCase&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;Symfony\Bundle\FrameworkBundle\Console\Application&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;Symfony\Component\Console\Input\StringInput&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;Symfony\Component\Console\Output\StreamOutput&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;Symfony\Bundle\FrameworkBundle\Client&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="sd"&gt;/**&lt;/span&gt;
&lt;span class="sd"&gt; * Base class for testing the CLI tools.&lt;/span&gt;
&lt;span class="sd"&gt; *&lt;/span&gt;
&lt;span class="sd"&gt; * @author Alexandre Salomé &amp;lt;alexandre.salome@gmail.com&amp;gt;&lt;/span&gt;
&lt;span class="sd"&gt; */&lt;/span&gt;
&lt;span class="k"&gt;abstract&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CommandTestCase&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;WebTestCase&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sd"&gt;/**&lt;/span&gt;
&lt;span class="sd"&gt;     * Runs a command and returns it output&lt;/span&gt;
&lt;span class="sd"&gt;     */&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;runCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Client&lt;/span&gt; &lt;span class="nv"&gt;$client&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$command&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$application&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Application&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$client&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getKernel&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
        &lt;span class="nv"&gt;$application&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;setAutoExit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nv"&gt;$fp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;tmpfile&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nv"&gt;$input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;StringInput&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$command&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;StreamOutput&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$fp&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nv"&gt;$application&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$output&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nb"&gt;fseek&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$fp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;feof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$fp&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;fread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$fp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4096&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nb"&gt;fclose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$fp&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$output&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="sample-please"&gt;
&lt;h2&gt;Sample, please&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

 &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;MyProject\MyProjectBundle\Test\CommandTestCase&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

 &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyTest&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;CommandTestCase&lt;/span&gt;
 &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;testDefaultDoesNotInstall&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
     &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="nv"&gt;$client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;self&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;createClient&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
         &lt;span class="nv"&gt;$output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;runCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$client&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;myproject:user-create alex &amp;#39;Alexandre Salomé&amp;#39; &amp;#39;alex@example.org&amp;#39;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

         &lt;span class="nv"&gt;$em&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$client&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getKernel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getContainer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;doctrine&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getEntityManager&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

         &lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$em&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getRepository&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;MyProjectBundle:User&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;findOneBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
             &lt;span class="s1"&gt;&amp;#39;username&amp;#39;&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;alex&amp;#39;&lt;/span&gt;
         &lt;span class="p"&gt;));&lt;/span&gt;

         &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;assertContains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;User created&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$output&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
         &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;assertEquals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Alexandre Salomé&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getFullname&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
         &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;assertEquals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;alex@example.org&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getEmail&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
         &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;assertEquals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getIsActive&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Here we are, we can now test our CLI edge cases and make the CLI command tools part of the test coverage.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AlexandreSalome/~4/HRwMuTd43eI" height="1" width="1"/&gt;</description>
        <feedburner:origLink>http://alexandre-salome.fr/blog/Test-your-commands-in-Symfony2</feedburner:origLink></item>
                <item>
            <title>PHP Tour Lille 2011</title>
            <pubDate>Sun, 27 Nov 2011 00:00:00 +0100</pubDate>
            <link>http://feedproxy.google.com/~r/AlexandreSalome/~3/rLF6MxXXpqM/PHP-Tour-Lille-2011</link>
            <guid isPermaLink="false">http://alexandre-salome.fr/blog/PHP-Tour-Lille-2011</guid>
            <description>&lt;div class="document"&gt;


&lt;p&gt;On november 24th, it was PHP Tour in Lille. It was the first time I was speaker in a conference.&lt;/p&gt;
&lt;p&gt;I had a great moment during those 2 days and met a lot of friendly people during the event. I hope to have other opportunities of speaking at conferences.&lt;/p&gt;
&lt;div class="section" id="magento-integration-continue-tests-et-automatisation"&gt;
&lt;h2&gt;Magento - Intégration continue, tests et automatisation&lt;/h2&gt;
&lt;img alt="Title slide from the presentation about Magento" class="float-left" src="/media/post/phptour-magento.png" /&gt;
&lt;p&gt;And finally, a presentation talking about Magento and best practices in a Magento project.&lt;/p&gt;
&lt;p&gt;In first part, presentation is about &lt;strong&gt;developing in Magento&lt;/strong&gt;, how to approach the critical question of resources. It talks about great resources in Magento, and being critical about informations we find.&lt;/p&gt;
&lt;p&gt;The second part is a &lt;strong&gt;technical part&lt;/strong&gt; with concrete examples available on Github. It explains how to automatically install the project, setup fixtures and automated tests in the project.&lt;/p&gt;
&lt;p&gt;During the conference, every sample code was live demonstrated.&lt;/p&gt;
&lt;p&gt;Like one guy said at the end of the presentation: all informations in this presentation is not only appliable to Magento, but also to any project.&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external" href="http://speakerdeck.com/u/alexandresalome/p/magento-integration-continue-tests-automatisation"&gt;Slides are available on speakerdeck (french slides)&lt;/a&gt; and &lt;a class="reference external" href="http://github.com/alexandresalome/Magento"&gt;code is on Github&lt;/a&gt; (see branches).&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="mocks-stubs-tests"&gt;
&lt;h2&gt;Mocks, Stubs, Tests&lt;/h2&gt;
&lt;p&gt;The other presentation was mainly prepared by &lt;a class="reference external" href="http://marcw.net"&gt;Marc Weistroff&lt;/a&gt; who could not attend the conference. So I replaced him for the presentation.&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;strong&gt;Tests&lt;/strong&gt;: why we create tests, meaning of tests&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Code coverage&lt;/strong&gt;: bad indicator, how to interpret&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Design&lt;/strong&gt;: how to create clean code&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mocks, Stubs&lt;/strong&gt;: the PHPUnit API&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a class="reference external" href="http://speakerdeck.com/u/alexandresalome/p/mocks-stubs-tests"&gt;Slides are on speakerdeck&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AlexandreSalome/~4/rLF6MxXXpqM" height="1" width="1"/&gt;</description>
        <feedburner:origLink>http://alexandre-salome.fr/blog/PHP-Tour-Lille-2011</feedburner:origLink></item>
                <item>
            <title>Last News From October 2011</title>
            <pubDate>Sun, 06 Nov 2011 00:00:00 +0100</pubDate>
            <link>http://feedproxy.google.com/~r/AlexandreSalome/~3/sgdZxcmxK94/Last-News-From-October-2011</link>
            <guid isPermaLink="false">http://alexandre-salome.fr/blog/Last-News-From-October-2011</guid>
            <description>&lt;div class="document"&gt;


&lt;p&gt;During the last weeks, a lot of things happened on my side.&lt;/p&gt;
&lt;div class="section" id="article-in-misc-magazine"&gt;
&lt;h2&gt;Article in MISC magazine&lt;/h2&gt;
&lt;img alt="Cover of the MISC Magazine" class="float-left" src="/media/post/misc-magazine.jpg" /&gt;
&lt;p&gt;It took me some weeks to tell it, but &lt;strong&gt;I've written an article for MISC Magazine&lt;/strong&gt;. This article appears in the edition of October/November.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;MISC Magazine&lt;/strong&gt; is specialized in security and very reputated in France for his advanced articles about security. This special edition &amp;quot;A l'assaut du Web&amp;quot; is about security for the Web.&lt;/p&gt;
&lt;p&gt;I thank Fabien Potencier for giving me the opportunity to write this article and his support for it.&lt;/p&gt;
&lt;p&gt;This article is called &amp;quot;&lt;strong&gt;Prise en compte de la sécurité dans un framework PHP : le cas Symfony2&lt;/strong&gt;&amp;quot;, which means &amp;quot;Handling security in a PHP framework: the Symfony2 case&amp;quot;.&lt;/p&gt;
&lt;p&gt;It details common security problems when dealing with Web applications (SQL Injection, CSRF attack, XSS...). For each one, it explains the problem, the raw PHP solution and finally the Symfony2 approach.&lt;/p&gt;
&lt;p&gt;So if you are french, run to your library and buy it! If you're not in France, &lt;a class="reference external" href="http://ed-diamond.com/rubriquemagactu.php?id_rubrique=9&amp;amp;caracteristique=1-2-&amp;amp;caracdisp=2-10-"&gt;Buy it online&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="conference-about-magento-in-some-weeks"&gt;
&lt;h2&gt;Conference about Magento in some weeks&lt;/h2&gt;
&lt;p&gt;I also practice Magento on my lost hours, and I prepare a &lt;strong&gt;conference for&lt;/strong&gt; &lt;a class="reference external" href="http://afup.org/pages/phptourlille2011/"&gt;PHP Tour Lille 2011&lt;/a&gt;. The conference is on &lt;strong&gt;November 25th, 2011&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This conference is in french and is called &amp;quot;&lt;strong&gt;Magento - Tests, automatisation et intégration continue&lt;/strong&gt;&amp;quot;. It means &amp;quot;Magento - Tests, automatisation and continuous integration&amp;quot;.&lt;/p&gt;
&lt;p&gt;It will talk about how to automate a Magento project and how to create some clean code. It will provide some samples for clearly coding with Magento. Code and slides will be published after the presentation.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="php-selenium-library-integrated-in-mink"&gt;
&lt;h2&gt;PHP Selenium Library integrated in Mink&lt;/h2&gt;
&lt;p&gt;Some weeks ago, &lt;a class="reference external" href="http://alexandre-salome.fr/blog/PHP-Selenium-Library"&gt;I introduced a PHP Selenium Library&lt;/a&gt;, in a clean PHP 5.3 code. It is now part of &lt;a class="reference external" href="http://mink.behat.org"&gt;Mink&lt;/a&gt;, a library used by &lt;a class="reference external" href="http://behat.org/"&gt;Behat&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For the moment it's still in the development branch, but &lt;strong&gt;next release of Behat will integrate the library for Selenium automation&lt;/strong&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="website-a-new-section-and-a-new-theme"&gt;
&lt;h2&gt;Website: A new section and a new theme!&lt;/h2&gt;
&lt;p&gt;If it's the first time you come to this website, you won't notice it, but &lt;strong&gt;before those new fresh colors, it was a monotone with big texts&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Thanks to people for being polite, but I admit that the previous theme was not very fun, and little bit boring.&lt;/p&gt;
&lt;p&gt;I refreshed it with some new colors, and I created a new sections called &lt;a class="reference external" href="/books"&gt;Books&lt;/a&gt; containing the list of books I've read. For the moment it's only a short description. Progressively, I will integrate a quick review for each one. I hope you will find some great books to read in it!&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AlexandreSalome/~4/sgdZxcmxK94" height="1" width="1"/&gt;</description>
        <feedburner:origLink>http://alexandre-salome.fr/blog/Last-News-From-October-2011</feedburner:origLink></item>
                <item>
            <title>PHP Selenium Library</title>
            <pubDate>Sat, 08 Oct 2011 00:00:00 +0200</pubDate>
            <link>http://feedproxy.google.com/~r/AlexandreSalome/~3/KanpqVdGlLE/PHP-Selenium-Library</link>
            <guid isPermaLink="false">http://alexandre-salome.fr/blog/PHP-Selenium-Library</guid>
            <description>&lt;div class="document"&gt;


&lt;p&gt;I've just created a PHP library for Selenium! It provides some basic features :&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;Fluid interface&lt;/li&gt;
&lt;li&gt;IDE code-completion&lt;/li&gt;
&lt;li&gt;Independant library&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For the moment, it's very basic (but it works).&lt;/p&gt;
&lt;p&gt;I plan to add some extra features later like context management, integrations into Symfony2, maybe Mink too.&lt;/p&gt;
&lt;div class="section" id="sample-code"&gt;
&lt;h2&gt;Sample code&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="k"&gt;require_once&lt;/span&gt; &lt;span class="nx"&gt;__DIR__&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;/autoload.php&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$client&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Selenium&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nv"&gt;$browser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$client&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getBrowser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;http://alexandre-salome.fr&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c"&gt;// Starts the browser&lt;/span&gt;
&lt;span class="nv"&gt;$browser&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nv"&gt;$browser&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;/&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;click&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Selenium&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;Locator&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;linkContaining&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Blog&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;waitForPageToLoad&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Page title: &amp;quot;&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$browser&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getTitle&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Available on Github : &lt;a class="reference external" href="https://github.com/alexandresalome/PHP-Selenium"&gt;https://github.com/alexandresalome/PHP-Selenium&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AlexandreSalome/~4/KanpqVdGlLE" height="1" width="1"/&gt;</description>
        <feedburner:origLink>http://alexandre-salome.fr/blog/PHP-Selenium-Library</feedburner:origLink></item>
                <item>
            <title>Generate mails with Twig</title>
            <pubDate>Wed, 28 Sep 2011 00:00:00 +0200</pubDate>
            <link>http://feedproxy.google.com/~r/AlexandreSalome/~3/o3j0qQbVvb8/Generate-Mails-With-Twig</link>
            <guid isPermaLink="false">http://alexandre-salome.fr/blog/Generate-Mails-With-Twig</guid>
            <description>&lt;div class="document"&gt;


&lt;p&gt;Yesterday, I discovered a new way for generating mails with Twig, in a very
powerful way.&lt;/p&gt;
&lt;div class="section" id="the-problem"&gt;
&lt;h2&gt;The problem&lt;/h2&gt;
&lt;p&gt;It started because of someone explaining me he was using something similar to
this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="c"&gt;// Subject was loaded from a yaml file&lt;/span&gt;
&lt;span class="nv"&gt;$subject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Welcome to newsletter, %%customer_name%%&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s1"&gt;&amp;#39;%%customer_name%%&amp;#39;&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getName&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="s1"&gt;&amp;#39;%%customer_mail%%&amp;#39;&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getMail&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="c"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$values&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$subject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;str_replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$subject&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;For generating the content of the mail, it was something like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="nv"&gt;$twig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;twig&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c"&gt;// a Twig_Environment instance&lt;/span&gt;
&lt;span class="nv"&gt;$bodyHtml&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$twig&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;mail_newsletter.html.twig&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$bodyText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$twig&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;mail_newsletter.text.twig&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The problem with this solution is that you have two different types of
templating engine. The first one is a PHP &lt;tt class="docutils literal"&gt;str_replace&lt;/tt&gt; templating engine and
the second one is Twig.&lt;/p&gt;
&lt;p&gt;After some searches, I finally discovered a powerful way for generating mails:&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="the-solution"&gt;
&lt;h2&gt;The solution&lt;/h2&gt;
&lt;p&gt;First, you need to create a template, let's assume &lt;tt class="docutils literal"&gt;mail.twig&lt;/tt&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;{% block subject &amp;#39;Welcome to newsletter, &amp;#39; ~ customer.getName() %}

{% block body_html %}
    This is the &amp;lt;strong&amp;gt;HTML body&amp;lt;/strong&amp;gt;.
{% endblock %}

{% block body_text %}
    This is the text body.
{% endblock %}
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This is perfect: in one file, we have every informations for generating the
mail content.&lt;/p&gt;
&lt;p&gt;Let's see now how to fetch it from Twig:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="nv"&gt;$twig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;twig&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c"&gt;// Twig_Environment&lt;/span&gt;

&lt;span class="nv"&gt;$template&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$twig&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;loadTemplate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;mail.twig&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$parameters&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s1"&gt;&amp;#39;customer&amp;#39;&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nv"&gt;$subject&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$template&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;renderBlock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;subject&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="nv"&gt;$parameters&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$bodyHtml&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$template&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;renderBlock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;body_html&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$parameters&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$bodyText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$template&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;renderBlock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;body_text&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$parameters&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And now, you have everything for creating your mail message, created from one
file only.&lt;/p&gt;
&lt;p&gt;This also means you can use in your template every Twig possibilities, like the
translation extension, or the inheritance mechanism of templates.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="integration-in-your-application"&gt;
&lt;h2&gt;Integration in your application&lt;/h2&gt;
&lt;p&gt;Now, we have a raw PHP implementation, let's see how it's possible to integrate
it in your application.&lt;/p&gt;
&lt;p&gt;The idea is to create a class for preparing the Swift message, so in the end we
only need to set the receiver, and that's all!&lt;/p&gt;
&lt;p&gt;A mail generator :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TwigMailGenerator&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$twig&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Twig_Environment&lt;/span&gt; &lt;span class="nv"&gt;$twig&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;twig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$twig&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$identifier&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$parameters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$template&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;twig&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;loadTemplate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;mail/&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$identifier&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;.twig&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c"&gt;// Define your own schema&lt;/span&gt;

        &lt;span class="nv"&gt;$subject&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$template&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;renderBlock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;subject&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="nv"&gt;$parameters&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$bodyHtml&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$template&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;renderBlock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;body_html&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$parameters&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$bodyText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$template&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;renderBlock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;body_text&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$parameters&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;Swift_Message&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;newInstance&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;setSubject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$subject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;setBody&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$bodyText&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;text/plain&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;addPart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$bodyHtml&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;text/html&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;For using it, very simple: suppose you have organized your mails according to
the schema &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;mail/&amp;lt;identifier&amp;gt;.twig&lt;/span&gt;&lt;/tt&gt;, the code to use it would be:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="nv"&gt;$twig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;twig&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;     &lt;span class="c"&gt;// Twig_Environment&lt;/span&gt;
&lt;span class="nv"&gt;$mailer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;mailer&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c"&gt;// Swift_Mailer&lt;/span&gt;

&lt;span class="nv"&gt;$generator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;TwigMailGenerator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$twig&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c"&gt;// Can be in a DIC&lt;/span&gt;

&lt;span class="nv"&gt;$message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$generator&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;newsletter&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s1"&gt;&amp;#39;customer&amp;#39;&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;
&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="nv"&gt;$message&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;setTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getMail&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="nv"&gt;$mailer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;That's all for the suggested implementation! No need to create a dedicated
bundle for it, or some kind of reusable code. There are 20 lines of code, just
integrate it in your application to fit your needs, and it's enough.&lt;/p&gt;
&lt;p&gt;Enjoy Twig!&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AlexandreSalome/~4/o3j0qQbVvb8" height="1" width="1"/&gt;</description>
        <feedburner:origLink>http://alexandre-salome.fr/blog/Generate-Mails-With-Twig</feedburner:origLink></item>
                <item>
            <title>Sass, Compass, and Assetic in 10 minutes</title>
            <pubDate>Sun, 31 Jul 2011 00:00:00 +0200</pubDate>
            <link>http://feedproxy.google.com/~r/AlexandreSalome/~3/f9LsXnvW6CQ/Sass-Compass-Assetic-In-Ten-Minutes</link>
            <guid isPermaLink="false">http://alexandre-salome.fr/blog/Sass-Compass-Assetic-In-Ten-Minutes</guid>
            <description>&lt;div class="document"&gt;


&lt;p&gt;CSS are boring for most of the developers. They don't like it. They prefer
development, because they hate supporting Internet Explorer, they find no
pleasure in writing CSS and they are right : CSS is boring. Writing CSS means
most of the time repeating code, supporting browsers and creating static code.&lt;/p&gt;
&lt;p&gt;There are also the frontend required optimizations, who prevent the developer
from generating beautiful and DRY CSS : sprite generation, put all CSS in one
file, compress assets, and so on.&lt;/p&gt;
&lt;p&gt;Most of the time, they prefer to have a &amp;quot;ready-to-use&amp;quot; HTML production. This
approach is not the most optimal, because you need to adapt CSS, to add new
rules, to refactor some parts. CSS are part of the application, as the PHP, as
the HTML. When a separation like this occurs, lot of time is spent fixing CSS
issues, and going through the CSS sounds like a headache.&lt;/p&gt;
&lt;p&gt;Once upon a time, some people created some concepts for the development : Don't
Repeat Yourself, Keep It Simple Stupid. Those concepts looks like forgotten when
developers create CSS.&lt;/p&gt;
&lt;p&gt;Let's see how to bring them back to the scene, let's power the CSS production.&lt;/p&gt;
&lt;div class="section" id="small-files-please"&gt;
&lt;h2&gt;1. Small files, please&lt;/h2&gt;
&lt;p&gt;First, whatever the context is, when you produce some code : create small and
separated files.&lt;/p&gt;
&lt;p&gt;For example, the &lt;a class="reference external" href="https://github.com/alexandresalome/Alom/tree/d973ccc8167ca6c25a2217111669ed38de214f9e/src/Alom/Website/MainBundle/Resources/css"&gt;CSS on this website&lt;/a&gt;,
the files are separated by purpose, as isolated as possible :&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;tt class="docutils literal"&gt;reset.css&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;&lt;tt class="docutils literal"&gt;main.css&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;&lt;tt class="docutils literal"&gt;banner.css&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;&lt;tt class="docutils literal"&gt;header.css&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;&lt;tt class="docutils literal"&gt;footer.css&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When I search something, I know the file to open, The feature is isolated. The
refactoring of a feature would be fast, easy and isolated enough.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="sass-it-s-f-king-awesome"&gt;
&lt;h2&gt;2. Sass : it's f#~king awesome&lt;/h2&gt;
&lt;p&gt;&lt;a class="reference external" href="http://sass-lang.com/"&gt;Sass&lt;/a&gt; is an extension of CSS adding new features to the
language : mixins, variables, inheritance and
&lt;a class="reference external" href="http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html"&gt;more&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;A Sass file looks like this :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="k"&gt;@mixin&lt;/span&gt; &lt;span class="nt"&gt;message-color&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;color&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;bg&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="nt"&gt;color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;            &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;color&lt;/span&gt;
    &lt;span class="nt"&gt;border&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;           &lt;span class="nt"&gt;1px&lt;/span&gt; &lt;span class="nt"&gt;solid&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;color&lt;/span&gt;
    &lt;span class="nt"&gt;background-color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;bg&lt;/span&gt;

&lt;span class="nf"&gt;#messages&lt;/span&gt;

    &lt;span class="nc"&gt;.error&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;.success&lt;/span&gt;
        &lt;span class="nt"&gt;margin&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;           &lt;span class="nt"&gt;1em&lt;/span&gt;
        &lt;span class="nt"&gt;padding&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;          &lt;span class="nt"&gt;1em&lt;/span&gt;

    &lt;span class="nc"&gt;.error&lt;/span&gt;
        &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nt"&gt;message-color&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;red&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;#ffaaaa&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

    &lt;span class="nc"&gt;.success&lt;/span&gt;
        &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nt"&gt;message-color&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;green&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;#aaffaa&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Sass allows to produce meaningful stylesheet code. Here we see different
concepts in Sass. But to be fully impressed by Sass, you should &lt;a class="reference external" href="http://sass-lang.com/"&gt;visit the
website&lt;/a&gt; and see examples.&lt;/p&gt;
&lt;p&gt;The main idea is avoid repeating or computing values. Each time you are about to
repeat something (a selector, a CSS ruleset), there is a method for it in Sass.&lt;/p&gt;
&lt;p&gt;For example, to avoid computing :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;headerHeight&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;50px&lt;/span&gt;
&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;menuHeight&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;   &lt;span class="nt"&gt;20px&lt;/span&gt;

&lt;span class="nf"&gt;#header&lt;/span&gt;
    &lt;span class="nt"&gt;position&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;relative&lt;/span&gt;
    &lt;span class="nt"&gt;height&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;   &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;headerHeight&lt;/span&gt;
&lt;span class="nf"&gt;#menu&lt;/span&gt;
    &lt;span class="nt"&gt;position&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;absolute&lt;/span&gt;
    &lt;span class="nt"&gt;top&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;      &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;headerHeight&lt;/span&gt; &lt;span class="nt"&gt;-&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;menuHeight&lt;/span&gt;
    &lt;span class="nt"&gt;right&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;    &lt;span class="nt"&gt;0&lt;/span&gt;
    &lt;span class="nt"&gt;height&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;   &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;menuHeight&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Here you can modify later the &lt;tt class="docutils literal"&gt;$menuHeight&lt;/tt&gt; or &lt;tt class="docutils literal"&gt;$headerHeight&lt;/tt&gt;, there is no
need to modify 20 different lines, no need to search where the value is used,
and no meaningless value in your CSS (&lt;tt class="docutils literal"&gt;height: 42px&lt;/tt&gt;, what's this value ?).&lt;/p&gt;
&lt;p&gt;Another useful command, when you already have existing CSS is &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;sass-convert&lt;/span&gt;&lt;/tt&gt;.
This command will convert to CSS to Sass files :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;sass-convert my-file.css my-file.sass
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This command has no magic inside, and cannot guess computed values, but it's a
good start for Sass.&lt;/p&gt;
&lt;p&gt;I already had many small CSS files for this website, converting them to Sass
was a &lt;a class="reference external" href="https://github.com/alexandresalome/Alom/commit/a88b9ed9058b72329f6655a63adcd9702825cbd0"&gt;30-seconds task&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="compass-a-framework-over-sass"&gt;
&lt;h2&gt;3. Compass, a framework over Sass&lt;/h2&gt;
&lt;p&gt;Sass provides the language. Compass provides the tools ! &lt;a class="reference external" href="http://compass-style.org/"&gt;Compass&lt;/a&gt; is a CSS authoring framework. It provides
you helpers and utilities like &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;image-width&lt;/span&gt;&lt;/tt&gt;, and &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;sprite-*&lt;/span&gt;&lt;/tt&gt; methods.
A &lt;a class="reference external" href="http://compass-style.org/reference/compass/"&gt;reference guide&lt;/a&gt; is available
with every methods.&lt;/p&gt;
&lt;p&gt;A quick-example of features available with it :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;compass/reset&amp;quot;&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;Reset&lt;/span&gt; &lt;span class="nt"&gt;CSS&lt;/span&gt;
&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;logoUrl&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;/logo.png&amp;quot;&lt;/span&gt;
&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;bgColor&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;blue&lt;/span&gt;

&lt;span class="nf"&gt;#header&lt;/span&gt;
    &lt;span class="nt"&gt;color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;bgColor&lt;/span&gt;
    &lt;span class="nt"&gt;background-color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;lighten&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;bgColor&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;40&lt;/span&gt;&lt;span class="o"&gt;%)&lt;/span&gt;
&lt;span class="nf"&gt;#logo&lt;/span&gt;
    &lt;span class="nt"&gt;width&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;      &lt;span class="nt"&gt;image-width&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;logoUrl&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="nt"&gt;height&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;     &lt;span class="nt"&gt;image-height&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;logoUrl&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="nt"&gt;background&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;url&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;logoUrl&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="nt"&gt;span&lt;/span&gt;
        &lt;span class="nt"&gt;display&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;none&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Sprite-generation also become very easy with Compass. Here's a small sample of
sprite-generation used for the menu of this website :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;menu&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;sprite-map&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;sprites/menu-*.png&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;#menu&lt;/span&gt;
    &lt;span class="nt"&gt;li&lt;/span&gt;
        &lt;span class="nt"&gt;background-image&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;sprite-url&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;menu&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nc"&gt;.blog&lt;/span&gt;
        &lt;span class="nt"&gt;background-position&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;sprite-position&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;menu&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;blog&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nc"&gt;.cv&lt;/span&gt;
        &lt;span class="nt"&gt;background-position&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;sprite-position&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;menu&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;cv&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nc"&gt;.contact&lt;/span&gt;
        &lt;span class="nt"&gt;background-position&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;sprite-position&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="nt"&gt;menu&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;contact&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Awesome, heh ?&lt;/p&gt;
&lt;p&gt;The sprite-image is generated automatically, so no need to refactor the CSS and
the sprite-image when you modify an image.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="assetic-the-magic-key"&gt;
&lt;h2&gt;4. Assetic : the magic key&lt;/h2&gt;
&lt;p&gt;&lt;a class="reference external" href="http://kriswallsmith.net/"&gt;Kris Wallsmith&lt;/a&gt; created an awesome tool for asset
management : &lt;a class="reference external" href="https://github.com/kriswallsmith/assetic"&gt;Assetic&lt;/a&gt;. For a brief
introduction on &amp;quot;how it works&amp;quot; and &amp;quot;what's in it&amp;quot;, please see &lt;a class="reference external" href="http://symfony.com/video/Paris2011/571"&gt;his presentation
on Symfony Live&lt;/a&gt; (&lt;a class="reference external" href="http://www.slideshare.net/kriswallsmith/introducing-assetic-asset-management-for-php-53"&gt;slides
here&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;First of all, separate two things : Assetic and AsseticBundle.&lt;/p&gt;
&lt;p&gt;Assetic is the library providing the filters, the asset manager, the formula
loader, and so on. It comes with many pre-configured filters for Sass, Compass
and others. It also provides the tools for combining assets.&lt;/p&gt;
&lt;p&gt;AsseticBundle is the integration in Symfony2 providing iteration of templates to
find formula, automatic generation of them in development, CLI tools, and so on.&lt;/p&gt;
&lt;div class="section" id="sample-with-symfony2-sass-compass"&gt;
&lt;h3&gt;Sample with Symfony2, Sass &amp;amp; Compass&lt;/h3&gt;
&lt;p&gt;Let's see how to create a Symfony2 project with some Sass files.&lt;/p&gt;
&lt;p&gt;First, install Sass &amp;amp; Compass (cf &lt;a class="reference external" href="http://sass-lang.com/"&gt;Sass website&lt;/a&gt; and &lt;a class="reference external" href="http://compass-style.org/install/"&gt;Compass install guide&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Then, enable filters in your application in &lt;tt class="docutils literal"&gt;app/config/config.yml&lt;/tt&gt;. Here, I
indicate to Compass where all my images are located. So when I say
&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;url('/images/logo.png')&lt;/span&gt;&lt;/tt&gt;, he knows it means
&lt;tt class="docutils literal"&gt;/my/project/web/images/logo.png&lt;/tt&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;parameters:
    # Assetic
    assetic.filter.compass.images_dir: %kernel.root_dir%/../web/images
    assetic.filter.compass.http_path:  /images

assetic:
    debug:          %kernel.debug%
    use_controller: false
    filters:
        sass:    ~
        compass: ~
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Then, create a &lt;tt class="docutils literal"&gt;stylesheets.html.twig&lt;/tt&gt; containing your assets definition :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="cp"&gt;{%&lt;/span&gt; &lt;span class="k"&gt;stylesheets&lt;/span&gt; &lt;span class="nv"&gt;filters&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;compass&amp;quot;&lt;/span&gt;
    &lt;span class="s2"&gt;&amp;quot;@AlomMainBundle/Resources/assets/css/main.sass&amp;quot;&lt;/span&gt;
    &lt;span class="s2"&gt;&amp;quot;@AlomMainBundle/Resources/assets/css/header.sass&amp;quot;&lt;/span&gt;
    &lt;span class="s2"&gt;&amp;quot;@AlomMainBundle/Resources/assets/css/footer.sass&amp;quot;&lt;/span&gt;
&lt;span class="cp"&gt;%}&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;stylesheet&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;asset_url&lt;/span&gt; &lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;{%&lt;/span&gt; &lt;span class="k"&gt;endstylesheets&lt;/span&gt; &lt;span class="cp"&gt;%}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And I include it in my layout :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;!- ... --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    {% include &amp;quot;::stylesheets.html.twig&amp;quot; %}
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And that's all.&lt;/p&gt;
&lt;p&gt;For the development environment, stylesheets are generated automatically. For
the production environment, you need to generate assets before, by running :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;./app/console assetic:dump --env&lt;span class="o"&gt;=&lt;/span&gt;prod --no-debug
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And that's all.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="conclusion"&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Mastering CSS is important for a project. Develop them the same way you develop
the rest of the application is very important if you want to make the code
evolve and want something reusable. This article shows you how to take
benefit from modern technologies : Sass, Compass, Assetic, and Symfony2.&lt;/p&gt;
&lt;p&gt;Even if you are not using Assetic and Symfony2, Sass &amp;amp; Compass are too awesome
to be unused : you can use them for generating HTML templates by using Compass
CLI tools.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AlexandreSalome/~4/f9LsXnvW6CQ" height="1" width="1"/&gt;</description>
        <feedburner:origLink>http://alexandre-salome.fr/blog/Sass-Compass-Assetic-In-Ten-Minutes</feedburner:origLink></item>
                <item>
            <title>How To Save Power Battery</title>
            <pubDate>Sun, 17 Jul 2011 00:00:00 +0200</pubDate>
            <link>http://feedproxy.google.com/~r/AlexandreSalome/~3/G4HiwY5mv_U/How-To-Save-Power-Battery</link>
            <guid isPermaLink="false">http://alexandre-salome.fr/blog/How-To-Save-Power-Battery</guid>
            <description>&lt;div class="document"&gt;


&lt;p&gt;Batteries are present in every device : laptop, mobile phone, MP3 player. But
after a time (depending of the quality of the battery and the usage), the
battery goes down, and you can only use it for 5 minutes. At this moment, you go
to Google to find some advices on &amp;quot;how to restore my battery&amp;quot;, but... it's to
late.&lt;/p&gt;
&lt;p&gt;Keep in mind that &lt;strong&gt;your battery is a consumable&lt;/strong&gt; : you will not be able to
keep it for ever. Knowing this, you can get some good practises to maximize the
lifetime.&lt;/p&gt;
&lt;p&gt;This article will teach you how to preserve your battery and how to keep it as
long as possible.&lt;/p&gt;
&lt;div class="section" id="ventilate-it"&gt;
&lt;h2&gt;Ventilate it&lt;/h2&gt;
&lt;p&gt;The battery hates heat, so when you are using your laptop at home, &lt;strong&gt;do not put it
on a pillow or in the bed&lt;/strong&gt;. Place something flat and rigid below it, to keep a
good airing in it.&lt;/p&gt;
&lt;p&gt;Also, get used to &lt;strong&gt;blow your computer&lt;/strong&gt; regularly (1 time per year). You can go
to a computer store, or buy a dry air bomb and do it yourself.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="avoid-extreme-temperatures"&gt;
&lt;h2&gt;Avoid extreme temperatures&lt;/h2&gt;
&lt;p&gt;A good-temperature for a battery is between 10°C and 20°C. Below 10°C and above
20°C can damage your battery.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;If you let your computer in a car, you can damage it&lt;/strong&gt; : if the weather is
sunny, your car will become a oven : high-temperatures damage your computer. At
the opposite, if it's winter, your car will become a freezer, and
low-temperatures damage your computer, too.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="do-not-use-it-below-10"&gt;
&lt;h2&gt;Do not use it below 10%&lt;/h2&gt;
&lt;p&gt;When you go below 10%, &lt;strong&gt;you are consuming a lot your battery&lt;/strong&gt;. The whole
battery is exhausted of the previous 90%, and now she has to concentrate a lot
to find the rest of energy contained in it.&lt;/p&gt;
&lt;p&gt;Take the habit to stop using the machine when it says &amp;quot;hey, my battery is low&amp;quot;.
At this moment, find a power supply and fill your battery.&lt;/p&gt;
&lt;p&gt;Recharge it when it is low, because &lt;strong&gt;keeping the battery at a low level is
bad&lt;/strong&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="do-not-keep-it-full-charged"&gt;
&lt;h2&gt;Do not keep it full-charged&lt;/h2&gt;
&lt;p&gt;Keeping the battery full-charged for a long time is a bad factor. This fact is
meaningful for people who always plug their computer to the power supply : &lt;strong&gt;if
you don't remove the power supply, remove the battery with 80% in it&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;As demonstrated above, there are some factors :&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="intensive-usage"&gt;
&lt;h2&gt;Intensive usage&lt;/h2&gt;
&lt;p&gt;An intensive usage of your battery is also painful for your battery, especially
when the level is low.&lt;/p&gt;
&lt;p&gt;When you are &lt;strong&gt;on battery, try to minimize activity&lt;/strong&gt; : minimize the light of
the screen, do not do 3D-processing, avoid video games, and so on.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="conclusion"&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Your battery is a consumable, you will not keep it for ever. But keep in mind
those factors (temperatures, intensity, low/high levels), and you can maximize
the lifetime of it.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AlexandreSalome/~4/G4HiwY5mv_U" height="1" width="1"/&gt;</description>
        <feedburner:origLink>http://alexandre-salome.fr/blog/How-To-Save-Power-Battery</feedburner:origLink></item>
                <item>
            <title>Isolation of tests in Symfony2</title>
            <pubDate>Sun, 10 Jul 2011 00:00:00 +0200</pubDate>
            <link>http://feedproxy.google.com/~r/AlexandreSalome/~3/FGZaWe-zwNc/Symfony2-Isolation-Of-Tests</link>
            <guid isPermaLink="false">http://alexandre-salome.fr/blog/Symfony2-Isolation-Of-Tests</guid>
            <description>&lt;div class="document"&gt;


&lt;p&gt;For achieving good tests in your project, you will need to have a correct
isolation of them. When a test executes, it should leave the application in
the same state as when he entered it.&lt;/p&gt;
&lt;p&gt;In Symfony2, the most common-case is the database isolation : when we are
testing, we expect from our application to isolate the test with a transaction
and to rollback it at the end.&lt;/p&gt;
&lt;div class="section" id="functional-tests-in-symfony2"&gt;
&lt;h2&gt;Functional tests in Symfony2&lt;/h2&gt;
&lt;p&gt;In Symfony2, functional testing is achieved with the &lt;strong&gt;test client&lt;/strong&gt;. The test
client is responsible of requesting the kernel, and fetching a response from
a request.&lt;/p&gt;
&lt;p&gt;The test client allows to easily request the kernel and crawl the response.&lt;/p&gt;
&lt;p&gt;For example, we can achieve :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyTest&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;PHPUnit_Framework_TestCase&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;testSomething&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;createClient&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nv"&gt;$crawler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$client&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;GET&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;/test&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;assertEquals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$client&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getResponse&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getStatusCode&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;assertEquals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Hello&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$crawler&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;h1&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The test client handles requests to the kernel and returns crawler, for easing
navigation through the returned response.&lt;/p&gt;
&lt;p&gt;In Symfony2, the test client is a service of the container. Its service name is
&lt;tt class="docutils literal"&gt;test.client&lt;/tt&gt;.&lt;/p&gt;
&lt;p&gt;It is possible to override your test client in your container, to add some
custom methods and behaviors, as we will see in the following chapters.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="basic-overriding-of-test-client"&gt;
&lt;h2&gt;Basic overriding of test client&lt;/h2&gt;
&lt;p&gt;To simply override the Test client, redefine in your configuration :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="nt"&gt;&amp;lt;parameters&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;parameter&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;test.client.class&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Alom\Website\MainBundle\Test\Client&lt;span class="nt"&gt;&amp;lt;/parameter&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/parameters&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Then, just redefine the test client class, like this :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="nx"&gt;namespace&lt;/span&gt; &lt;span class="nx"&gt;Alom&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;Website&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;MainBundle&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;Test&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;Symfony&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;Bundle&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;FrameworkBundle&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;Client&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;BaseClient&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Client&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;BaseClient&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This way, we can override the test client with our custom methods. For
example, we can create a &lt;tt class="docutils literal"&gt;connect&lt;/tt&gt; method to automatically connect the user
to the website.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="c"&gt;// ...&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$crawler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;GET&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;/login&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="c"&gt;// ....&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;With this method, you can create anything that you need for easing tests of your
application.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="isolation-of-doctrine"&gt;
&lt;h2&gt;Isolation of Doctrine&lt;/h2&gt;
&lt;p&gt;Each time you make a request, Symfony2 creates a new container for it. This
means that the Doctrine objects (for DBAL and ORM) are different for each
request.&lt;/p&gt;
&lt;p&gt;And here is the problem : we have a different connection for each request, so
it's not possible to have the same connection for every request of the client.&lt;/p&gt;
&lt;p&gt;The solution is to pass the service through different requests, and isolate them
in a transaction.&lt;/p&gt;
&lt;p&gt;To achieve this, we override the &lt;tt class="docutils literal"&gt;doRequest&lt;/tt&gt; method of the test client, which
is responsible of passing requests to the kernel.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="c"&gt;// ...&lt;/span&gt;
    &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$connection&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$requested&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;doRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;requested&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;kernel&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;shutdown&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;kernel&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;boot&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;injectConnection&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;requested&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;kernel&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;injectConnection&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;self&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nv"&gt;$connection&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;self&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nv"&gt;$connection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getContainer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;doctrine.dbal.default_connection&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;requested&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;self&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nv"&gt;$connection&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;rollback&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getContainer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;doctrine.dbal.default_connection&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;self&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nv"&gt;$connection&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;requested&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;self&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nv"&gt;$connection&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;beginTransaction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class="section" id="isn-t-it-integrated-in-symfony2"&gt;
&lt;h3&gt;Isn't it integrated in Symfony2 ?&lt;/h3&gt;
&lt;p&gt;The answer is no. This code, here is quite simple, 20 lines for achieving what
we want, in our project. Integrating it in Symfony2 would mean 100-200 lines
for :&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;Disabling it when Doctrine is not bundled&lt;/li&gt;
&lt;li&gt;Add a support of multiple connections&lt;/li&gt;
&lt;li&gt;Override the test client when the Doctrine bundle is activated&lt;/li&gt;
&lt;li&gt;Add some options for edge-cases : no isolation needed, ODM, etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There is also the question of isolation for other services of your application :
SolR engine, Web Services, and so on.&lt;/p&gt;
&lt;p&gt;The better place for it (in my humble opinion) is in your project. Because even
if it's a common case, the implementation is not trivial.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AlexandreSalome/~4/FGZaWe-zwNc" height="1" width="1"/&gt;</description>
        <feedburner:origLink>http://alexandre-salome.fr/blog/Symfony2-Isolation-Of-Tests</feedburner:origLink></item>
                <item>
            <title>Versioning A Project</title>
            <pubDate>Sat, 09 Jul 2011 00:00:00 +0200</pubDate>
            <link>http://feedproxy.google.com/~r/AlexandreSalome/~3/A-2PTaC3lMg/Versioning-A-Project</link>
            <guid isPermaLink="false">http://alexandre-salome.fr/blog/Versioning-A-Project</guid>
            <description>&lt;div class="document"&gt;


&lt;p&gt;Project versioning provides many confort when developing a project : managing
concurent developments, keeping an history, easing the release process,
isolation of some features, version tagging, unified version for all developers,
and so on.&lt;/p&gt;
&lt;p&gt;Many systems exist : Subversion, Git, Bazaar, Mercurial... but both systems share
some common philosophy, and every informations of this article are true for
every versioning system.&lt;/p&gt;
&lt;div class="section" id="only-keep-your-brain-generated-code"&gt;
&lt;h2&gt;Only keep your brain-generated code&lt;/h2&gt;
&lt;p&gt;The first important rule is to keep only the created code. There is no place for
generated code, for example the API documentation : it is generated from your
code.&lt;/p&gt;
&lt;p&gt;The most dummy reason is to keep the source repository as small as possible. The
other reason is the consistency : if you modify your source code without
re-generating the API documentation, you will have a difference between the
sourcecode and its documentation.&lt;/p&gt;
&lt;p&gt;Removing generated code from the repository will also prevent users from
modifying them. For example, in symfony 1.4, Doctrine generates base entities.
It was very confusing, because they were placed with the sourcecode, and many
developers versionned them. Then, someone else started modifying it. At the end,
you cannot regenerate entities without breaking the application.&lt;/p&gt;
&lt;p&gt;All generated files should be ignored with &lt;tt class="docutils literal"&gt;svn:ignore&lt;/tt&gt; or &lt;tt class="docutils literal"&gt;.gitignore&lt;/tt&gt;, or
whatever, depending of your versioning system.&lt;/p&gt;
&lt;p&gt;This rule is also true when dealing with external softwares. For example,
you shouldn't version third libraries, because this is not your code. This will
be discussed later in this article.&lt;/p&gt;
&lt;p&gt;To conclude, just remember : &lt;strong&gt;only version what you created, with your brain&lt;/strong&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="environment-and-security"&gt;
&lt;h2&gt;Environment and security&lt;/h2&gt;
&lt;p&gt;It's important to identify what's specific to your local environment and what's
in the project scope. For example, a folder path is specific to your local
environment. The database configuration is also dependent of your environment.
Maybe you are using &lt;tt class="docutils literal"&gt;project:project&amp;#64;localhost&lt;/tt&gt;, and say &amp;quot;Ok, it's the way it
should be&amp;quot;, but I will tell you : &amp;quot;I don't use a specific MySQL access for each
project, because it's boring to create an access for each project&amp;quot;.&lt;/p&gt;
&lt;p&gt;So, each time you put some code or configuration, the question you must ask to
yourself is : &amp;quot;Is this value specific to my instance, or every instance of the
project will have this value ?&amp;quot;. There will be different instances :
development, staging, testing, production, etc. The source code shouldn't be
aware of physical environment specificities. And also, never ever-ever-never
version something like this :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;serverA:
  host: myhostA
  user: userA
  pass: passA
serverB:
  host: myHostB
  user: userB
  pass: passB
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This is a also a security problem : it means that any developer of the project
will have the production passwords. It also means that on server A, you will have
access informations of server B.&lt;/p&gt;
&lt;p&gt;The &amp;quot;Security-In-Depth&amp;quot; (future article ?) concept applies here, and you have no
valable reason for keeping on server A informations about server B. It's a
security lack.&lt;/p&gt;
&lt;p&gt;Still concerning the security, &lt;strong&gt;no password should be stored&lt;/strong&gt; in version
system : CSRF token, third-service key, etc. All those informations should be
configured
per-instance, and secured somewhere else.&lt;/p&gt;
&lt;p&gt;The main idea is : &lt;strong&gt;If a hacker gets access to your sourcecode repository, he
shouldn't be able to connect to your services&lt;/strong&gt;. He should only be able to do a
a code-review.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="good-practices"&gt;
&lt;h2&gt;Good practices&lt;/h2&gt;
&lt;div class="section" id="atomic-commits"&gt;
&lt;h3&gt;Atomic commits&lt;/h3&gt;
&lt;p&gt;Every commit should be as small as possible (until it makes sense). For example,
if you are developing the feature &amp;quot;User account&amp;quot;, a correct commit-stream could
be :&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;Modelization of user&lt;/li&gt;
&lt;li&gt;Fixtures for user&lt;/li&gt;
&lt;li&gt;Register page&lt;/li&gt;
&lt;li&gt;Login page&lt;/li&gt;
&lt;li&gt;Logout page&lt;/li&gt;
&lt;li&gt;User profile page&lt;/li&gt;
&lt;li&gt;Tests for the user account&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Acting like this, you will be able to review quickly your code and find a given
information, when needed.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="review-before-committing"&gt;
&lt;h3&gt;Review before committing&lt;/h3&gt;
&lt;p&gt;With git, it's very easy, you just have to type &lt;tt class="docutils literal"&gt;git diff &lt;span class="pre"&gt;--staged&lt;/span&gt;&lt;/tt&gt;. With
Subversion : &lt;tt class="docutils literal"&gt;svn diff &amp;lt;files you will commit&amp;gt;&lt;/tt&gt;. A global review often show
you some small mistakes, and will prevent you from committing passwords, useless
code and typo mistakes.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="tagging-the-releases"&gt;
&lt;h3&gt;Tagging the releases&lt;/h3&gt;
&lt;p&gt;Before putting to your production server, you should always tag it, to keep a
trace of the release history. It will allow you to revert to a previous known
state, in case of mistake.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="branching-the-unstable-developments"&gt;
&lt;h3&gt;Branching the unstable developments&lt;/h3&gt;
&lt;p&gt;Branching is very useful when you are developing new features. For example, if
you are developing the comments feature, you will have to make many commits
before stabilizing the feature. But the &lt;tt class="docutils literal"&gt;master&lt;/tt&gt;/&lt;tt class="docutils literal"&gt;trunk&lt;/tt&gt; should always be as
stable as possible.&lt;/p&gt;
&lt;p&gt;So to keep the application stable, create branch for developing feature and
merge it to the &lt;tt class="docutils literal"&gt;master&lt;/tt&gt;/&lt;tt class="docutils literal"&gt;trunk&lt;/tt&gt; when finished.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="external-dependencies"&gt;
&lt;h3&gt;External dependencies&lt;/h3&gt;
&lt;p&gt;When dealing with external dependencies, you shouldn't put in your sourcecode
repository the code coming from other sources. Each versioning system provides
tools for linking to external repositories : &lt;tt class="docutils literal"&gt;svn:externals&lt;/tt&gt; or
&lt;tt class="docutils literal"&gt;.gitmodules&lt;/tt&gt;.&lt;/p&gt;
&lt;p&gt;If you have to deal with Git from SVN of SVN from Git, you should consider
creating a small script (Bash?) that will checkout the external source in an
ignored folder.&lt;/p&gt;
&lt;p&gt;It is also very important to fix the revision of the external library, because
it occurs very often that the external is changing, and this could insert bugs
into your application. With Git modules, you are constrainted to it. With
Subversion, just set the &lt;tt class="docutils literal"&gt;svn:externals&lt;/tt&gt; property to &lt;tt class="docutils literal"&gt;myvendor &lt;span class="pre"&gt;-r445&lt;/span&gt;
&lt;span class="pre"&gt;http://...&lt;/span&gt;&lt;/tt&gt;.&lt;/p&gt;
&lt;p&gt;You should always rely on stable versions, with a version number.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="to-conclude"&gt;
&lt;h2&gt;To conclude&lt;/h2&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;Just version code generated with your brain&lt;/li&gt;
&lt;li&gt;Small commits&lt;/li&gt;
&lt;li&gt;Tag to keep a trace&lt;/li&gt;
&lt;li&gt;Branch when unstable working&lt;/li&gt;
&lt;li&gt;Fix externals&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AlexandreSalome/~4/A-2PTaC3lMg" height="1" width="1"/&gt;</description>
        <feedburner:origLink>http://alexandre-salome.fr/blog/Versioning-A-Project</feedburner:origLink></item>
                <item>
            <title>Blog Opening</title>
            <pubDate>Fri, 08 Jul 2011 00:00:00 +0200</pubDate>
            <link>http://feedproxy.google.com/~r/AlexandreSalome/~3/JYd0tPxq8uk/Blog-Opening</link>
            <guid isPermaLink="false">http://alexandre-salome.fr/blog/Blog-Opening</guid>
            <description>&lt;div class="document"&gt;


&lt;p&gt;After 1 year of development, after 15 versions of Symfony2, the site is ready !&lt;/p&gt;
&lt;div class="section" id="a-new-website"&gt;
&lt;h2&gt;A new website&lt;/h2&gt;
&lt;p&gt;This blog is part of the new version of the site and contains 2 new categories :
&lt;a class="reference external" href="http://alexandre-salome.fr/blog"&gt;Blog&lt;/a&gt; &amp;amp; &lt;a class="reference external" href="http://alexandre-salome.fr/cv"&gt;CV&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;All the website sourcecode is &lt;a class="reference external" href="http://github.com/alexandresalome/Alom"&gt;available on Github&lt;/a&gt;, so if you want to change something,
make a pull-request !&lt;/p&gt;
&lt;p&gt;The old version is still available on &lt;a class="reference external" href="http://alexandre-salome.fr/archives/2009-2011"&gt;http://alexandre-salome.fr/archives/2009-2011&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="a-new-blog"&gt;
&lt;h2&gt;A new blog&lt;/h2&gt;
&lt;p&gt;This blog will be mostly technical. It won't be dedicated to Symfony2/PHP,
it will also talk of versioning a project, general concepts, IT stuff, etc.&lt;/p&gt;
&lt;p&gt;For the opening, 2 fresh articles are available :&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="http://alexandre-salome.fr/blog/Symfony2-Isolation-Of-Tests"&gt;Symfony2 - Isolation of tests&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="http://alexandre-salome.fr/blog/Versioning-A-Project"&gt;Versioning a project&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I still have 10 posts in my pool, I have no precise idea of the rythm for the
posts. If you want to keep in touch, you have 2 solutions :&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;Subscribe to RSS : &lt;a class="reference external" href="http://feeds.feedburner.com/AlexandreSalome"&gt;http://feeds.feedburner.com/AlexandreSalome&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Follow me on twitter : &lt;a class="reference external" href="http://twitter.com/alexandresalome"&gt;http://twitter.com/alexandresalome&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Enjoy !&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AlexandreSalome/~4/JYd0tPxq8uk" height="1" width="1"/&gt;</description>
        <feedburner:origLink>http://alexandre-salome.fr/blog/Blog-Opening</feedburner:origLink></item>
            </channel>
</rss>

