<?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>Senses: A blog about the Thirdi Software perception &#187; unit testing</title>
	<atom:link href="http://senses.thirdi.com/tags/unit-testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://senses.thirdi.com</link>
	<description>Welcome to Senses: a place for Thirdi Software to explore what's seen, heard, and felt about technology, software development, and life experiences.</description>
	<lastBuildDate>Tue, 27 Jul 2010 16:42:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Quality Software @ Thirdi &#8211; Factory Method Pattern</title>
		<link>http://senses.thirdi.com/posts/1030-quality-software-thirdi-factory-method-pattern/</link>
		<comments>http://senses.thirdi.com/posts/1030-quality-software-thirdi-factory-method-pattern/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 18:11:31 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[Quality Software]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://senses.thirdi.com/?p=1030</guid>
		<description><![CDATA[Software Design Patterns are solutions to common problems that can be applied when developing software. They are well known and understood solutions to regular programming problems.
The factory method pattern is a design pattern for creating objects. The factory is responsible for creating objects, that is, using the new keyword. Every time you create objects of [...]


Related posts:<ol><li><a href='http://senses.thirdi.com/posts/1498-quality-software-thirdi-php-53/' rel='bookmark' title='Permanent Link: Quality Software @ Thirdi &#8211; PHP 5.3'>Quality Software @ Thirdi &#8211; PHP 5.3</a></li>
<li><a href='http://senses.thirdi.com/posts/968-quality-software-thirdi-symfony-checklist/' rel='bookmark' title='Permanent Link: Quality Software @ Thirdi &#8211; Symfony Checklist'>Quality Software @ Thirdi &#8211; Symfony Checklist</a></li>
<li><a href='http://senses.thirdi.com/posts/1892-quality-software-thirdi-mega-drop-down-navigation-menus/' rel='bookmark' title='Permanent Link: Quality Software @ Thirdi &#8211; Mega Drop-Down Navigation Menus'>Quality Software @ Thirdi &#8211; Mega Drop-Down Navigation Menus</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29">Software Design Patterns</a> are solutions to common problems that can be applied when developing software. They are well known and understood solutions to regular programming problems.</p>
<p>The factory method pattern is a design pattern for creating objects. The factory is responsible for creating objects, that is, using the <strong>new</strong> keyword. Every time you create objects of a certain type you delegate the task to the factory.</p>
<p>Lets say we have a system that can invite contacts from different email providers. The factory code would look like something like this in PHP:</p>
<pre><span style="font-family: courier new,monospace;">class InviterFactory
{
  public static function getInviter($type)
  {
    switch ($type)
    {
    case 'gmail':
      $inviter = new GmailInviter();
      break;
    case 'hotmail':
      $inviter = new HotmailInviter();
      break;
    case 'yahoo':
      $inviter = new YahooInviter();
      break;
    default:
      $inviter = null;
    }

    return $inviter;
  }
}</span></pre>
<p>In the future, if we ever add another email provider, say, canada.com, we would only have to add the CanadaInviter to the factory class, and our whole project is now ready to use this type of inviter.</p>
<p>The factory pattern is also good for <a href="http://googletesting.blogspot.com/2008/08/by-miko-hevery-so-you-decided-to.html">unit testing</a>. In unit testing we want to completely be able to control a small section of the program to test all possible inputs and outputs. When testing a section of code that uses the factory to create objects, we can replace the standard factory with a unit-test factory, that returns dummy objects with only enough functionality required for testing that component.</p>
<p>Factory methods promote encapsulation. In our example each of the inviters have the same functionality to retrieving a contact list from the provider, but implement it differently.</p>
<pre><span style="font-family: courier new,monospace;">interface Inviter
{
  public function getContacts();
}

class GmailInviter implements Inviter
{
  public function getContacts()
  {
    // code to get contacts
    return $contacts;
  }
}

class HotmailInviter implements Inviter
{
  public function getContacts()
  // ...
}</span></pre>
<p>Now you can add the factory pattern to your programming tool belt. Note, this is just example code, real code has comments and error checking.</p>


<p>Related posts:<ol><li><a href='http://senses.thirdi.com/posts/1498-quality-software-thirdi-php-53/' rel='bookmark' title='Permanent Link: Quality Software @ Thirdi &#8211; PHP 5.3'>Quality Software @ Thirdi &#8211; PHP 5.3</a></li>
<li><a href='http://senses.thirdi.com/posts/968-quality-software-thirdi-symfony-checklist/' rel='bookmark' title='Permanent Link: Quality Software @ Thirdi &#8211; Symfony Checklist'>Quality Software @ Thirdi &#8211; Symfony Checklist</a></li>
<li><a href='http://senses.thirdi.com/posts/1892-quality-software-thirdi-mega-drop-down-navigation-menus/' rel='bookmark' title='Permanent Link: Quality Software @ Thirdi &#8211; Mega Drop-Down Navigation Menus'>Quality Software @ Thirdi &#8211; Mega Drop-Down Navigation Menus</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://senses.thirdi.com/posts/1030-quality-software-thirdi-factory-method-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit Testing &#8211; Autoload Classes</title>
		<link>http://senses.thirdi.com/posts/12-unit-testing-autoload-classes/</link>
		<comments>http://senses.thirdi.com/posts/12-unit-testing-autoload-classes/#comments</comments>
		<pubDate>Mon, 12 May 2008 23:47:06 +0000</pubDate>
		<dc:creator>Stanley</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[lazy]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony tip]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://senses.thirdi.com/posts/12-unit-testing-autoload-classes/</guid>
		<description><![CDATA[I like test driven development. I don&#8217;t like adding required files to test script manually because it&#8217;s tedious and I am lazy. I really like Symfony&#8217;s autoloading feature. Unfortunately, this feature is not available for running unit tests. Running symfony test-unit without including any of the required files, tests will not run.
Fortunately, there is an [...]


Related posts:<ol><li><a href='http://senses.thirdi.com/posts/2870-unit-tests-vs-functional-tests/' rel='bookmark' title='Permanent Link: Unit Tests vs. Functional Tests'>Unit Tests vs. Functional Tests</a></li>
<li><a href='http://senses.thirdi.com/posts/11-my-laziness-and-sfpropelmigrationslightplugin/' rel='bookmark' title='Permanent Link: My Laziness and sfPropelMigrationsLightPlugin'>My Laziness and sfPropelMigrationsLightPlugin</a></li>
<li><a href='http://senses.thirdi.com/posts/1030-quality-software-thirdi-factory-method-pattern/' rel='bookmark' title='Permanent Link: Quality Software @ Thirdi &#8211; Factory Method Pattern'>Quality Software @ Thirdi &#8211; Factory Method Pattern</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I like test driven development. I don&#8217;t like adding required files to test script manually because it&#8217;s tedious and I am lazy. I really like Symfony&#8217;s autoloading feature. Unfortunately, this feature is not available for running unit tests. Running <em>symfony test-unit</em> without including any of the required files, tests will not run.</p>
<p>Fortunately, there is an elegant solution. The idea is based on the Symfony CLI environment. At the top of the test script, add the following lines (or put them in a file and include that file):</p>
<p><em><strong>&lt;?php<br />
require_once &#8216;PHPUnit/Framework.php&#8217;;</strong></em></p>
<p><em><strong>define(&#8216;SF_ROOT_DIR&#8217;,      realpath(dirname(__file__).&#8217;/../..&#8217;));<br />
define(&#8216;SF_APP&#8217;,           &#8216;frontend&#8217;);<br />
define(&#8216;SF_ENVIRONMENT&#8217;,   &#8216;cli&#8217;);<br />
define(&#8216;SF_DEBUG&#8217;,          false);</strong></em></p>
<p><em><strong>require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.&#8217;apps&#8217;.<br />
DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.&#8217;config&#8217;.<br />
DIRECTORY_SEPARATOR.&#8217;config.php&#8217;);<br />
?&gt;</strong></em></p>
<p>These lines should be familiar if you have worked with Symfony CLI. Basically, they are boilerplate code for any Symfony CLI app. With any luck, Symfony should load classes for you automagically.</p>


<p>Related posts:<ol><li><a href='http://senses.thirdi.com/posts/2870-unit-tests-vs-functional-tests/' rel='bookmark' title='Permanent Link: Unit Tests vs. Functional Tests'>Unit Tests vs. Functional Tests</a></li>
<li><a href='http://senses.thirdi.com/posts/11-my-laziness-and-sfpropelmigrationslightplugin/' rel='bookmark' title='Permanent Link: My Laziness and sfPropelMigrationsLightPlugin'>My Laziness and sfPropelMigrationsLightPlugin</a></li>
<li><a href='http://senses.thirdi.com/posts/1030-quality-software-thirdi-factory-method-pattern/' rel='bookmark' title='Permanent Link: Quality Software @ Thirdi &#8211; Factory Method Pattern'>Quality Software @ Thirdi &#8211; Factory Method Pattern</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://senses.thirdi.com/posts/12-unit-testing-autoload-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
