<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Take anything, but my IDE</title>
	<atom:link href="http://blog.webmatters.it/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.webmatters.it</link>
	<description>just another instance of Developer</description>
	<lastBuildDate>Thu, 20 Sep 2012 09:09:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>&lt;canvas&gt; rocks, &lt;video&gt; sucks</title>
		<link>http://blog.webmatters.it/2012/09/canvas-rocks-video-sucks/</link>
		<comments>http://blog.webmatters.it/2012/09/canvas-rocks-video-sucks/#comments</comments>
		<pubDate>Tue, 18 Sep 2012 23:30:49 +0000</pubDate>
		<dc:creator>fmntf</dc:creator>
				<category><![CDATA[Image processing]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.webmatters.it/?p=259</guid>
		<description><![CDATA[When in news.yc I find posts like &#8220;iPhone 5 website teardown: How Apple compresses video using JPEG, JSON, and &#60;canvas&#62;&#8221; I really fall in love. Seriously. So much in love that I need to try it by myself. Hence, VideoCanvas. &#8230; <a href="http://blog.webmatters.it/2012/09/canvas-rocks-video-sucks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When in news.yc I find posts like &#8220;<a href="https://docs.google.com/document/pub?id=1GWTMLjqQsQS45FWwqNG9ztQTdGF48hQYpjQHR_d1WsI">iPhone 5 website teardown: How Apple compresses video using JPEG, JSON, and &lt;canvas&gt;</a>&#8221; I really fall in love.</p>
<p>Seriously. So much in love that I need to try it by myself. Hence, <a href="https://github.com/fmntf/videocanvas">VideoCanvas</a>.<br />
VideoCanvas is a mix of PHP, ffmpeg and ImageMagik.</p>
<p>Starting from a video, it creates an images with all the tiles and an HTML page with hard-coded JSON containing frames info and some JavaScript to start the video.</p>
<p>It relies on ffmpeg to extract video frames in separate images. Then with the ImageMagik extension of PHP it creates a minimum set of tiles to recreate the video in the &lt;canvas&gt;.</p>
<p>Have a look at the <a href="http://acme.webmatters.it/misc/videocanvas/">final result of version 0.1</a>. Here you can find the <a href="http://acme.webmatters.it/misc/videocanvas/source.mp4">source</a> video made with Kazam Screencaster.</p>
<p>(<strong>Edit</strong>: the JS code has been updated to use requestAnimationFrame when available)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.webmatters.it/2012/09/canvas-rocks-video-sucks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://acme.webmatters.it/misc/videocanvas/source.mp4" length="208972" type="video/mp4" />
		</item>
		<item>
		<title>Experimenting PHPADD on Doctrine2</title>
		<link>http://blog.webmatters.it/2012/03/experimenting-phpadd-on-doctrine2/</link>
		<comments>http://blog.webmatters.it/2012/03/experimenting-phpadd-on-doctrine2/#comments</comments>
		<pubDate>Mon, 05 Mar 2012 23:16:06 +0000</pubDate>
		<dc:creator>fmntf</dc:creator>
				<category><![CDATA[PHPADD]]></category>

		<guid isPermaLink="false">http://blog.webmatters.it/?p=254</guid>
		<description><![CDATA[Today I tried to unleash PHPADD over Doctrine2 sources. Of course, it couldn&#8217;t even start: it didn&#8217;t support namespaces. So I had to improve the analysis of tokenized PHP source and now it works. By the way, the report was not satisfying as &#8230; <a href="http://blog.webmatters.it/2012/03/experimenting-phpadd-on-doctrine2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today I tried to unleash PHPADD over Doctrine2 sources.</p>
<p>Of course, it couldn&#8217;t even start: it didn&#8217;t support namespaces. So I had to improve the analysis of tokenized PHP source and now it works.</p>
<p>By the way, the report was not satisfying as I expected. With a big project such Doctrine you understand how much it is important to have a concise report. So now:</p>
<ul>
<li>the parameters are internally indexed by name. This means that it is easy to detect a changed type, but names changes are still seen as &#8220;added param $newName&#8221; + &#8220;removed param $oldName&#8221;.</li>
<li>@inheritdoc is supported.</li>
<li>multiple types (integer|bool $param) are supported.</li>
</ul>
<p>This leads to an almost accurate analysis of Doctrine2 ORM classes:</p>
<p style="padding-left: 30px;"><em>Scanned 261 files with 1672 methods in their classes. 919 methods (55.0%) are regular, 388 methods (23.2%) have no docblock, 365 methods (21.8%) have an outdated docblock.</em></p>
<p>Since these changes are not in the pear channel yet, if you are lazy&amp;curious the report is <a href="http://acme.webmatters.it/misc/doctrine2-orm.html">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.webmatters.it/2012/03/experimenting-phpadd-on-doctrine2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5.3.7 is the best PHP release ever</title>
		<link>http://blog.webmatters.it/2011/09/5-3-7-is-the-best-php-release-ever/</link>
		<comments>http://blog.webmatters.it/2011/09/5-3-7-is-the-best-php-release-ever/#comments</comments>
		<pubDate>Sun, 04 Sep 2011 21:26:28 +0000</pubDate>
		<dc:creator>fmntf</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.webmatters.it/?p=250</guid>
		<description><![CDATA[Before release 5.3.7, PHP was fantastic. It had everything the web needed, built-in. But starting from 5.3.7 something in the interpreter changed: - a stupid regression on crypt() - the knowledge it has only 70% of code covered by tests &#8230; <a href="http://blog.webmatters.it/2011/09/5-3-7-is-the-best-php-release-ever/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Before release 5.3.7, PHP was fantastic. It had everything the web needed, built-in.<br />
But starting from 5.3.7 something in the interpreter changed:<br />
- a stupid regression on crypt()<br />
- the knowledge it has only 70% of code covered by tests<br />
- the knowledge it has almost 200 failing tests<br />
- the knowledge that no one runs tests on it before release</p>
<p>So, now PHP is evil. Personally, I agree with <a href="http://epixa.com/2011/08/how-php-is-broken-and-how-it-can-be-fixed">Anna Filina</a>:</p>
<blockquote><p>This is an insult to all people who work hard at it. The words that you use to describe things are simply baffling. “You” and “them” are the community, and it’s your responsibility as much as theirs.</p></blockquote>
<p>People can improve. The crypt() function can be fixed (ooops, already done). The failing tests can be analized and fixed. The release team can learn to avoid to be embarrassed again. If you understand something that can be improved, you can improve.</p>
<p>For this reason I think PHP 5.3.7 is a great release for self-improvement.<br />
One point for PHP, zero points for stupidity.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.webmatters.it/2011/09/5-3-7-is-the-best-php-release-ever/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPADD 1.3.0</title>
		<link>http://blog.webmatters.it/2011/03/phpadd-1-3-0/</link>
		<comments>http://blog.webmatters.it/2011/03/phpadd-1-3-0/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 09:51:31 +0000</pubDate>
		<dc:creator>fmntf</dc:creator>
				<category><![CDATA[PHPADD]]></category>

		<guid isPermaLink="false">http://blog.webmatters.it/?p=237</guid>
		<description><![CDATA[I just uploaded to the PEAR repository the latest version of PHPADD, which is labeled 1.3.0. From this release I can consider it useful, since it includes the ability of exclude whatever you do not want to scan. In fact, &#8230; <a href="http://blog.webmatters.it/2011/03/phpadd-1-3-0/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just uploaded to the PEAR repository the latest version of PHPADD, which is labeled <code>1.3.0</code>.</p>
<p>From this release I can consider it useful, since it includes the ability of exclude whatever you do not want to scan. In fact, you can exclude from scanning any path, class name or method name.</p>
<p>In Allbus, the company where I work, we have several types of classes that are not so much interesting, like implementations of Factory or View Model patterns.  A Factory creates instances of Services with all the needed collaborator injected, with method names like <code>getVehicleService()</code> &#8211; which is self-explanatory. A View Model selects some fields from the Sacred <a href="http://martinfowler.com/eaaCatalog/domainModel.html">Domain Model</a> and always has just a method, <code>setUp()</code>. Nothing more!</p>
<p>As you can see, in such cases the use of docblocks is tautological. While analyzing what classes need a visit to their docblocks, it is important to have no noise around. Simply leave behind classes that do not introduce logic:</p>
<pre class="brush: bash;">phpadd --exclude-paths application/*/view/model/* ...
phpadd --exclude-classes Factory$ ...
phpadd --exclude-methods ^setUp$ ...</pre>
<p>If you have already installed an older version of PHPADD, you can just run <code>pear upgrade-all</code>. Otherwise, <a href="http://blog.webmatters.it/phpadd/">install it via the repository</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.webmatters.it/2011/03/phpadd-1-3-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPADD: abandoned docblocks detector</title>
		<link>http://blog.webmatters.it/2010/12/phpadd-abandoned-docblocks-detector/</link>
		<comments>http://blog.webmatters.it/2010/12/phpadd-abandoned-docblocks-detector/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 15:27:43 +0000</pubDate>
		<dc:creator>fmntf</dc:creator>
				<category><![CDATA[PHPADD]]></category>

		<guid isPermaLink="false">http://blog.webmatters.it/?p=194</guid>
		<description><![CDATA[Docblocks may become as evil as comments when they&#8217;re not treated as first-class citizens (see: Meaningless docblocks). PHPADD can analyze a directory with PHP source code and detect (for each file, for each class, for each method) if the parameters in &#8230; <a href="http://blog.webmatters.it/2010/12/phpadd-abandoned-docblocks-detector/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>Docblocks may become as evil as comments when they&#8217;re not treated as first-class citizens (see: </em><a href="http://css.dzone.com/articles/meaningless-docblocks">Meaningless docblocks</a><em>).</em></p>
<p><img class="alignright size-full wp-image-201" title="phpadd" src="http://blog.webmatters.it/wp-content/uploads/phpadd-b.png" alt="" width="161" height="231" /><strong>PHPADD</strong> can analyze a directory with PHP source code and detect <em>(for each file, for each class, for each method)</em> if the parameters in the function declaration are compatible with the parameters found in the docblock, <strong>reporting</strong> the <strong>outdated</strong> ones.</p>
<p>This can be easily integrated in your build script and the result can be published in build result. Using Hudson, you just need <em>HTML Publisher</em> plugin.</p>
<p><strong>Install it</strong><br />
With PEAR it is very simple. On Linux, you may need to prefix each command with <code>sudo</code>.</p>
<pre class="brush: bash;">pear channel-discover pear.webmatters.it
pear install webmatters/phpadd</pre>
<p><strong>Try it</strong><br />
Once installed it responds to <code>phpadd</code> from your console.</p>
<pre class="brush: bash;">phpadd --publish-html /tmp/output.html directory/to/analyze</pre>
<p>This command will produce an <a href="http://acme.webmatters.it/misc/phpadd-output.html">output like this</a>.</p>
<p>Please note, phpadd has to be improved. For example, it needs to ignore warning on files/classes/methods matching a given regular expression (controller classes, for example).<br />
Or the difference between docblock params and function params: it is not so smart.<br />
If you want to help, <a href="https://github.com/fmntf/phpadd">fork it on GitHub</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.webmatters.it/2010/12/phpadd-abandoned-docblocks-detector/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>BannedComboItems: ComboBox with disabled items</title>
		<link>http://blog.webmatters.it/2010/11/bannedcomboitems-combobox-with-disabled-items/</link>
		<comments>http://blog.webmatters.it/2010/11/bannedcomboitems-combobox-with-disabled-items/#comments</comments>
		<pubDate>Sun, 28 Nov 2010 18:02:25 +0000</pubDate>
		<dc:creator>fmntf</dc:creator>
				<category><![CDATA[ExtJS extensions]]></category>
		<category><![CDATA[User experience]]></category>

		<guid isPermaLink="false">http://blog.webmatters.it/?p=175</guid>
		<description><![CDATA[Combos are beasts. Beasts for developers (400 lines of ugly configuration) and beasts for customers. For some business logic, you may not select some elements. What to do in these cases? If you do not put unselectable items in the &#8230; <a href="http://blog.webmatters.it/2010/11/bannedcomboitems-combobox-with-disabled-items/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://acme.webmatters.it/extamples/BannedComboItems/"><img class="alignleft size-full wp-image-181" title="BannedComboItems plugin" src="http://blog.webmatters.it/wp-content/uploads/bannedcomboitems1.png" alt="" width="383" height="174" /></a><strong>Combos are beasts</strong>. Beasts for developers (400 lines of <a href="http://twitter.com/#!/_jdg/status/3077874785460224">ugly</a> configuration) and beasts for customers.<br />
For some business logic, you may not select some elements. What to do in these cases?</p>
<p>If you do not put unselectable items in the combo, your customers will say you: &#8220;<em>Why can&#8217;t I see raspberries in the list? I&#8217;m sure I added them to the system</em>&#8220;.<br />
And if you put everything in the combo, they will say you &#8220;<em>Oh, that&#8217;s too much, why do I see all this useless stuff?</em>&#8220;.</p>
<p>But wait for a moment, we already solved this problem 20 years ago in menus!<br />
<span id="more-175"></span>In the menu of an application you see everything, but you can select only some items.</p>
<p>This plugin replicates this behaviour: <strong>it grays out unselectable items</strong>. And since it is simple to do in ExtJS, it provides a qtip with the reason of that status.<br />
<strong> You just need to provide a little more detailed store</strong>. In this example we have:</p>
<pre class="brush: jscript;">{
	'id': 2,
	'label': 'Raspberries',
	'banned': true,
	'banReason': 'Not available in this season.'
}</pre>
<p>Play with the <a href="http://acme.webmatters.it/extamples/BannedComboItems/">example</a> or <a href="http://acme.webmatters.it/extamples/BannedComboItems/BannedComboItems.zip">download the sources</a>. And last but not least, thanks to <a href="http://twitter.com/pins983">Gianluca</a> for the idea.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.webmatters.it/2010/11/bannedcomboitems-combobox-with-disabled-items/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Git tips and tricks</title>
		<link>http://blog.webmatters.it/2010/11/git-tips-and-tricks/</link>
		<comments>http://blog.webmatters.it/2010/11/git-tips-and-tricks/#comments</comments>
		<pubDate>Wed, 24 Nov 2010 17:20:54 +0000</pubDate>
		<dc:creator>fmntf</dc:creator>
				<category><![CDATA[Git]]></category>

		<guid isPermaLink="false">http://blog.webmatters.it/?p=154</guid>
		<description><![CDATA[Display the active branch in the terminal prompt Add this line to ~/.bashrc PS1='\u@\h:\w$(__git_ps1 " (%s)")\$ ' Automatic add during commit git commit -am "message" It automatically adds already versioned files to the index before commit. This will automatically remove &#8230; <a href="http://blog.webmatters.it/2010/11/git-tips-and-tricks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Display the active branch in the terminal prompt</strong><br />
Add this line to <code>~/.bashrc</code><br />
<code style="margin-left: 20px;">PS1='\u@\h:\w$(__git_ps1 " (%s)")\$ '</code></p>
<p><strong>Automatic add during commit</strong><br />
<code style="margin-left: 20px;">git commit -am "message"</code><br />
It automatically adds <em>already </em>versioned files to the index before commit. This will automatically remove file disappeared from the filesystem. Untracked files will <strong>not</strong> be added.</p>
<p><strong>Add to the index just some part of a file</strong><br />
<code style="margin-left: 20px;">git add --patch</code><br />
For each chunk, you can type: <strong>y</strong> (stage it), <strong>n</strong> (do not stage it), <strong>q</strong> (do not stage &amp; quit)</p>
<p><strong>Interactive index add</strong><br />
<code style="margin-left: 20px;">git add --interactive</code><br />
This UI has Super Cow Powers. Go in update mode with <strong>u</strong>pdate. Now type:</p>
<p style="margin-left: 15px;">1     to add the first file to the index<br />
1-3 to add files 1, 2 and 3 to the index<br />
-1   to unstage first file</p>
<p>To go back into &#8220;what now&#8221; mode, press Enter. With <strong>r</strong>evert mode you can restore a file as it is in HEAD. For other modes, type <strong>h</strong>elp.</p>
<p><strong>Undo a commit</strong><br />
To go back to the previous state<br />
<code style="margin-left: 20px;">git reset --soft HEAD^</code><br />
Fix what was wrong and commit from the discarded commit (ORIG_HEAD)<br />
<code style="margin-left: 20px;">git commit -c ORIG_HEAD</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.webmatters.it/2010/11/git-tips-and-tricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ext.Ajax on steroids [AuthorizedAjax]</title>
		<link>http://blog.webmatters.it/2010/11/ext-ajax-on-steroids-authorizedajax/</link>
		<comments>http://blog.webmatters.it/2010/11/ext-ajax-on-steroids-authorizedajax/#comments</comments>
		<pubDate>Wed, 10 Nov 2010 22:28:19 +0000</pubDate>
		<dc:creator>fmntf</dc:creator>
				<category><![CDATA[Domain specific languages]]></category>
		<category><![CDATA[ExtJS extensions]]></category>

		<guid isPermaLink="false">http://blog.webmatters.it/?p=144</guid>
		<description><![CDATA[In the company I work for we use ExtTop, the Windows-like desktop environment which provides icons, taskbar and start menu. It is a single page web application. You can open all the windows you want, but you will never reload &#8230; <a href="http://blog.webmatters.it/2010/11/ext-ajax-on-steroids-authorizedajax/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In the company I work for we use ExtTop, the Windows-like desktop environment which provides icons, taskbar and start menu. It is a single page web application. You can open all the windows you want, but you will never reload the page.</p>
<p>We want to log users off after one hour of inactivity. If your user session is destroyed and you try to open a form, you should be warned that you cannot continue and <strong>you will be invited to log in again</strong>.</p>
<p>That&#8217;s very simple. For each <code>Ext.Ajax</code> request, you should check that you are still in, if not, open a login form and if the server accepts your credentials, continue. For each request. For each request. For each request. [...]</p>
<p>That repetition sucks. What could we do?</p>
<ul>
<li>copy and paste all the code, in every <code>Ext.Ajax.request()</code></li>
<li>create a <code>detectIfLoggedOf()</code> function and call it in every <code>success()</code> callback of <code>Ext.Ajax.request()</code></li>
<li>define a new <code>Ext.Ajax</code> that do everything.</li>
</ul>
<p>Since you should spend your time writing a strong  web application, let&#8217;s discard option 1 and 2. <strong>AuthorizedAjax</strong> is option 3.</p>
<p>Please keep in mind this is more a proof of concept rather than a real implementation. There is no documentation (yet?). <strong>See the <a href="http://acme.webmatters.it/extamples/AuthorizedAjax/">example</a></strong> and read it&#8217;s configuration file.<br />
<span id="more-144"></span></p>
<p><strong>How it works</strong><br />
Your server must send special headers if something unusual happens (for example, the user is not logged in or the ACL system denied the access). Then you tell <code>AuthorizedAjax</code> how the server can answer, and what to do in that cases.</p>
<p>If the server will not send any special header, <code>AuthorizedAjax</code> will behave as <code>Ext.Ajax</code> &#8211; otherwise, something (configurable) will be executed.</p>
<p><strong>Conclusion</strong><br />
I repeat, this is just a proof of concept of a domain specific language. &#8220;Dear system, this case may happen, and in that case you will do this&#8221; (action-reaction). A DSL applied to something more complex is powerful &#8211; it allows everyone to configure a system, just knowing how the system works and nothing about programming.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.webmatters.it/2010/11/ext-ajax-on-steroids-authorizedajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Once upon a time&#8230;</title>
		<link>http://blog.webmatters.it/2010/11/once-upon-a-time/</link>
		<comments>http://blog.webmatters.it/2010/11/once-upon-a-time/#comments</comments>
		<pubDate>Mon, 01 Nov 2010 10:23:14 +0000</pubDate>
		<dc:creator>fmntf</dc:creator>
				<category><![CDATA[Things you must know]]></category>

		<guid isPermaLink="false">http://blog.webmatters.it/?p=105</guid>
		<description><![CDATA[This post is all about testing. If you are already testing your code, you can skip it. Imagine PHP without the in_array() function: you need it, so you have to write it: function inArray($needle, array $haystack) { foreach (...) { ... &#8230; <a href="http://blog.webmatters.it/2010/11/once-upon-a-time/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>This post is all about testing. If you are already testing your code, you can skip it.</em></p>
<p>Imagine PHP without the <code>in_array()</code> function: you need it, so you have to write it:</p>
<pre class="brush: php;">function inArray($needle, array $haystack)
{
	foreach (...) { ... }
	return $found;
}</pre>
<p>Then you check if it works:</p>
<pre class="brush: php;">$array = array(4, 8, 15, 16, 23, 42);
var_dump(inArray(2, $array));
var_dump(inArray(16, $array));</pre>
<p>You see that everything works as expected, you throw away the three lines above and commit your code. It works, afterall!</p>
<p><span id="more-105"></span><br />
Considerations:<br />
- you spent some time to write a manual, use-and-throw test;<br />
- if your code changes, for example you implement the third optional parameter <code>strict</code>, you have to test the old functionalities (<strong>déjà vu</strong>) and the new ones;<br />
- you can&#8217;t make predictions about code&#8217;s immutability (and often, it changes).</p>
<div id="attachment_122" class="wp-caption alignright" style="width: 310px"><img class="size-medium wp-image-122" title="LOST system failure" src="http://blog.webmatters.it/wp-content/uploads/systemfailure-300x166.jpg" alt="LOST system failure" width="300" height="157" /><p class="wp-caption-text">They could automate the execute button pushing</p></div>
<p><strong>Use automated testing</strong><br />
Testing your code by hand is nice (you show that it works &#8212; at least for now), but if your computer does it for you, it is nicer. All you have to do is to explain how your software should work by writing a (reusable) test. You are slower to execute tests, you can forget to do it, you may do mistakes while doing it. A computer won&#8217;t.</p>
<p><em>Def.</em>: <strong>A test is an executable specification </strong>for your software that you write once and execute whenever you like. In a test you setup an environment needed by the SUT (system under test), you exercise the SUT and you do some assertions on the results.</p>
<p>Now that you know <em>what </em>and <em>why</em>, let&#8217;s be more practical. First, <a href="http://www.phpunit.de/manual/current/en/installation.html">install PHPUnit</a>. Now suppose that the above <code>inArray()</code> definition is contained in the file <code>InArray.php.</code><br />
Create a file named <code>InArrayTest.php</code> with this content:</p>
<pre class="brush: php;">&lt;?php
include('InArray.php');
class InArrayTest extends PHPUnit_Framework_TestCase
{
	public function testFindsExistingElements()
	{
		// setup
		$array = array(4, 8, 15, 16, 23, 42);
		// try the system
		$elementInArray = inArray(16, $array);
		// check results
		$this-&gt;assertTrue($elementInArray);
	}

	public function testWontFindUnexistingElements()
	{
		$array = array(4, 8, 15, 16, 23, 42);
		$elementInArray = inArray(16, $array);
		$this-&gt;assertFalse($elementInArray);
	}
}</pre>
<p>You just defined the container for the tests of your <code>inArray()</code> function &#8211; the <code>InArrayTest</code> class. PHPUnit will search in it for public functions starting with test*() and will execute them. In other words, a class for each thing to test (thing is for: a class, a function, an Ext window, &#8230;), a method for each group of assertions.</p>
<p>In these functions (&#8220;tests&#8221;):<br />
1) you will prepare the environment the SUT will need (for example: creating sample data, instantiating a collaborator, opening an ExtJS window of the application);<br />
2) you will exercise your SUT (<code>inArray</code>, in our case);<br />
3) you will check that everything works as expected with <a href="http://www.phpunit.de/manual/current/en/api.html#api.assert">assertions</a>. You can check that a variable is true (<code>assertTrue</code>), that a variable has a known value (<code>assertEquals</code>), and so on.</p>
<p><strong>This is the same way you would do by hand. </strong>To test our function, we have 1) built a sample array, 2) called <code>inArray</code> on it and 3) printed the result and we have thought: &#8220;it returns true and I wanted it to be true.. it works&#8221;.</p>
<p>To run your test file, you can type:</p>
<pre class="brush: bash;">$ phpunit --testdox InArrayTest.php
PHPUnit 3.5.0 by Sebastian Bergmann.

InArray
 [x] Finds existing elements
 [x] Wont find unexisting elements</pre>
<p>Note: we created two tests, for two functionalities. This is ok for fast tests, but if the test setup takes seconds (for example you are creating a database with data, or you are asking Selenium to open a browser to test your ExtJS application) you should check more things in a single test.<br />
That should be avoided when possible, but done to keep test execution time low (when you change some code, you want a fast feedback).</p>
<p><strong>An important result</strong><br />
Now that you stuck your specifications in an executable format, you can refactor/add functionalities to your SUT being sure <strong>not to introduce regressions</strong> &#8211; if you break something, at least a test will fail.</p>
<p>How many time you said: &#8220;why this code? it could be simpler&#8221; or &#8220;this happens because that function is called here, but it shouldn&#8217;t happen, let&#8217;s remove the call&#8221;? And each time you fixed a bug, but you destroyed something else.</p>
<p><strong>Golder rules</strong><br />
&gt; Remember to test <strong>everything</strong> that is important, and skip what is not necessary. Cover all the possible cases with your tests.</p>
<p>&gt; If you cover all the cases of interest, you are in a safe place. You can fix bugs without break other things, you can fix bugs on your in-production software without stress (the test suite passes? no regressions, you can deploy). In other words, with tests you will always <strong>know what works and what not</strong>.</p>
<p>&gt; If you find a bug, write a test to reproduce that bug. Then make the test pass, fixing the bug. Has your supervisor ever shouted you &#8220;why this problem still occurs?&#8221; or not?</p>
<p><strong>Selenium</strong><br />
Selenium Remote Control is a server that accepts requests like &#8220;open the page at <code>$url</code>&#8220;, &#8220;click on element with selector <code>#mybutton</code>&#8221; and it lets you see the DOM.<br />
To execute your requests, it opens a browser (or a set of browsers, if you want), it loads your page and executes your commands. All this (almost) at the speed of light.<br />
Download it from <a href="http://selenium.googlecode.com/files/selenium-remote-control-1.0.3.zip">here</a> and run it with <code>java -jar selenium-server.jar</code>.</p>
<p>You will give commands to Selenium via PHPUnit. To do this, you have to extend <code>PHPUnit_Extensions_SeleniumTestCase</code> or <code>ExtDiamond_TestCase</code> (which extends the first).<br />
See this <a href="http://www.phpunit.de/manual/current/en/selenium.html#selenium.seleniumtestcase.examples.WebTest.php">example</a>: we are asking Selenium to open a certain URL and to check the page title. See Selenium API to check out other useful methods.</p>
<p><strong>Rich Internet Applications</strong><br />
Testing a web site is simple &#8211;  you do some asserts on some elements. Complicate things may only be forms population and submit.<br />
For example, you tell to Selenium to open <code>shownews.php?newsid=1</code> and you assert that <code>div#title</code>, <code>div#introduction</code> and <code>img.articlecategory</code> elements all have some content. Done.</p>
<p>Testing web applications is harder. You will need to click on some elements, that will open some windows, you will interact with them and then you will do some assertions on the DOM. That is generally more complicate.</p>
<p>ExtDiamond aims to make this simple. See the grid ExtDiamond <a href="http://github.com/fmntf/ExtDiamond/blob/master/Example/tests/GridTest.php">example</a>. The page under test automatically renders a window with class <code>firewall-window</code>. If the window would not be automatically displayed, you could call</p>
<pre class="brush: php;">$this-&gt;click('css=div.something-that-will-open-window');</pre>
<p>In both cases you have the opened window, at line 30 we get it&#8217;s reference. Then on line 32 we get the value of the title property (on the <code>Ext.Window</code> object) and we check that it&#8217;s value is correct. As alternative way, you can access the DOM of the window and assert on the title on the DOM.</p>
<p>Read the ExtDiamond presentation to find out which ways is better depending on your case. I also recommend you to scan PHPUnit, Selenium and ExtDiamond APIs.</p>
<p style="text-align: right;">&#8230; happily until their <span style="text-decoration: line-through;">assertion failures</span> deaths.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.webmatters.it/2010/11/once-upon-a-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ExtDiamond 1.1</title>
		<link>http://blog.webmatters.it/2010/10/extdiamond-1-1/</link>
		<comments>http://blog.webmatters.it/2010/10/extdiamond-1-1/#comments</comments>
		<pubDate>Mon, 25 Oct 2010 20:15:46 +0000</pubDate>
		<dc:creator>fmntf</dc:creator>
				<category><![CDATA[ExtDiamond]]></category>

		<guid isPermaLink="false">http://blog.webmatters.it/?p=78</guid>
		<description><![CDATA[This is a minor release, with a little but important functionality. Download it on GitHub! What changed ExtDiamond is shipped with some built-in widgets. Right now we have only GridPanel and Form.Field, but we hope to have something more in &#8230; <a href="http://blog.webmatters.it/2010/10/extdiamond-1-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is a minor release, with a little but important functionality. <a href="http://github.com/fmntf/ExtDiamond">Download it</a> on GitHub!</p>
<p><strong>What changed</strong><br />
ExtDiamond is shipped with some built-in widgets. Right now we have only GridPanel and Form.Field, but we hope to have something more in the future.<br />
By the way, you application may use non-standard widgets (meaning: not provided with ExtJS) that you developed by yourself or bought from someone.</p>
<p>In these cases, you <em>may</em> need to define your own widget reference classes, especially if your component is complicated.<br />
This release allows you to register a path where ExtDiamond will search your own widget classes, that will be loaded when you call <code>handleAs()</code> on your references.</p>
<p>Now that all the original functionalities are completed, I will concentrate my time on new features.<br />
Finally, I want to notify you that <a href="http://blog.webmatters.it/extdiamond/api/">ExtDiamond API</a> is available.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.webmatters.it/2010/10/extdiamond-1-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
