<?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>Binary Thinking</title>
	<atom:link href="http://blog.karolsojko.com/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.karolsojko.com</link>
	<description>Karol Sójko&#039;s blog</description>
	<lastBuildDate>Sat, 06 Apr 2013 10:26:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>BDD is not for control freaks</title>
		<link>http://blog.karolsojko.com/index.php/2013/02/bdd-is-not-for-control-freaks/</link>
		<comments>http://blog.karolsojko.com/index.php/2013/02/bdd-is-not-for-control-freaks/#comments</comments>
		<pubDate>Sat, 09 Feb 2013 18:16:00 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[code coverage]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[report]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=836</guid>
		<description><![CDATA[Tweet Code coverage &#8211; it&#8217;s not good for you When I see people trying to embrace the concept of BDD, most of the time they will try to apply on it everything that they&#8217;ve learned in TDD.  Remember though that BDD is in fact TDD but done right &#8211; so stop dragging along all the bad ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2013/02/bdd-is-not-for-control-freaks/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton836" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2013%2F02%2Fbdd-is-not-for-control-freaks%2F&amp;via=karolsojko&amp;text=%23BDD%20is%20not%20for%20control%20freaks&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2013%2F02%2Fbdd-is-not-for-control-freaks%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2013/02/bdd-is-not-for-control-freaks/" size="standard"></g:plusone></div><h1 style="text-align: justify;"><a href="http://blog.karolsojko.com/wp-content/uploads/2013/02/3sx5eo1.jpg"><img class="aligncenter size-full wp-image-843" alt="3sx5eo" src="http://blog.karolsojko.com/wp-content/uploads/2013/02/3sx5eo1.jpg" width="600" height="546" /></a></h1>
<h1 style="text-align: justify;">Code coverage &#8211; it&#8217;s not good for you</h1>
<p style="text-align: justify;">When I see people trying to embrace the concept of BDD, most of the time they will try to apply on it everything that they&#8217;ve learned in TDD.  Remember though that BDD is in fact TDD but done right &#8211; so stop dragging along all the bad habbits that BDD is trying the leave behind. The most common case pointed out is the lack of code coverage and tools for reporting it. If you are one of those people I&#8217;ve got bad news for you &#8211; code coverage is not a good metric.</p>
<h2 style="text-align: justify;">Clean cut test hero</h2>
<p style="text-align: justify;">So why is it so bad and why is there no value added with those code coverage reports? You might argue that as a developer you feel very safe and secure when every line of code is tested and you have your CI environment to prove that. Stop! If you&#8217;re feeling insecure about the code without your coverage reports &#8211; that means you didn&#8217;t write it good. It may have as many tests as you want but ask yourself those 3 questions:</p>
<ul style="text-align: justify;">
<li><span style="line-height: 13px;">Does it do what I expect it to do?</span></li>
<li>Do I know what is it expected to do? - <em>oh legacy&#8230; </em></li>
<li>Do I feel confident changing something that gazillion regression tests prove is ok?</li>
</ul>
<h2 style="text-align: justify;">Oh coverage, guide my path</h2>
<p style="text-align: justify;">I hope you can see the problem here. The issue is that TDD has started being done wrong (some people do it right!) and in most cases the tests are very code-focused (<em>duh!</em>). What I mean is that developers tend to put their effor in writting tests about how the internals of functions work or how this data structure looks like etc. This is a dead end. I&#8217;ve seen dozens of tests just testing setters and getters and a bunch of redundant stuff. You might&#8217;ve seen that as well and I think by this point you know why. Obviously they are just an attempt to satisfy the gods of code coverage.</p>
<p style="text-align: justify;"><a href="http://blog.karolsojko.com/wp-content/uploads/2013/02/3sx5b2.jpg"><img class="aligncenter size-full wp-image-840" alt="3sx5b2" src="http://blog.karolsojko.com/wp-content/uploads/2013/02/3sx5b2.jpg" width="625" height="448" /></a></p>
<h2 style="text-align: justify;"><em>How can you have any pudding if you don&#8217;t eat your meat?</em></h2>
<p style="text-align: justify;">The feeling I&#8217;ve got is that TDD has gotten very code-centric instead of client-centric and it has drifted strongly from it&#8217;s best practices. It&#8217;s has become a domain of people who are more about code coverage reports, building over-complicated architecture and verifying stuff instead of focusing to deliver software that does what is expected, is self-explanatory and has clear rules of communicating with other software. Most often tests are so tightly checking the code itself that it disables refactoring. BDD is about the code being flexible and understanding that it changes overtime &#8211; this is a living organism. The only thing is to maintain it to do what expected and allow it to refactor itself for example according to <a title="The Boy Scout Rule" href="http://programmer.97things.oreilly.com/wiki/index.php/The_Boy_Scout_Rule" target="_blank">the boy scout rule</a>.</p>
<h1 style="text-align: justify;">Don&#8217;t worry be happy</h1>
<p style="text-align: justify;">What BDD does to you is that it makes you think about what your software delivers. What story does it tell ? What have you specified it to do and what examples have you given ? In that approach you don&#8217;t need any coverage report. You&#8217;ve written a code that does what you expect it to do &#8211; moreover you have the freedom and flexibility of refactoring it. Believe me when I say I sleep better at night knowing that my code does what it should do and not carrying about the percentage of my code coverage.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2013/02/bdd-is-not-for-control-freaks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Pitfalls of mocking</title>
		<link>http://blog.karolsojko.com/index.php/2012/12/pitfalls-of-mocking/</link>
		<comments>http://blog.karolsojko.com/index.php/2012/12/pitfalls-of-mocking/#comments</comments>
		<pubDate>Sun, 23 Dec 2012 09:45:58 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHPSpec]]></category>
		<category><![CDATA[PHPUnit]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[Mock]]></category>
		<category><![CDATA[Mocking]]></category>
		<category><![CDATA[Spec]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=797</guid>
		<description><![CDATA[Tweet DISCLAIMER: The problem described below has been fixed by the mocking framework Prophecy. Thank @_md and @everzet on Twitter. Lately I&#8217;m doing some quite extensive specing with PHPSpec. Of course when you do BDD or TDD you always have to mock your dependencies. Mocks can be very effective but they have a serious flaw ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2012/12/pitfalls-of-mocking/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton797" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F12%2Fpitfalls-of-mocking%2F&amp;via=karolsojko&amp;text=Pitfalls%20of%20mocking&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F12%2Fpitfalls-of-mocking%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2012/12/pitfalls-of-mocking/" size="standard"></g:plusone></div><p style="text-align: justify;"><a href="http://blog.karolsojko.com/wp-content/uploads/2012/12/star_wars_its_a_trap_wallpapers-1680x1050.jpg"><img class="aligncenter  wp-image-823" alt="star_wars_its_a_trap_wallpapers-1680x1050" src="http://blog.karolsojko.com/wp-content/uploads/2012/12/star_wars_its_a_trap_wallpapers-1680x1050-1024x572.jpg" width="614" height="343" /></a></p>
<p style="text-align: justify;"><strong>DISCLAIMER:</strong> The problem described below has been fixed by the mocking framework <a title="Prohpecy" href="https://github.com/phpspec/prophecy" target="_blank">Prophecy</a>. Thank <a title="Marcello Duarte" href="https://twitter.com/_md" target="_blank">@_md</a> and <a title="Konstantin Kudryashov" href="https://twitter.com/everzet" target="_blank">@everzet</a> on Twitter.</p>
<p style="text-align: justify;">Lately <a title="PHPSpec – How I’ve stopped testing and started specifying" href="http://blog.karolsojko.com/index.php/2012/12/phpspec-how-ive-stopped-testing-and-started-specifying/" target="_blank">I&#8217;m doing some quite extensive specing</a> with PHPSpec. Of course when you do BDD or TDD you always have to mock your dependencies. Mocks can be very effective but they have a serious flaw which can leave your code in bad state. Working the other day on some specs with a colleague of mine we&#8217;ve runned into a curious situation. When you do a lot of mocking you can accidentally mock methods that don&#8217;t exist and even forget about implementing them. Obviously the specs will run as expected so you won&#8217;t even know that the code doesn&#8217;t work.</p>
<p style="text-align: justify;">This is a common problem for <a title="PHPSpec" href="http://www.phpspec.net/" target="_blank">PHPSpec</a> and <a title="PHPUnit" href="http://www.phpunit.de/manual/current/en/index.html" target="_blank">PHPUnit</a> (<a title="Mock expectations shouldn't be allowed on non existent methods" href="https://github.com/sebastianbergmann/phpunit-mock-objects/issues/21">issue</a>) as well. So without further ado</p>
<h1 style="text-align: justify;">The example</h1>
<pre class="brush: php; title: ; notranslate">

// spec for classA
...
$classBCollection = array(...);
$mock-&gt;beAMockOf('\ClassBRetriever');
$mock-&gt;getClassBBySomeCriteria(ANY_ARGUMENTS)
    -&gt;willReturn($classBCollection);
$this-&gt;setClassBRetriever($mock);
...
$this-&gt;someMethodThatUsesClassBRetriever()-&gt;will ...

</pre>
<h1 style="text-align: justify;">The problem</h1>
<p style="text-align: justify;">As you can see the mock has <em>getClassBBySomeCriteria</em> method behavior defined and since it could not even exist &#8211; everything is fine at the moment of executing tests or specs. Normally you wouldn&#8217;t have specs/tests for that method because it only retrieves data from the database which is not supposed to be specified or tested.</p>
<p style="text-align: justify;">It gets complicated when you actually try to run the implementation. You&#8217;ll notice that you haven&#8217;t really implemented the method so the code breaks. Furthermore if you did implement the method and somebody has removed or renamed it then you won&#8217;t even notice that fact when running your specs/tests. Another problem is that when you make changes you would have to go through your whole specs or tests in order to fix the mocks.</p>
<p style="text-align: justify;">One thing that could fix it would be if the mocks displayed some kind of warning in the console. For example &#8220;Hey you are mocking a method that does not exist!&#8221;. <a title="Informative mocks" href="https://github.com/phpspec/phpspec2/issues/86" target="_blank">I&#8217;ve raised an issue for that</a> in PHPSpec and as it turns out it is already a work in progress. So you have to hold your breath for that one.</p>
<h1 style="text-align: justify;">The approach</h1>
<p style="text-align: justify;">Since this is not implemented yet the thing you could do is to mock interfaces. This is not a perfect solution but it ensures that you have to implement all abstract methods in classes that implement the interfaces. Another thing is that you will most certainly end up with a better, more loosely coupled design. Then again you have to mock methods that are in the interface as well &#8211; so again you have to be very aware of what you&#8217;re mocking. As I said this is not the perfect solution for the whole scope of the problem but it works for most of the aspects.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2012/12/pitfalls-of-mocking/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Behat with Propel performance tip</title>
		<link>http://blog.karolsojko.com/index.php/2012/12/behat-with-propel-performance-tip/</link>
		<comments>http://blog.karolsojko.com/index.php/2012/12/behat-with-propel-performance-tip/#comments</comments>
		<pubDate>Fri, 14 Dec 2012 20:17:50 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[Behat]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[Propel]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=786</guid>
		<description><![CDATA[Tweet Lately I&#8217;m writting a REST API and since I have converted fully to BDD there is nothing better then Behat to describe my features for the API. So having that said I noticed that there is some serious memory leaking when you use Propel 1.6 with Behat. All the scenarios are executed in one ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2012/12/behat-with-propel-performance-tip/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton786" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F12%2Fbehat-with-propel-performance-tip%2F&amp;via=karolsojko&amp;text=Behat%20with%20Propel%20performance%20tip&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F12%2Fbehat-with-propel-performance-tip%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2012/12/behat-with-propel-performance-tip/" size="standard"></g:plusone></div><p style="text-align: justify;"><a href="http://blog.karolsojko.com/wp-content/uploads/2012/12/behat_and_propel.png"><img class="aligncenter size-full wp-image-788" alt="behat_and_propel" src="http://blog.karolsojko.com/wp-content/uploads/2012/12/behat_and_propel.png" width="596" height="368" /></a></p>
<p style="text-align: justify;">Lately I&#8217;m writting a REST API and since I have <a title="PHPSpec – How I’ve stopped testing and started specifying" href="http://blog.karolsojko.com/index.php/2012/12/phpspec-how-ive-stopped-testing-and-started-specifying/" target="_blank">converted fully to BDD</a> there is nothing better then <a title="Behat - BDD for PHP" href="http://behat.org/" target="_blank">Behat</a> to describe my features for the API. So having that said I noticed that there is some serious memory leaking when you use <a title="Propel" href="http://propelorm.org/" target="_blank">Propel</a> 1.6 with Behat. All the scenarios are executed in one process and because of that Propel becomes a real memory hog. Apparently <a title="Fixing failing Behat scenarios in large suites" href="http://www.zalas.eu/fixing-failing-behat-scenarios-in-large-suites" target="_blank">Doctrine can have the same problems</a>.</p>
<p style="text-align: justify;">I&#8217;ve tried closing the connections after the scenarios but that actually was not the case (Propel handles it pretty nicely). The problem turned out to be pretty simple. Propel keeps already retrieved objects in it&#8217;s cache called <a title="Propel Instance Pool" href="http://propelorm.org/documentation/03-basic-crud.html#propel_instance_pool" target="_blank">Propel Instance Pool</a>. So after each feature/scenario the pool might be getting bigger because it still runs in one process. The solution is very straight forward:</p>
<pre class="brush: php; title: ; notranslate">

use Behat\MinkExtension\Context\MinkContext;
use Behat\Behat\Event\SuiteEvent;
use Propel;

/**
 * Features context.
 */
 class FeatureContext extends MinkContext
 {

    /**
     * @BeforeSuite
     */
    public static function prepare(SuiteEvent $event)
    {
        Propel::disableInstancePooling();
    }

    // ...

</pre>
<p style="text-align: justify;">You have to define a before suite hook in your feature context where you will disable the instance pool and that&#8217;s it. Hope it helps <img src='http://blog.karolsojko.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2012/12/behat-with-propel-performance-tip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPSpec &#8211; How I&#8217;ve stopped testing and started specifying</title>
		<link>http://blog.karolsojko.com/index.php/2012/12/phpspec-how-ive-stopped-testing-and-started-specifying/</link>
		<comments>http://blog.karolsojko.com/index.php/2012/12/phpspec-how-ive-stopped-testing-and-started-specifying/#comments</comments>
		<pubDate>Sun, 02 Dec 2012 18:39:12 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHPSpec]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[Behat]]></category>
		<category><![CDATA[PHPSpec2]]></category>
		<category><![CDATA[SpecBDD]]></category>
		<category><![CDATA[StoryBDD]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=769</guid>
		<description><![CDATA[Tweet Probably like most of you reading this post I&#8217;m a PHP developer that was deeply into TDD. Some time ago I&#8217;ve felt in love with the BDD concept and a tool called Behat. My work made sense on the level that I&#8217;ve finally was able to get in the software&#8217;s beneficient role. Behat gave ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2012/12/phpspec-how-ive-stopped-testing-and-started-specifying/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton769" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F12%2Fphpspec-how-ive-stopped-testing-and-started-specifying%2F&amp;via=karolsojko&amp;text=PHPSpec%20%26%238211%3B%20How%20I%26%238217%3Bve%20stopped%20testing%20and%20started%20specifying&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F12%2Fphpspec-how-ive-stopped-testing-and-started-specifying%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2012/12/phpspec-how-ive-stopped-testing-and-started-specifying/" size="standard"></g:plusone></div><p style="text-align: justify;"><a href="http://blog.karolsojko.com/wp-content/uploads/2012/12/tumblr_mbktmuxXvV1qzeh5uo1_1280.jpg"><img class="aligncenter size-large wp-image-771" title="phpspec" src="http://blog.karolsojko.com/wp-content/uploads/2012/12/tumblr_mbktmuxXvV1qzeh5uo1_1280-1024x640.jpg" alt="" width="560" height="350" /></a></p>
<p style="text-align: justify;">Probably like most of you reading this post I&#8217;m a PHP developer that was deeply into TDD. Some time ago I&#8217;ve felt in love with the BDD concept and a tool called <a title="Behat - BDD for PHP" href="http://behat.org/" target="_blank">Behat</a>. My work made sense on the level that I&#8217;ve finally was able to get in the software&#8217;s beneficient role. Behat gave me an awesome tool for describing my software&#8217;s specifications and as a bonus I had the functional tests for it. But there was still something missing. I mean I was still hooked into doing TDD with <a title="PHPUnit" href="http://www.phpunit.de/manual/current/en/index.html" target="_blank">PHPUnit</a> so I lacked unit tests obviously in BDD.</p>
<h1 style="text-align: justify;">And then there came PHPSpec2&#8230;</h1>
<p style="text-align: justify;">I&#8217;m trully enjoying the concept of SpecBDD with <a title="Spec BDD with phpspec" href="http://www.phpspec.net/" target="_blank">PHPSpec2</a> nowadays. Don&#8217;t get me wrong &#8211; I&#8217;ve enjoyed PHPUnit over the years but I think there is a new king coming. This is a game changer if you&#8217;ve been into TDD like me before. BDD is advertised most of the time as TDD done right, and ofcourse you might have done it right, but there are some pitfalls in which we all fall if we&#8217;ve got the wrong tools for it.</p>
<p style="text-align: justify;">PHPSpec2 may be in it&#8217;s really early <a title="phpspec2 github" href="https://github.com/phpspec/phpspec2" target="_blank">alpha days</a> now but I can see it already as a great tool that helps me to do things right. I&#8217;m very pleased with the way how it is descriptive and intuitive in usage. For example when you specify a class and see something like this:</p>
<pre class="brush: php; title: ; notranslate">

public function let($mailer)
{
    $mailer-&gt;beAMockOf('\Swift_Mailer');
    $this-&gt;beConstructedWith($mailer);
}

</pre>
<p style="text-align: justify;">Try to read it in one sentence out loud: &#8220;Let mailer be a mock of swift mailer and this be constructed with mailer&#8221;. This is sooo intuitive when you look at someone else&#8217;s specs. This is just the way you would say it to a friend. And that&#8217;s the best thing about PHPSpec &#8211; it&#8217;s your friend.</p>
<h1 style="text-align: justify;">Focus on the behavior</h1>
<p style="text-align: justify;">I think the most powerfull thing about PHPSpec is that when you describe your classes you&#8217;re not deep down into how the functions work but you sure as hell are buletproofing the architectural design and ofcourse the outcome. For example if you specify a class and make good prophet objects for it&#8217;s dependencies you will end up with having nice loosely coupled classes.</p>
<p style="text-align: justify;">I&#8217;ve seen a lot of people asking about &#8220;how can I specify a class with PHPSpec that looks like that &#8230;&#8221;. I always look at those examples and ask myself if I would write a class like that if I&#8217;ve written the specs first. The answer is obviously NO! So my advice to you is forget about what the functions do &#8211; think about what you want the class to do. Think about the behavior. Write your specs and you&#8217;ll see that you will refactor the class and benefit from it big time.</p>
<h1 style="text-align: justify;">Don&#8217;t test &#8211; spec and THINK !</h1>
<p style="text-align: justify;">Another thing is that PHPSpec makes you THINK ! I have many times struggled with it to achieve some goal and almost every time ended up with an &#8220;Hey! My class is not suppose to do that anyway. This was stupid in the first place&#8221;. Almost in all cases I&#8217;ve always changed it to the proper simple specification and example schema and it was always spot on! I&#8217;ve delivered the software that does exactly what I want it to do.</p>
<h1 style="text-align: justify;">BDD is for you and me</h1>
<p style="text-align: justify;">Nowadays I can feel that my developer&#8217;s toolbelt is finally complete. I&#8217;m throwing away the old rusty hammers and screwdrivers and have my new shiny toys &#8211; <a title="Behat - BDD for PHP" href="http://behat.org/" target="_blank">Behat</a> for StoryBDD and <a title="Spec BDD with phpspec" href="http://www.phpspec.net/" target="_blank">PHPSpec</a> for SpecBDD. For sure I will be evangelising BDD wherever or whenever I meet any fellow developers.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2012/12/phpspec-how-ive-stopped-testing-and-started-specifying/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Symfony 2 Bundle for Last.fm API</title>
		<link>http://blog.karolsojko.com/index.php/2012/08/symfony-2-bundle-for-last-fm-api/</link>
		<comments>http://blog.karolsojko.com/index.php/2012/08/symfony-2-bundle-for-last-fm-api/#comments</comments>
		<pubDate>Fri, 31 Aug 2012 19:31:30 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony 2]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Bundle]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[Last.fm]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=717</guid>
		<description><![CDATA[Tweet What I was thinking for some time now was writting my own Symfony 2 Bundle. I had some ideas what I want to do and one of them was to implement the Last.fm API. I found a bundle for that but it was written in a messy way and there were only methods concerning ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2012/08/symfony-2-bundle-for-last-fm-api/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton717" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F08%2Fsymfony-2-bundle-for-last-fm-api%2F&amp;via=karolsojko&amp;text=Symfony%202%20Bundle%20for%20Last.fm%20API&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F08%2Fsymfony-2-bundle-for-last-fm-api%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2012/08/symfony-2-bundle-for-last-fm-api/" size="standard"></g:plusone></div><p style="text-align: justify;"><a href="http://blog.karolsojko.com/wp-content/uploads/2012/08/last.fm_.jpg"><img class="aligncenter size-full wp-image-756" title="lastfm" src="http://blog.karolsojko.com/wp-content/uploads/2012/08/last.fm_.jpg" alt="" width="500" height="374" /></a></p>
<p style="text-align: justify;">What I was thinking for some time now was writting my own Symfony 2 Bundle. I had some ideas what I want to do and one of them was to implement the <a title="Web Services - Last.fm" href="http://www.lastfm.pl/api/intro" target="_blank">Last.fm API</a>. I found a bundle for that but it was written in a messy way and there were only methods concerning albums. On top of that it had very poor test coverage. Then there was KnpLabs&#8217; <a title="KnpLabs/php-lastfm-client" href="https://github.com/KnpLabs/php-lastfm-client" target="_blank">php-lastfm-client</a>, but it was not a Symfony 2 bundle. You might say &#8220;Hey but you can wrap that in a bundle easily !&#8221; &#8211; Yes, I could but first of all were&#8217;s the fun in that <img src='http://blog.karolsojko.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  and secondly I wanted to have a solution that would help you to get there without actually reading and analysing the Last.fm API.</p>
<p style="text-align: justify;">So as I thought I did. I made the bundle project available on <a title="karolsojko/BinaryThinkingLastfmBundle" href="https://github.com/karolsojko/BinaryThinkingLastfmBundle" target="_blank">github</a> and encouraged actually anyone on Twitter that would like to participate with me:</p>
<p style="text-align: justify;"><!-- tweet id : 237844973091966976 --><style type='text/css'>#bbpBox_237844973091966976 a { text-decoration:none; color:#0084B4; }#bbpBox_237844973091966976 a:hover { text-decoration:underline; }</style><div id='bbpBox_237844973091966976' class='bbpBox' style='padding:20px; margin:5px 0; background-color:#C0DEED; background-image:url(http://a0.twimg.com/images/themes/theme1/bg.png); background-repeat:no-repeat'><div style='background:#fff; padding:10px; margin:0; min-height:48px; color:#333333; -moz-border-radius:5px; -webkit-border-radius:5px;'><span style='width:100%; font-size:18px; line-height:22px;'>I'm working on a <a href="http://twitter.com/search?q=%23Symfony2" title="#Symfony2">#Symfony2</a> <a href="http://twitter.com/search?q=%23Lastfm" title="#Lastfm">#Lastfm</a> <a href="http://twitter.com/search?q=%23API" title="#API">#API</a> Bundle. Feel free to join in if you like :) <a href="https://t.co/wgjbJMnR" rel="nofollow">https://t.co/wgjbJMnR</a> <a href="http://twitter.com/search?q=%23PHP" title="#PHP">#PHP</a></span><div class='bbp-actions' style='font-size:12px; width:100%; padding:5px 0; margin:0 0 10px 0; border-bottom:1px solid #e6e6e6;'><img align='middle' src='http://blog.karolsojko.com/wp-content/plugins/twitter-blackbird-pie//images/bird.png' /><a title='tweeted on August 21, 2012 11:33 am' href='http://twitter.com/#!/karolsojko/status/237844973091966976' target='_blank'>August 21, 2012 11:33 am</a> via <a href="http://www.tweetdeck.com" rel="nofollow" target="blank">TweetDeck</a><a href='https://twitter.com/intent/tweet?in_reply_to=237844973091966976' class='bbp-action bbp-reply-action' title='Reply'><span><em style='margin-left: 1em;'></em><strong>Reply</strong></span></a><a href='https://twitter.com/intent/retweet?tweet_id=237844973091966976' class='bbp-action bbp-retweet-action' title='Retweet'><span><em style='margin-left: 1em;'></em><strong>Retweet</strong></span></a><a href='https://twitter.com/intent/favorite?tweet_id=237844973091966976' class='bbp-action bbp-favorite-action' title='Favorite'><span><em style='margin-left: 1em;'></em><strong>Favorite</strong></span></a></div><div style='float:left; padding:0; margin:0'><a href='http://twitter.com/intent/user?screen_name=karolsojko'><img style='width:48px; height:48px; padding-right:7px; border:none; background:none; margin:0' src='http://a0.twimg.com/profile_images/2405127321/bcban9mjijriulbvfvtt_normal.jpeg' /></a></div><div style='float:left; padding:0; margin:0'><a style='font-weight:bold' href='http://twitter.com/intent/user?screen_name=karolsojko'>@karolsojko</a><div style='margin:0; padding-top:2px'>Karol S&#243;jko</div></div><div style='clear:both'></div></div></div><!-- end of tweet --></p>
<p style="text-align: justify;">Then I&#8217;ve created some issues and milestones so anyone would know where to start <img src='http://blog.karolsojko.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   :</p>
<p style="text-align: justify;"><!-- tweet id : 240896588782923776 --><style type='text/css'>#bbpBox_240896588782923776 a { text-decoration:none; color:#0084B4; }#bbpBox_240896588782923776 a:hover { text-decoration:underline; }</style><div id='bbpBox_240896588782923776' class='bbpBox' style='padding:20px; margin:5px 0; background-color:#C0DEED; background-image:url(http://a0.twimg.com/images/themes/theme1/bg.png); background-repeat:no-repeat'><div style='background:#fff; padding:10px; margin:0; min-height:48px; color:#333333; -moz-border-radius:5px; -webkit-border-radius:5px;'><span style='width:100%; font-size:18px; line-height:22px;'>Created some new issues if somebody wants to help with BinaryThinkingLastfmBundle for <a href="http://twitter.com/search?q=%23Symfony2" title="#Symfony2">#Symfony2</a> <a href="https://t.co/KumZTgZY" rel="nofollow">https://t.co/KumZTgZY</a></span><div class='bbp-actions' style='font-size:12px; width:100%; padding:5px 0; margin:0 0 10px 0; border-bottom:1px solid #e6e6e6;'><img align='middle' src='http://blog.karolsojko.com/wp-content/plugins/twitter-blackbird-pie//images/bird.png' /><a title='tweeted on August 29, 2012 9:39 pm' href='http://twitter.com/#!/karolsojko/status/240896588782923776' target='_blank'>August 29, 2012 9:39 pm</a> via web<a href='https://twitter.com/intent/tweet?in_reply_to=240896588782923776' class='bbp-action bbp-reply-action' title='Reply'><span><em style='margin-left: 1em;'></em><strong>Reply</strong></span></a><a href='https://twitter.com/intent/retweet?tweet_id=240896588782923776' class='bbp-action bbp-retweet-action' title='Retweet'><span><em style='margin-left: 1em;'></em><strong>Retweet</strong></span></a><a href='https://twitter.com/intent/favorite?tweet_id=240896588782923776' class='bbp-action bbp-favorite-action' title='Favorite'><span><em style='margin-left: 1em;'></em><strong>Favorite</strong></span></a></div><div style='float:left; padding:0; margin:0'><a href='http://twitter.com/intent/user?screen_name=karolsojko'><img style='width:48px; height:48px; padding-right:7px; border:none; background:none; margin:0' src='http://a0.twimg.com/profile_images/2405127321/bcban9mjijriulbvfvtt_normal.jpeg' /></a></div><div style='float:left; padding:0; margin:0'><a style='font-weight:bold' href='http://twitter.com/intent/user?screen_name=karolsojko'>@karolsojko</a><div style='margin:0; padding-top:2px'>Karol S&#243;jko</div></div><div style='clear:both'></div></div></div><!-- end of tweet --></p>
<p style="text-align: justify;">The bundle is available on :</p>
<ul style="text-align: justify;">
<li><a title="karolsojko/BinaryThinkingLastfmBundle" href="https://github.com/karolsojko/BinaryThinkingLastfmBundle" target="_blank">github</a></li>
<li><a title="BinaryThinkingLastfmBundle by karolsojko" href="http://knpbundles.com/karolsojko/BinaryThinkingLastfmBundle" target="_blank">KnpBundles</a></li>
<li><a title="binarythinking/lastfm-bundle" href="http://packagist.org/packages/binarythinking/lastfm-bundle" target="_blank">packagist</a></li>
<li><a title="karolsojko/BinaryThinkingLastfmBundle" href="http://travis-ci.org/#!/karolsojko/BinaryThinkingLastfmBundle" target="_blank">Travis CI</a></li>
</ul>
<p style="text-align: justify;">The installation instructions are available @ github so feel free to install it, run the tests and start helping <img src='http://blog.karolsojko.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . At this moment I have Artis and Album contexts covered &#8211; check the <a title="Milestones - karolsojko/BinaryThinkingLastfmBundle" href="https://github.com/karolsojko/BinaryThinkingLastfmBundle/issues/milestones" target="_blank">milestones</a> to see where it is going now <img src='http://blog.karolsojko.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Give me a shout on twitter @karolsojko if you like it <img src='http://blog.karolsojko.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2012/08/symfony-2-bundle-for-last-fm-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deleting records from big data tables in MySQL</title>
		<link>http://blog.karolsojko.com/index.php/2012/07/deleting-records-from-big-data-tables-in-mysql/</link>
		<comments>http://blog.karolsojko.com/index.php/2012/07/deleting-records-from-big-data-tables-in-mysql/#comments</comments>
		<pubDate>Sat, 14 Jul 2012 09:04:23 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[big data]]></category>
		<category><![CDATA[buffer]]></category>
		<category><![CDATA[cursor]]></category>
		<category><![CDATA[deleting]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[InnoDB]]></category>
		<category><![CDATA[large tables]]></category>
		<category><![CDATA[lock table size]]></category>
		<category><![CDATA[locks]]></category>
		<category><![CDATA[mySQL]]></category>
		<category><![CDATA[procedure]]></category>
		<category><![CDATA[removing]]></category>
		<category><![CDATA[stored procedure]]></category>
		<category><![CDATA[tables]]></category>
		<category><![CDATA[Transactions]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=690</guid>
		<description><![CDATA[Tweet Selecting records to remove The issue with big data tables is that you can&#8217;t easily perform simple queries like deleting a couple of records without exceeding either time or memory. You can encounter those problems both on MySQL side or PHP/Apache side. If there are a lot of records involved, you will want to ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2012/07/deleting-records-from-big-data-tables-in-mysql/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton690" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F07%2Fdeleting-records-from-big-data-tables-in-mysql%2F&amp;via=karolsojko&amp;text=Deleting%20records%20from%20big%20data%20tables%20in%20MySQL&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F07%2Fdeleting-records-from-big-data-tables-in-mysql%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2012/07/deleting-records-from-big-data-tables-in-mysql/" size="standard"></g:plusone></div><h1><a href="http://blog.karolsojko.com/wp-content/uploads/2012/07/23448718.jpg"><img class="aligncenter size-full wp-image-706" title="mysql_big_data" src="http://blog.karolsojko.com/wp-content/uploads/2012/07/23448718.jpg" alt="" width="512" height="372" /></a></h1>
<h1>Selecting records to remove</h1>
<p style="text-align: justify;">The issue with big data tables is that you can&#8217;t easily perform simple queries like deleting a couple of records without exceeding either time or memory. You can encounter those problems both on MySQL side or PHP/Apache side.</p>
<p style="text-align: justify;">If there are a lot of records involved, you will want to push the whole data processing to the MySQL side. For example in my case I wanted to add a missing foreign key and I wanted to select the records that had missing foreign references in order to delete them.</p>
<p style="text-align: justify;">When I started with something like this :</p>
<pre class="brush: sql; title: ; notranslate">
SELECT a.id FROM table_A a WHERE a.bid NOT IN
(SELECT b.id FROM table_B b);
</pre>
<p style="text-align: justify;">This was very stressful for the database engine because it gave the tables a full scan. So I quickly went from that to:</p>
<pre class="brush: sql; title: ; notranslate">
SELECT a.id FROM table_A LEFT JOIN table_B b
ON a.bid = b.id WHERE b.id IS NULL;
</pre>
<h1>The Procedure</h1>
<p style="text-align: justify;">Now this was much faster. But I still wanted to move the weight of this to MySQL because I knew PHP didn&#8217;t have the capacity to handle such amount of data.</p>
<p style="text-align: justify;">The way to go was to create a procedure for MySQL and then call it from PHP. What I came up in the end was something like this:</p>
<pre class="brush: sql; title: ; notranslate">
CREATE PROCEDURE deleteMissingKeyRecords()
BEGIN
  DECLARE done INT DEFAULT FALSE;
  DECLARE aId INT;
  DECLARE aCursor CURSOR FOR
    SELECT a.id FROM table_A LEFT JOIN table_B b
    ON a.bid = b.id WHERE b.id IS NULL;
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

  DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK;
  DECLARE EXIT HANDLER FOR SQLWARNING ROLLBACK;

  START TRANSACTION;

  OPEN aCursor;

  read_loop: LOOP
    FETCH aCursor INTO aId;
    IF done THEN
      LEAVE read_loop;
    END IF;
    DELETE FROM tableA WHERE id = aId;
  END LOOP;

  CLOSE aCursor;

  COMMIT;
END;
</pre>
<p style="text-align: justify;">Now this is probably the most effective way to delete records from big data tables. Now the only thing you want to do is :</p>
<pre class="brush: sql; title: ; notranslate">
CALL deleteMissingKeyRecords();
</pre>
<h1>The environment tune</h1>
<p style="text-align: justify;">If you have a fairly big amount of data you could expect errors like this one :</p>
<blockquote><p>ERROR 1206 (HY000): The total number of locks exceeds the lock table size</p></blockquote>
<p style="text-align: justify;">Now during the delete operation the table is locked and you could exceed your environment&#8217;s limit of locks if a lot of data is being deleted. The solution here is to change in your MySQL configuration (which you can find at /etc/my.cnf or /etc/mysql/my.cnf) the InnoDB buffer pool size. I came across this solution on <a title="A quick performance tune for mysql - innodb_buffer_pool_size &lt;&lt; Cowboy Coded" href="http://www.cowboycoded.com/2009/08/26/a-quick-performance-tune-for-mysql-innodb_buffer_pool_size/" target="_blank">Cowboy Coded blog</a></p>
<p style="text-align: justify;">Go to the configuration file and add:</p>
<blockquote><p>innodb_buffer_pool_size = 1G</p></blockquote>
<p style="text-align: justify;">Please adjust respectivly if the errors still occure. When the procedure is executing you can just show the processlist on MySQL &#8211; if it&#8217;s not preparing then it should say what records are being deleted now. Leave a comment if it helped you <img src='http://blog.karolsojko.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2012/07/deleting-records-from-big-data-tables-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to motivate developers to write tests</title>
		<link>http://blog.karolsojko.com/index.php/2012/06/how-to-motivate-developers-to-write-tests/</link>
		<comments>http://blog.karolsojko.com/index.php/2012/06/how-to-motivate-developers-to-write-tests/#comments</comments>
		<pubDate>Mon, 25 Jun 2012 19:50:54 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[Behavior Driven Development]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[motivation]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[test driven development]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[Unit Tests]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=671</guid>
		<description><![CDATA[Tweet When introducing test driven development to programmers that don&#8217;t have a good grip of it and don&#8217;t really feel the need to wite tests, there are a couple of things that you should keep in mind. Here are some ideas that helped me change my friends minds from &#8220;just do it&#8221; to &#8220;test first&#8221; ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2012/06/how-to-motivate-developers-to-write-tests/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton671" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F06%2Fhow-to-motivate-developers-to-write-tests%2F&amp;via=karolsojko&amp;text=How%20to%20motivate%20developers%20to%20write%20tests&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F06%2Fhow-to-motivate-developers-to-write-tests%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2012/06/how-to-motivate-developers-to-write-tests/" size="standard"></g:plusone></div><p style="text-align: justify;"><a href="http://blog.karolsojko.com/wp-content/uploads/2012/06/23099724.jpg"><img class="aligncenter size-full wp-image-680" title="unit_test_guy" alt="" src="http://blog.karolsojko.com/wp-content/uploads/2012/06/23099724.jpg" width="391" height="488" /></a></p>
<p style="text-align: justify;">When introducing test driven development to programmers that don&#8217;t have a good grip of it and don&#8217;t really feel the need to wite tests, there are a couple of things that you should keep in mind. Here are some ideas that helped me change my friends minds from &#8220;just do it&#8221; to &#8220;test first&#8221; approach.</p>
<h2 style="text-align: justify;">Prepare the environment</h2>
<p style="text-align: justify;">First of all make sure you got the environment properly set up in your project so it&#8217;s good to go. Don&#8217;t bother people that are just eager to learn about tests with setting up stuff. They just want to go straight to the bussiness. Make sure you don&#8217;t trouble them on &#8220;how &amp; why&#8221; it works at first. Ofcourse you will be showing them that later on, but don&#8217;t focus on that at the starting point. You can easily discourage people that have their best intentions to try something new &#8211; and believe me, most of the time they do.</p>
<h2 style="text-align: justify;">Make some tests</h2>
<p style="text-align: justify;">Just like the point above &#8211; make some starting point tests to show them how it works. Write some simple example tests to make it easier for you to explain the idea of TDD. Make sure you have some functionality implemented for some of the tests to pass and some of them to fail.</p>
<h2 style="text-align: justify;">Design the function</h2>
<p style="text-align: justify;">In this moment I think it is very important to work in pairs. Sit down and design the function toghether. Explain how crucial it is to think of the input and output when designing a function and writting a test. This is the part when you plan how it works. When you&#8217;ve got a failing test move on to the implementation. Now this is the part that is the most satisfying for developers. Crossing the bridge between a failing test and a nicely green passed test.</p>
<h2 style="text-align: justify;">Explain the bright side</h2>
<p style="text-align: justify;">When you&#8217;ve got the feeling that people think there is something curiosly satisfying in writting tests try to explain more and more positives about TDD. Mention that this is the way the code is cleaner because it is designed properly first. When you&#8217;re at that make them feel secure by showing that once they&#8217;ve written a piece of code and it is covered by tests properly then they can be sure that no one will change the functionality without breaking the tests. This is very welcomed in environments where there are many developers that work on one project.</p>
<h2 style="text-align: justify;">Show failures</h2>
<p style="text-align: justify;">When an opportunity strikes change some functionality the way it is ment to be changed but in a way that it breaks the tests. This will make people who have written it and the tests fight like lions for fixing the code and tests to have it nice and neet once more. Even better when they put pressure on you to fix it. This is the part in which you know you&#8217;ve got them hooked on TDD.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2012/06/how-to-motivate-developers-to-write-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preparing for PHP ZCE exam : Passing the exam !</title>
		<link>http://blog.karolsojko.com/index.php/2012/05/preparing-for-php-zce-exam-passing-the-exam/</link>
		<comments>http://blog.karolsojko.com/index.php/2012/05/preparing-for-php-zce-exam-passing-the-exam/#comments</comments>
		<pubDate>Thu, 03 May 2012 19:45:26 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZCE Exam]]></category>
		<category><![CDATA[exam]]></category>
		<category><![CDATA[PHP 5.3]]></category>
		<category><![CDATA[ZCE]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Certified Engineer]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=620</guid>
		<description><![CDATA[Tweet I hope that the series of &#8220;Preparing for PHP ZCE exam&#8221; helped you to learn for the exam itself . As for me I have successfully passed the exam on 25th of April 2012. This is just a short note that I would like to share with all people reading my series of articles. ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2012/05/preparing-for-php-zce-exam-passing-the-exam/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton620" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F05%2Fpreparing-for-php-zce-exam-passing-the-exam%2F&amp;via=karolsojko&amp;text=Preparing%20for%20PHP%20ZCE%20exam%20%3A%20Passing%20the%20exam%20%21&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F05%2Fpreparing-for-php-zce-exam-passing-the-exam%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2012/05/preparing-for-php-zce-exam-passing-the-exam/" size="standard"></g:plusone></div><p style="text-align: center;"><a href="http://blog.karolsojko.com/wp-content/uploads/2012/05/812054_47630563.png"><img class="aligncenter  wp-image-621" title="zce_passing" src="http://blog.karolsojko.com/wp-content/uploads/2012/05/812054_47630563.png" alt="" width="480" height="708" /></a></p>
<p style="text-align: justify;">I hope that the series of &#8220;<a title="PHP ZCE Exam" href="http://blog.karolsojko.com/index.php/category/php/zce-exam/" target="_blank">Preparing for PHP ZCE exam</a>&#8221; helped you to learn for the exam itself . As for me I have successfully passed the exam on 25th of April 2012. This is just a short note that I would like to share with all people reading my series of articles.</p>
<p style="text-align: justify;">The exam had it&#8217;s difficult parts and some tricky one&#8217;s as well but a fair part of them were easy for someone who has prepared for it. I strongly advise you to focus on some of the parts that I&#8217;ve mentioned are worth learning and I hope you should pass you exam as well. Please don&#8217;t ask me about the exam&#8217;s questions as I am legally bound not to give them. Once more I wish you all good luck and passing the exam <img src='http://blog.karolsojko.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2012/05/preparing-for-php-zce-exam-passing-the-exam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preparing for PHP ZCE exam : Chapter #10 Web Features</title>
		<link>http://blog.karolsojko.com/index.php/2012/05/preparing-for-php-zce-exam-chapter-10-web-features/</link>
		<comments>http://blog.karolsojko.com/index.php/2012/05/preparing-for-php-zce-exam-chapter-10-web-features/#comments</comments>
		<pubDate>Wed, 02 May 2012 08:28:25 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZCE Exam]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[exam]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[PHP 5.3]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[web features]]></category>
		<category><![CDATA[ZCE]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Certified Engineer]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=567</guid>
		<description><![CDATA[Tweet This is one of the easy chapters that everyone should be well familiar with. So just refresh your memory on this one because it may earn you some easy extra points in the exam. This is as well the final chapter of the PHP ZCE exam preparation. Sessions This is a part that describes ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2012/05/preparing-for-php-zce-exam-chapter-10-web-features/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton567" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F05%2Fpreparing-for-php-zce-exam-chapter-10-web-features%2F&amp;via=karolsojko&amp;text=Preparing%20for%20PHP%20ZCE%20exam%20%3A%20Chapter%20%2310%20Web%20Features&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F05%2Fpreparing-for-php-zce-exam-chapter-10-web-features%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2012/05/preparing-for-php-zce-exam-chapter-10-web-features/" size="standard"></g:plusone></div><p style="text-align: center;"><a href="http://blog.karolsojko.com/wp-content/uploads/2012/05/936172_65994480.png"><img class="aligncenter  wp-image-615" title="zce_webfeatures" src="http://blog.karolsojko.com/wp-content/uploads/2012/05/936172_65994480.png" alt="" width="480" height="436" /></a></p>
<p style="text-align: justify;">This is one of the easy chapters that everyone should be well familiar with. So just refresh your memory on this one because it may earn you some easy extra points in the exam. This is as well the final chapter of the PHP ZCE exam preparation.</p>
<h2 style="text-align: justify;">Sessions</h2>
<p style="text-align: justify;">This is a part that describes what sessions are how they are created. You should know as well where they can be stored. There are a couple of php.ini settings to get familiar with as well f.e. <em>session.use_only_cookies</em>. Get to know the session functions and handlers as well. More about that on <a title="Sessions" href="http://us.php.net/manual/en/intro.session.php" target="_blank">PHP manual</a>.</p>
<h2 style="text-align: justify;">Forms</h2>
<p style="text-align: justify;">Forms are the primary way of sending data to an application. Any developer that is thinking about taking the exam should have a good understanding of what forms are. Some things that are worth mentioning here are:</p>
<ul style="text-align: justify;">
<li><strong>Superglobal arrays </strong>: learn all about those and how data is passed by them.</li>
<li><strong>Encoding &amp; decoding</strong> : Check the manual on how to encode and decode data passed from and to the server.</li>
<li><strong>File uploading</strong> : This is a special part of the forms subject. Make sure you know all about $_FILES array and remember the enctype parameter should be set to &#8216;multipart/form-data&#8217;.</li>
</ul>
<h2 style="text-align: justify;">Cookies &amp; Headers</h2>
<p style="text-align: justify;">This part focuses on creating and getting cookies from user&#8217;s client and the headers that could be sent to the user. This is fairly simple and straight forward. Just to mention you should remember all the parameters that can be set when calling <em>setcookie</em> function.</p>
<p style="text-align: justify;">When talking about headers it is not only important to know how to send them but checking if they are sent or getting a list of headers to be sent is important as well. Get familiarized with the header functions available in the <a title="Network Functions" href="http://www.php.net/manual/en/ref.network.php" target="_blank">manual</a>. Make sure you know the HTTP header codes and what each of them means.</p>
<p style="text-align: justify;">This is it ! Now you should be ready for passing the PHP ZCE exam. I hope that my series of preparation articles helped someone to reach the goal of passing the exam <img src='http://blog.karolsojko.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Thank you for reading <img src='http://blog.karolsojko.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2012/05/preparing-for-php-zce-exam-chapter-10-web-features/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preparing for PHP ZCE exam : Chapter #9 Security</title>
		<link>http://blog.karolsojko.com/index.php/2012/05/preparing-for-php-zce-exam-chapter-9-security/</link>
		<comments>http://blog.karolsojko.com/index.php/2012/05/preparing-for-php-zce-exam-chapter-9-security/#comments</comments>
		<pubDate>Tue, 01 May 2012 12:41:41 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZCE Exam]]></category>
		<category><![CDATA[CGI]]></category>
		<category><![CDATA[CSRF]]></category>
		<category><![CDATA[exam]]></category>
		<category><![CDATA[PHP 5.3]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[SQL Injection]]></category>
		<category><![CDATA[XSS]]></category>
		<category><![CDATA[ZCE]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Certified Engineer]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=565</guid>
		<description><![CDATA[Tweet This is probably the hardest chapter of the exam and one that is strongly emphasized. Configuration &#38; Installation Read all about installing PHP as CGI binary or as an Apache module, which is most likely the way you have done it usually. It is crucial to understand the way how the redirect mechanism works. ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2012/05/preparing-for-php-zce-exam-chapter-9-security/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton565" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F05%2Fpreparing-for-php-zce-exam-chapter-9-security%2F&amp;via=karolsojko&amp;text=Preparing%20for%20PHP%20ZCE%20exam%20%3A%20Chapter%20%239%20Security&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F05%2Fpreparing-for-php-zce-exam-chapter-9-security%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2012/05/preparing-for-php-zce-exam-chapter-9-security/" size="standard"></g:plusone></div><p style="text-align: center;"><a href="http://blog.karolsojko.com/wp-content/uploads/2012/05/1166687_41661603.png"><img class="aligncenter  wp-image-607" title="zce_security" src="http://blog.karolsojko.com/wp-content/uploads/2012/05/1166687_41661603.png" alt="" width="480" height="360" /></a></p>
<p style="text-align: justify;">This is probably the hardest chapter of the exam and one that is strongly emphasized.</p>
<h2 style="text-align: justify;">Configuration &amp; Installation</h2>
<p style="text-align: justify;">Read all about installing PHP as CGI binary or as an Apache module, which is most likely the way you have done it usually. It is crucial to understand the way how the redirect mechanism works. The thing to focus on here is the possible measures to protect your folders from unwanted access. You can read more about it on <a href="http://php.net/manual/en/security.php" target="_blank">PHP.net&#8217;s Security</a> section.</p>
<h2 style="text-align: justify;">Attacks</h2>
<p style="text-align: justify;">There are couple of attacks mentioned in the chapter and you should really focus on how PHP applications are attacked and where are their vulnerabilities. Here&#8217;s a list what you should look up thoroughly:</p>
<ul style="text-align: justify;">
<li><strong>Session attacks</strong> : Two methods here to read about are session hijacking and session fixation. You can read more about the first one on <a title="Session Hijacking" href="http://www.serversidemagazine.com/php/session-hijacking/" target="_blank">Server-Side Magazine&#8217;s &#8220;Session Hijacking</a>&#8221; and the second one on <a title="Session Fixation" href="http://shiflett.org/articles/session-fixation" target="_blank">Chris Shiflett&#8217;s &#8220;Session Fixation&#8221;</a>.</li>
<li><strong>Cross-Site Scripting (XSS)</strong> : An attack that is based on injecting HTML, CSS or JavaScript into the page. More about XSS on <a title="Cross-site scripting" href="http://en.wikipedia.org/wiki/Cross-site_scripting" target="_blank">Wikipedia</a>.</li>
<li><strong>Cross-Site Request Forgery (CSRF)</strong> : Attack that relies on web site&#8217;s vulnerability of trusting logged in users. You can read more about CSRF&#8217;s and counter measures on <a title="Cross-Site Request Forgeries" href="http://shiflett.org/articles/cross-site-request-forgeries" target="_blank">Chris Shiftlett&#8217;s blog</a> as well.</li>
<li><strong>SQL Injection</strong> : Probably one of the most popular attacks incorporating SQL syntax which may break not-escaped queries and expose the whole database. More about the subject on Krzysztof Kotowicz&#8217;s <a title="Hardening PHP: SQL Injection - complete walkthrough" href="http://blog.kotowicz.net/2010/03/hardening-php-sql-injection-complete.html" target="_blank">&#8220;Hardening PHP: SQL Injection &#8211; Complete walkthrough&#8221;</a>.</li>
</ul>
<p style="text-align: justify;">There are of course a lot more attacks like for example : Remote Code Injection, Email Injection, but you should strongly focus on those mentioned above.</p>
<h2 style="text-align: justify;">Input &amp; Output</h2>
<p style="text-align: justify;">When considering security you should always have in mind the two fundamental rules:</p>
<ol style="text-align: justify;">
<li>Filter and validate input</li>
<li>Escape output</li>
</ol>
<p style="text-align: justify;">When displaying output on the page always remember to escape it. You can use specially designed functions for that like: <em>strip_tags</em>, <em>htmlspecialchars</em>, <em>htmlentities</em>.</p>
<h2 style="text-align: justify;">File uploads</h2>
<p style="text-align: justify;">Although this is a fairly easy part, this is a subject that has some some strong focus on the exam. Try to learn everything about upload files, the superglobal $_FILES, and some helping functions like: <em>is_uploaded_file</em>, <em>move_uploaded_file</em>.</p>
<p style="text-align: justify;">There are some other subjects in this chapter like encrypting passwords, designing databases and SSL but this should be very well know the ones mentioned above should be your primary focus considering the exam.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2012/05/preparing-for-php-zce-exam-chapter-9-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preparing for PHP ZCE exam : Chapter #8 Databases</title>
		<link>http://blog.karolsojko.com/index.php/2012/04/preparing-for-php-zce-exam-chapter-8-databases/</link>
		<comments>http://blog.karolsojko.com/index.php/2012/04/preparing-for-php-zce-exam-chapter-8-databases/#comments</comments>
		<pubDate>Sun, 22 Apr 2012 16:25:03 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZCE Exam]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[exam]]></category>
		<category><![CDATA[PDO]]></category>
		<category><![CDATA[PHP 5.3]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Transactions]]></category>
		<category><![CDATA[ZCE]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Certified Engineer]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=563</guid>
		<description><![CDATA[Tweet SQL This chapter focuses on some of the topics related with databases. For example SQL is one of the key points of this part. This should not be an issue for people that want to pass the exam because the questions mainly consist of standard SQL queries like SELECT, INSERT, UPDATE, DELETE. One thing ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2012/04/preparing-for-php-zce-exam-chapter-8-databases/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton563" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F04%2Fpreparing-for-php-zce-exam-chapter-8-databases%2F&amp;via=karolsojko&amp;text=Preparing%20for%20PHP%20ZCE%20exam%20%3A%20Chapter%20%238%20Databases&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F04%2Fpreparing-for-php-zce-exam-chapter-8-databases%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2012/04/preparing-for-php-zce-exam-chapter-8-databases/" size="standard"></g:plusone></div><h2 style="text-align: justify;"><a href="http://blog.karolsojko.com/wp-content/uploads/2012/04/zce_databases.png"><img class="aligncenter  wp-image-596" title="zce_databases" src="http://blog.karolsojko.com/wp-content/uploads/2012/04/zce_databases.png" alt="" width="480" height="431" /></a></h2>
<h2 style="text-align: justify;">SQL</h2>
<p style="text-align: justify;">This chapter focuses on some of the topics related with databases. For example SQL is one of the key points of this part. This should not be an issue for people that want to pass the exam because the questions mainly consist of standard SQL queries like SELECT, INSERT, UPDATE, DELETE. One thing that is crucial here is that you have a good understanding of the difference between LEFT JOIN&#8217;s and INNER JOIN&#8217;s.</p>
<h2 style="text-align: justify;">PDO (PHP Data Objects)</h2>
<p style="text-align: justify;">This chapter focuses strongly on PDO. There are some topics in relation with PDO that are worth looking into:</p>
<ul style="text-align: justify;">
<li style="text-align: justify;"><em><strong>Transactions</strong></em>: Get a good grip of commiting and rolling back transactions. You can read more about it in the <a href="http://php.net/manual/en/pdo.transactions.php" target="_blank">Transactions and auto-commit</a> article on PHP manual.</li>
<li style="text-align: justify;"><em><strong>Prepared statements</strong></em>: This is a strong feature of PDO as it emulates the behaviour even for the adapters that do not support prepared statements. Read more on <a href="http://www.php.net/manual/en/pdo.prepared-statements.php" target="_blank">Prepared statements and stored procedures</a> at php.net.</li>
<li style="text-align: justify;"><em><strong>Connections</strong></em>: Lear about how to initiate a connection and how to close one.</li>
<li style="text-align: justify;"><em><strong>PDOStatement</strong></em>: Read more about the class <a href="http://www.php.net/manual/en/class.pdostatement.php" target="_blank">here</a>. The thing that you could focus on is the many ways of getting the results from the database. Try to learn about the fetch modes when executing a query.</li>
</ul>
<p style="text-align: justify;">As you can see the SQL part of this chapter is very simple and straight forward. I assume most of the people know a lot already about SQL so the only point to focus on here is the PDO extension which you should get familiarized with.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2012/04/preparing-for-php-zce-exam-chapter-8-databases/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preparing for PHP ZCE exam : Chapter #7 OOP</title>
		<link>http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-7-oop/</link>
		<comments>http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-7-oop/#comments</comments>
		<pubDate>Sat, 24 Mar 2012 11:26:26 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZCE Exam]]></category>
		<category><![CDATA[autoloading]]></category>
		<category><![CDATA[exam]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[late static binding]]></category>
		<category><![CDATA[magic methods]]></category>
		<category><![CDATA[PHP 5.3]]></category>
		<category><![CDATA[reflections]]></category>
		<category><![CDATA[spl]]></category>
		<category><![CDATA[ZCE]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Certified Engineer]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=561</guid>
		<description><![CDATA[Tweet Object Oriented Programming Most of the rules mentioned in this chapter apply to a great majority of programming languages, so assuming you have some experience with software this should be just a good reminder. Although this chapter has some general ideas of programming there are some PHP specific issues here and there. Take a ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-7-oop/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton561" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F03%2Fpreparing-for-php-zce-exam-chapter-7-oop%2F&amp;via=karolsojko&amp;text=Preparing%20for%20PHP%20ZCE%20exam%20%3A%20Chapter%20%237%20OOP&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F03%2Fpreparing-for-php-zce-exam-chapter-7-oop%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-7-oop/" size="standard"></g:plusone></div><h1 style="text-align: justify;"><a href="http://blog.karolsojko.com/wp-content/uploads/2012/03/495073_44006441.png"><img class="aligncenter size-full wp-image-588" title="ZCE_oop" src="http://blog.karolsojko.com/wp-content/uploads/2012/03/495073_44006441.png" alt="" width="800" height="600" /></a></h1>
<h1 style="text-align: justify;">Object Oriented Programming</h1>
<p style="text-align: justify;">Most of the rules mentioned in this chapter apply to a great majority of programming languages, so assuming you have some experience with software this should be just a good reminder. Although this chapter has some general ideas of programming there are some PHP specific issues here and there. Take a good look at this one because it is filled with tricky questions. Some topics that are worth mentioning:</p>
<h2 style="text-align: justify;">Reflections</h2>
<p style="text-align: justify;">Reflections are a good tool to investigate your classes or dynamically modify them. This is very often used to create documentation files from a set of PHP classes. The main advantage of reflections is that you can handle dynamic method calling in an elegant way. On top of that you can set static properties in classes and modify the accessibility of fields. This is a powerful tool for dynamic definition of code.</p>
<h2 style="text-align: justify;">Autoloading</h2>
<p style="text-align: justify;">Try to learn everything about the autoloader mechanism. How does it work and how to modify it. There is a good example of autoloading on <a title="Demystifying the PHP spl_autoload_register, spl_autoload and __autoload functions" href="http://www.waynemay.com/demystifying-the-php-spl-autoload-register-spl-autoload-and-autoload-functions-12022011" target="_blank">Wayne May&#8217;s blog</a>.</p>
<h2 style="text-align: justify;">Late Static Binding</h2>
<p style="text-align: justify;">This is a new feature in PHP 5.3 and it is a one that was needed for a long time indeed. Now when you call an inherited method of class you can call static methods from the initialy called class rather than parent class with the use of <em>static:: </em>- for examples see the <a title="PHP: Late Static Bindings - Manual" href="http://php.net/manual/en/language.oop5.late-static-bindings.php" target="_blank">PHP manaul</a>.</p>
<h2 style="text-align: justify;">Inheritance</h2>
<p style="text-align: justify;">Focus especially on questions concerning method overriding. This ones are ment to be tricky with all the variations of overriding. Think of all the abstract/static method modifiers possibilities. Keep in mind that code leading to fatal errors may come up in questions as well.</p>
<h2 style="text-align: justify;">Magic Methods</h2>
<p style="text-align: justify;">Although they are not used often magic methods are key feature of some PHP frameworks. For example Symfony 1.x used them extensively in many aspects. So if you feel like designing a new big project/framework you can consider them as a tool for you. Keep in mind that the current trend is to &#8220;get rid of all the magic&#8221; as the code is not always clear. More on magic methods can be found on <a title="Deciphering Magic Methods in PHP | Nettuts+" href="http://net.tutsplus.com/tutorials/php/deciphering-magic-methods-in-php/" target="_blank">NetTuts+ post</a></p>
<h2 style="text-align: justify;">SPL</h2>
<p style="text-align: justify;">Standard PHP Library is library of interfaces that provide software developers to finally write PHP code in an object oriented manner. It comes with all sort of Iterators and classes that help construct object with array-like behaviour. I recommend reading this very good introduction to SPL that is available on <a title="DevZone &gt;&gt; The Standard PHP Library (SPL)" href="http://devzone.zend.com/1075/the-standard-php-library-spl/" target="_blank">Zend&#8217;s DevZone</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-7-oop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preparing for PHP ZCE exam : Chapter #6 Functions</title>
		<link>http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-6-functions/</link>
		<comments>http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-6-functions/#comments</comments>
		<pubDate>Tue, 20 Mar 2012 18:58:13 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZCE Exam]]></category>
		<category><![CDATA[closures]]></category>
		<category><![CDATA[exam]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[PHP 5.3]]></category>
		<category><![CDATA[ZCE]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Certified Engineer]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=553</guid>
		<description><![CDATA[Tweet This is probably one of the easiest and shortest topics on the exam. But use it as your advantage &#8211; this is a great way to earn some easy points to help you pass the exam. If you are a PHP developer that considers taking ZCE exam I suppose you already know the subject ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-6-functions/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton553" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F03%2Fpreparing-for-php-zce-exam-chapter-6-functions%2F&amp;via=karolsojko&amp;text=Preparing%20for%20PHP%20ZCE%20exam%20%3A%20Chapter%20%236%20Functions&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F03%2Fpreparing-for-php-zce-exam-chapter-6-functions%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-6-functions/" size="standard"></g:plusone></div><p style="text-align: justify;"><a href="http://blog.karolsojko.com/wp-content/uploads/2012/03/976083_74231444.png"><img class="aligncenter size-full wp-image-556" title="ZCE_functions" src="http://blog.karolsojko.com/wp-content/uploads/2012/03/976083_74231444.png" alt="" width="800" height="533" /></a></p>
<p style="text-align: justify;">This is probably one of the easiest and shortest topics on the exam. But use it as your advantage &#8211; this is a great way to earn some easy points to help you pass the exam. If you are a PHP developer that considers taking ZCE exam I suppose you already know the subject by heart. Nevertheless here are some topics that are mentioned in this chapter:</p>
<p style="text-align: justify;"><em><strong>Returning values</strong></em>: returning references from functions are something worth mentioning that may appear in some questions.</p>
<p style="text-align: justify;"><em><strong>Variable scope</strong></em>: some questions may concern defining variables in and outside of the functions and their visibility in them. Remember about globals.</p>
<p style="text-align: justify;"><em><strong>Arguments</strong></em>: Focus on passing arguments by reference, getting variable-length arguments lists.</p>
<p style="text-align: justify;"><em><strong>Closures</strong></em>: Also known as anonymous functions. Often used as callbacks. Questions about inheriting variables from parent scope might apear. Read more <a href="http://www.php.net/manual/en/functions.anonymous.php" target="_blank">here</a>.</p>
<p style="text-align: justify;">As you can see this one should be a piece of pie for you so use it on your advantage.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-6-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preparing for PHP ZCE exam : Chapter #5 Input &amp; Output</title>
		<link>http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-5-input-output/</link>
		<comments>http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-5-input-output/#comments</comments>
		<pubDate>Sun, 11 Mar 2012 19:25:33 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZCE Exam]]></category>
		<category><![CDATA[exam]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[output]]></category>
		<category><![CDATA[PHP 5.3]]></category>
		<category><![CDATA[streams]]></category>
		<category><![CDATA[ZCE]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Certified Engineer]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=541</guid>
		<description><![CDATA[Tweet Reading and Writting One of the key parts of this chapters is for you to focus on all the file_* and f* functions, which are great tools for file handling. All of them can be found here. So start off with the easy ones (file_*), which work with a filename. Then go to the ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-5-input-output/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton541" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F03%2Fpreparing-for-php-zce-exam-chapter-5-input-output%2F&amp;via=karolsojko&amp;text=Preparing%20for%20PHP%20ZCE%20exam%20%3A%20Chapter%20%235%20Input%20%26%23038%3B%20Output&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F03%2Fpreparing-for-php-zce-exam-chapter-5-input-output%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-5-input-output/" size="standard"></g:plusone></div><h2 style="text-align: justify;"><a href="http://blog.karolsojko.com/wp-content/uploads/2012/03/284743_2835.png"><img class="aligncenter size-full wp-image-546" title="ZCE_io" src="http://blog.karolsojko.com/wp-content/uploads/2012/03/284743_2835.png" alt="" width="640" height="480" /></a></h2>
<h2 style="text-align: justify;">Reading and Writting</h2>
<p style="text-align: justify;">One of the key parts of this chapters is for you to focus on all the <em>file_*</em> and <em>f*</em> functions, which are great tools for file handling. All of them can be found <a href="http://www.php.net/manual/en/ref.filesystem.php" target="_blank">here</a>. So start off with the easy ones (<em>file_*</em>), which work with a filename. Then go to the ones that work with a resource (<em>f*</em>).  Memorize all the possible ways to open a resource &#8211; you can find all the modes in the <a href="http://www.php.net/manual/en/function.fopen.php" target="_blank">fopen documentation</a>. While you&#8217;re at the resource based file functions try to get familiar with manipulating the file pointer in the resource with functions like <em>fseek</em>, <em>ftell</em> or <em>rewind</em>.</p>
<h2 style="text-align: justify;">File Operations</h2>
<p style="text-align: justify;">At this point you can focus on functions that are helpfull with operating on files. For example you should be studying topics like : how to read the directory contents, how to copy files, how to delete them or how to determine if a file/directory exists. There&#8217;s a lot of helpful functions for this matter. They on the <a href="http://www.php.net/manual/en/ref.filesystem.php" target="_blank">list</a> with the previous ones. Most of them have very straight forward names : <em>copy</em>, <em>delete</em>, <em>rename</em>, <em>file_exists</em>. Some of them are named exactly the same as UNIX shell commands : <em>chgrp</em>, <em>chmod</em>, <em>chown </em>so this should be easy to remember.</p>
<h2 style="text-align: justify;">Streams</h2>
<p style="text-align: justify;">This is probably the hardest part of this chapter so if you&#8217;re not familiar with streams in PHP you&#8217;ve got some catching up to do. First off you can never go wrong with going to the <a href="http://www.php.net/manual/en/book.stream.php " target="_blank">manual</a>. There are very many useful functionalities concerning streams, for example: learn a thing or two about stream contexts. Thanks to them you can give some extra headers to the stream which is often the scenario you will need. Another useful thing about streams is stream filtering. You can define your own filters that will modify the data of the file while it&#8217;s being read in your script. You can read about registering your filters in the <a href="http://php.net/manual/en/function.stream-filter-register.php" target="_blank">manual</a> as always. If you&#8217;d like to read more about streams I would recommend <a title="Introduction to PHP streams | sk89q" href="http://www.sk89q.com/2010/04/introduction-to-php-streams/" target="_blank">sk89q&#8217;s introduction to PHP streams</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-5-input-output/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preparing for PHP ZCE exam : Chapter #4 Arrays</title>
		<link>http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-4-arrays/</link>
		<comments>http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-4-arrays/#comments</comments>
		<pubDate>Tue, 06 Mar 2012 18:08:26 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZCE Exam]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[exam]]></category>
		<category><![CDATA[PHP 5.3]]></category>
		<category><![CDATA[spl]]></category>
		<category><![CDATA[ZCE]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Certified Engineer]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=531</guid>
		<description><![CDATA[Tweet Basics Arrays are probably the strongest and best tool in PHP for data manipulation. There are dozens of specially prepared functions just for handling arrays. I assume that you are already well familiarized with the basics of creating, adressing, splitting and looping through arrays. Though these are very simple points of the exam, try ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-4-arrays/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton531" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F03%2Fpreparing-for-php-zce-exam-chapter-4-arrays%2F&amp;via=karolsojko&amp;text=Preparing%20for%20PHP%20ZCE%20exam%20%3A%20Chapter%20%234%20Arrays&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F03%2Fpreparing-for-php-zce-exam-chapter-4-arrays%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-4-arrays/" size="standard"></g:plusone></div><h2><a href="http://blog.karolsojko.com/wp-content/uploads/2012/03/1379288_78456432.png"><img class="aligncenter  wp-image-535" title="ZCE_arrays" src="http://blog.karolsojko.com/wp-content/uploads/2012/03/1379288_78456432.png" alt="" width="540" height="360" /></a></h2>
<h2 style="text-align: justify;">Basics</h2>
<p style="text-align: justify;">Arrays are probably the strongest and best tool in PHP for data manipulation. There are dozens of specially prepared <a href="http://php.net/manual/en/ref.array.php " target="_blank">functions</a> just for handling arrays. I assume that you are already well familiarized with the basics of creating, adressing, splitting and looping through arrays. Though these are very simple points of the exam, try to focus on some variations of adding and removing elements like for example:</p>
<ul style="text-align: justify;">
<li>array_push</li>
<li>array_unshift</li>
<li>array_pop</li>
<li>array_shift</li>
</ul>
<h2 style="text-align: justify;">Sorting</h2>
<p style="text-align: justify;">There are very many ways of sorting an array in PHP. The key here is to know all types of the sort functions and what they do:</p>
<ul style="text-align: justify;">
<li>sort</li>
<li>rsort &#8211; reverse sort</li>
<li>asort &#8211; associative sort</li>
<li>arsort &#8211; associative reverse sort</li>
<li>ksort &#8211; sort by key</li>
<li>krsort &#8211; sort by key in reverse</li>
<li>usort &#8211; user defined sort</li>
<li>natsort &#8211; natural sort</li>
</ul>
<p style="text-align: justify;">Try to memorize all of them and the set of parameters that they take f.e. the sort mode :</p>
<ul style="text-align: justify;">
<li>SORT_LOCALE_STRING &#8211; sort based on locale settings</li>
<li>SORT_NUMERIC &#8211; numeric sort</li>
<li>SORT_REGULAR &#8211; normal sorting</li>
<li>SORT_STRING &#8211; sorting as strings</li>
</ul>
<p style="text-align: justify;">It is very crucial to know the difference in how those modes work and what would be the outcome of sorting in each of those modes.</p>
<h2 style="text-align: justify;">Comparing</h2>
<p style="text-align: justify;">There is a big family of function in PHP that are defined for comparing arrays and getting their differences or elements that are present in each. For checking out the differences there are a lot of functions that start with <em>array_diff </em>or <em>array_udiff </em>for user defined calculations. The same goes for checking the elements present in one array that are available in the other &#8211; this time we have functions starting with <em>array_intersect </em>or <em>array_uintersect</em>.</p>
<h2 style="text-align: justify;">SPL</h2>
<p style="text-align: justify;">Standard PHP Library introduced a new helpful aproach for creating arrays. Now by extending the <a href="http://www.php.net/manual/en/class.arrayobject.php" target="_blank">ArrayObject</a> class delivered with SPL we can define our own logic in accesing, iterating, serializing or sorting array elements. This can be very helpful in many ways for example: we could want to throw a custom exception when accessing an illegal offset in array. This is a very powerful tool and try to focus on getting to know it better.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2012/03/preparing-for-php-zce-exam-chapter-4-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preparing for PHP ZCE exam : Chapter #3 Strings</title>
		<link>http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-3-strings/</link>
		<comments>http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-3-strings/#comments</comments>
		<pubDate>Wed, 29 Feb 2012 18:07:17 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZCE Exam]]></category>
		<category><![CDATA[exam]]></category>
		<category><![CDATA[PHP 5.3]]></category>
		<category><![CDATA[ZCE]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Certified Engineer]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=519</guid>
		<description><![CDATA[Tweet String manipulation Besides the real basics of strings in PHP (like f.e. escaping, heredoc syntax, determining the length) you should focus on some of the essential tools that PHP provides for string manipulation. First of all try to focus on comparing, searching and replacing strings. Try to memorize as many function from PHP manual ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-3-strings/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton519" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F02%2Fpreparing-for-php-zce-exam-chapter-3-strings%2F&amp;via=karolsojko&amp;text=Preparing%20for%20PHP%20ZCE%20exam%20%3A%20Chapter%20%233%20Strings&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F02%2Fpreparing-for-php-zce-exam-chapter-3-strings%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-3-strings/" size="standard"></g:plusone></div><h2><a href="http://blog.karolsojko.com/wp-content/uploads/2012/02/Bez-nazwy.png"><img class="aligncenter  wp-image-522" title="ZCE_strings" src="http://blog.karolsojko.com/wp-content/uploads/2012/02/Bez-nazwy.png" alt="" width="480" height="360" /></a></h2>
<h2>String manipulation</h2>
<p>Besides the real basics of strings in PHP (like f.e. escaping, heredoc syntax, determining the length) you should focus on some of the essential tools that PHP provides for string manipulation.</p>
<p>First of all try to focus on comparing, searching and replacing strings. Try to memorize as many function from <a href="http://php.net/manual/en/ref.strings.php" target="_blank">PHP manual</a> as you can. A good way to start would be to group them in functionalities f.e.:</p>
<p><em>Searching</em>:</p>
<ul>
<li>strpos</li>
<li>stripos</li>
<li>strstr</li>
<li>stristr</li>
</ul>
<p><em>Replacing</em>:</p>
<ul>
<li>str_replace</li>
<li>str_ireplace</li>
<li>substr_replace</li>
</ul>
<p><em>Formating</em>:</p>
<ul>
<li>printf</li>
<li>vprintf</li>
<li>sprintf</li>
<li>vsprintf</li>
<li>fprintf</li>
</ul>
<h2>Encoding</h2>
<p>After you get a grip with all the string manipulation techniques a good thing to do would be to get familiar with encodings. This is a thing that from my experience is often the cause of some serious and hard to fix application bugs. So try to learn everything about the changing and determining the encoding of characters in strings.</p>
<h2>Regular Expressions</h2>
<p>Last but not least probably the hardest part in this chapter are regular expressions. This is a tool that will make you a very powerful and skilled developer if you know it very good. But don&#8217;t be fooled, it&#8217;s very easy to mess everything up with some wrong or greedy regular expressions. RE are in my opinion not something that you can learn overnight. It takes some practice and a couple of mistakes to get a good grip of them. So try to practice as many regular expressions as you can find. The <a href="http://www.regular-expressions.info/examples.html" target="_blank">Regular Expression Examples</a> is a good site if you need some inspiration or a point of start.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-3-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preparing for PHP ZCE exam : Chapter #2 Data Types and Formats</title>
		<link>http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-2-data-types-and-formats/</link>
		<comments>http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-2-data-types-and-formats/#comments</comments>
		<pubDate>Fri, 24 Feb 2012 17:06:45 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZCE Exam]]></category>
		<category><![CDATA[exam]]></category>
		<category><![CDATA[PHP 5.3]]></category>
		<category><![CDATA[ZCE]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Certified Engineer]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=478</guid>
		<description><![CDATA[Tweet This is the first part of the exam on which we can actually focus some more. There are some points here that tend to be troublesome or tricky like f.e. xpath queries. From my experience this chapter describes some crucial tools for a PHP developer that make life easier. Besides data formats, the concept ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-2-data-types-and-formats/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton478" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F02%2Fpreparing-for-php-zce-exam-chapter-2-data-types-and-formats%2F&amp;via=karolsojko&amp;text=Preparing%20for%20PHP%20ZCE%20exam%20%3A%20Chapter%20%232%20Data%20Types%20and%20Formats&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F02%2Fpreparing-for-php-zce-exam-chapter-2-data-types-and-formats%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-2-data-types-and-formats/" size="standard"></g:plusone></div><p style="text-align: center;"><a href="http://blog.karolsojko.com/wp-content/uploads/2012/02/Skitched-image01.png"><img class="aligncenter  wp-image-488" title="ZCE_DTF" src="http://blog.karolsojko.com/wp-content/uploads/2012/02/Skitched-image01.png" alt="" width="560" height="374" /></a></p>
<p>This is the first part of the exam on which we can actually focus some more. There are some points here that tend to be troublesome or tricky like f.e. xpath queries. From my experience this chapter describes some crucial tools for a PHP developer that make life easier. Besides data formats, the concept of a web service is a key point of this section as well. So let&#8217;s get the show on the road:</p>
<p><strong>XML</strong> : Besides the basics, like understanding DOM or creating XML parsers, the main focus in here would be to get a good grip of SimpleXML. Read about the classes and methods that PHP offers in an OOP access for XML data. As a part of SimpleXML study, focus on the xpath section. This is a crucial thing as the questions may be tricky for this one.</p>
<p><strong>SOAP &amp; REST</strong> : This shouldn&#8217;t be a hard to learn one, because those are pretty straight forward. Try to learn as much as you can about REST principles and focus on SoapClient communication with SoapServer and the functionalities that they both have to offer.</p>
<p><strong>Date &amp; Time</strong> : Every PHP developer should have a good sense of how to manipulate with date and time formats. Nevertheless try to refresh your memory about the formats in which the time is displayed, some php.ini date.* settings and get familiar with the DateTime class which is not commonly used.</p>
<p>This chapter covers some others stuff like f.e. JSON &amp; AJAX but I think every developer (not only PHP) should know them pretty well, so as it&#8217;s not a matter of learning them, you can have a look and double check if you still know everything about them.</p>
<p>Till next time <img src='http://blog.karolsojko.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-2-data-types-and-formats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preparing for PHP ZCE exam : Chapter #1 Basics</title>
		<link>http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-1-basics/</link>
		<comments>http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-1-basics/#comments</comments>
		<pubDate>Thu, 23 Feb 2012 18:18:32 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZCE Exam]]></category>
		<category><![CDATA[exam]]></category>
		<category><![CDATA[PHP 5.3]]></category>
		<category><![CDATA[ZCE]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Certified Engineer]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=463</guid>
		<description><![CDATA[Tweet Most of the people who will want to take this exam will probably know a thing or two about PHP. Major part of this exam section is something that goes without saying. As a developer you should be familiar with the language syntax and already have written a fair amount of PHP code. Although ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-1-basics/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton463" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F02%2Fpreparing-for-php-zce-exam-chapter-1-basics%2F&amp;via=karolsojko&amp;text=Preparing%20for%20PHP%20ZCE%20exam%20%3A%20Chapter%20%231%20Basics&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F02%2Fpreparing-for-php-zce-exam-chapter-1-basics%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-1-basics/" size="standard"></g:plusone></div><p style="text-align: justify;"><a href="http://blog.karolsojko.com/wp-content/uploads/2012/02/Skitched-image1.png"><img class="aligncenter size-full wp-image-467" title="ZCE_basics" src="http://blog.karolsojko.com/wp-content/uploads/2012/02/Skitched-image1.png" alt="" width="800" height="536" /></a></p>
<p style="text-align: justify;">Most of the people who will want to take this exam will probably know a thing or two about PHP. Major part of this exam section is something that goes without saying. As a developer you should be familiar with the language syntax and already have written a fair amount of PHP code.</p>
<p style="text-align: justify;"><span id="more-463"></span></p>
<p style="text-align: justify;">Although this one should be a piece of cake, there are some key points of this chapter that are worth studying deeper. For example:</p>
<ul>
<li><strong>Namespaces</strong> : a great new feature that was introduced with PHP 5.3. They are not yet as popular as one would expect so many developers didn&#8217;t have a good grip of them yet. People working with modern frameworks like <a title="Symfony" href="http://symfony.com/" target="_blank">Symfony 2</a> or <a title="Zend framework" href="http://framework.zend.com/zf2" target="_blank">Zend 2</a> should have a good sense of what namespaces are, but If you don&#8217;t I recommend to have a good look at them. The parts that are especially worth focusing on are importing and aliasing of namespaces.</li>
<li><strong>Configuration</strong>: it is always good to refresh your knowledge or learn something new about php.ini files. The main focus here would be to read about the settings that are available and if you already know most of them then try to memorise them so as not to mess the settings names. See <a title="php ini core" href="http://www.php.net/manual/en/ini.core.php" target="_blank">PHP manual</a> for more.</li>
</ul>
<p style="text-align: justify;">As you can see not many fields to focus in this chapter but don&#8217;t neglect it. Make sure you are prepared for questions that seem innocent at first glance but for example have some tricky bitwise operators.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-1-basics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preparing for PHP ZCE exam : Chapter #0 Introduction</title>
		<link>http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-0-introduction/</link>
		<comments>http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-0-introduction/#comments</comments>
		<pubDate>Wed, 22 Feb 2012 18:10:45 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZCE Exam]]></category>
		<category><![CDATA[exam]]></category>
		<category><![CDATA[PHP 5.3]]></category>
		<category><![CDATA[ZCE]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Certified Engineer]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=447</guid>
		<description><![CDATA[Tweet I&#8217;m currently in the process of preparing for my ZCE exam for PHP. Some time ago I had an idea to turn this whole learning process into a set of articles/blog posts. This could help me to sum up some keynotes about some of the main points of the exam. Hopefully this would help ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-0-introduction/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton447" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F02%2Fpreparing-for-php-zce-exam-chapter-0-introduction%2F&amp;via=karolsojko&amp;text=Preparing%20for%20PHP%20ZCE%20exam%20%3A%20Chapter%20%230%20Introduction&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2012%2F02%2Fpreparing-for-php-zce-exam-chapter-0-introduction%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-0-introduction/" size="standard"></g:plusone></div><p style="text-align: justify;"><a href="http://blog.karolsojko.com/wp-content/uploads/2012/02/Skitched-image0.png"><img class="aligncenter size-full wp-image-472" title="ZCE_introduction" src="http://blog.karolsojko.com/wp-content/uploads/2012/02/Skitched-image0.png" alt="" width="800" height="536" /></a></p>
<p style="text-align: justify;">I&#8217;m currently in the process of preparing for my ZCE exam for PHP. Some time ago I had an idea to turn this whole learning process into a set of articles/blog posts. This could help me to sum up some keynotes about some of the main points of the exam. Hopefully this would help someone there preparing for the exam as well.<br />
<span id="more-447"></span></p>
<p style="text-align: justify;">At first I thought of some kind of day-by-day walkthrough but I don&#8217;t think I would have the time to become a pro-blogger by posting an article each day. Then I came up with the plan of organising these articles into chapters, so each chapter would address a certain part of the exam.</p>
<p style="text-align: justify;">My intention is not to deliver a tutorial on how to prepare for the exam, but to document the learning process. Maybe point out some hints or things that I think are worth focusing on.  This could help some people to get a grip of the ZCE exam. Last but not least this could help me as well. I count on your comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2012/02/preparing-for-php-zce-exam-chapter-0-introduction/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mocknity &#8211; Auto Mocking Container For Unity</title>
		<link>http://blog.karolsojko.com/index.php/2011/05/mocknity-auto-mocking-container-for-unity/</link>
		<comments>http://blog.karolsojko.com/index.php/2011/05/mocknity-auto-mocking-container-for-unity/#comments</comments>
		<pubDate>Tue, 31 May 2011 21:17:14 +0000</pubDate>
		<dc:creator>Karol Sójko</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[Auto Mocking Container]]></category>
		<category><![CDATA[automocking]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Container]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Inversion Of Control]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[Mocking]]></category>
		<category><![CDATA[Rhino Mocks]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unit Test]]></category>

		<guid isPermaLink="false">http://blog.karolsojko.com/?p=386</guid>
		<description><![CDATA[Tweet Mocknity is an extension for Microsoft&#8217;s Dependency Injection Container &#8211; Unity, which turns the Patterns &#38; Practices Container into an Auto Mocking Container. Mocknity uses Rhino Mocks for creation of mock objects. The Idea The basic idea of auto mocking is to minimize the huge amount of boilerplate configuration that you need to repeat ...<a class="post-readmore" href="http://blog.karolsojko.com/index.php/2011/05/mocknity-auto-mocking-container-for-unity/">read more</a>]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton386" class="tw_button" style="float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2011%2F05%2Fmocknity-auto-mocking-container-for-unity%2F&amp;via=karolsojko&amp;text=%23Mocknity%20-%20Auto%20Mocking%20%20Container%20For%20Unity.%20Dependency%20Injection%20with%20mocking%20made%20easy%20via%20%40karolsojko.&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fblog.karolsojko.com%2Findex.php%2F2011%2F05%2Fmocknity-auto-mocking-container-for-unity%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://blog.karolsojko.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><div class="google_plusone_widget"><g:plusone 
      count="true" href="http://blog.karolsojko.com/index.php/2011/05/mocknity-auto-mocking-container-for-unity/" size="standard"></g:plusone></div><p style="text-align: center;"><a href="http://blog.karolsojko.com/wp-content/uploads/2011/05/northern_mockingbird_web1.jpg"><img class="aligncenter size-medium wp-image-402" title="Mocking Bird" src="http://blog.karolsojko.com/wp-content/uploads/2011/05/northern_mockingbird_web1-292x300.jpg" alt="Mocking Bird" width="292" height="300" /></a></p>
<p><a title="Mocknity" href="https://github.com/karolsojko/Mocknity" target="_blank">Mocknity</a> is an extension for Microsoft&#8217;s Dependency Injection Container &#8211; <a title="Unity" href="http://unity.codeplex.com/" target="_blank">Unity</a>, which turns the Patterns &amp; Practices Container into an Auto Mocking Container. Mocknity uses <a title="Rhino Mocks" href="http://ayende.com/blog" target="_blank">Rhino Mocks</a> for creation of mock objects.<span id="more-386"></span></p>
<h2>The Idea</h2>
<p>The basic idea of auto mocking is to minimize the huge amount of boilerplate configuration that you need to repeat for your Dependency Injection in different environments. In most cases they differ only by 2-3 dependencies and the rest is just copy &amp; paste.</p>
<p>Thanks to an Auto Mocking Container you need to specify only the dependencies that you want to be resolved with class instances that will be tested in the unit tests.</p>
<p>The way it works is similar to the Dependency Injection Container (which it is based on) but instead of resolving certain registered interface-to-class mappings it resolves them with mock objects. An object&#8217;s dependencies that are declared as interfaces and were not registered earlier will be mocked. This way you can focus on the unit testing and forget about filling in the dependecies.</p>
<h2>Examples</h2>
<pre class="brush: csharp; title: ; notranslate">
[TestClass]
public class MocknityTests
{
  IUnityContainer container;
  MocknityContainerExtension mocknity;
  MockRepository repository;

  [TestInitialize]
  public void TestInitialize()
  {
    container = new UnityContainer();
    repository = new MockRepository();
    mocknity = new MocknityContainerExtension(repository);
    container.AddExtension(mocknity);
  }

  [TestMethod]
  public void ResolveObject__MockDependenciesNotNull()
  {
    Car car = container.Resolve&lt;Car&gt;();
    // ... aserts go here ....
  }

}
</pre>
<p>This example shows how to configure Mocknity for your test class. You have to instantiate it with a mocking repository provided by Rhino Mocks. Upon resolving an object by the container, all it&#8217;s dependencies will be mocked if needed.</p>
<p>Let&#8217;s say that Car instance has two dependencies : IWheels and IEngine. Those two will be mocked in the scenario above.</p>
<h2>Strategies</h2>
<p>Mocknity comes with three types of strategies for building mocked dependencies:</p>
<ul>
<li>DynamicRhinoMocksBuilderStrategy (default)</li>
<li>StrictRhinoMocksBuilderStrategy</li>
<li>StubRhinoMocksBuilderStrategy</li>
</ul>
<p>The first one is the most flexible scenario thus making it the default strategy. StrictRhinoMocksBuilderStrategy on the other hand gives you mocks that you have to make certain expectations for them to work properly. The last strategy is only for stub creation.</p>
<p>This following example shows how to set a strategy for certain interface and shows the behaviour of a strict mock which will throw an exception when asked for something that wasn&#8217;t declared expected:</p>
<pre class="brush: csharp; title: ; notranslate">

[TestMethod]
[ExpectedException(typeof(ExpectationViolationException))]
public void IWheelsIsAStrictMock__ExceptionThrownOnCallingNotExpectedMethod()
{

  mocknity.setStrategy&lt;StrictRhinoMocksBuilderStrategy&gt;(typeof(IWheels));
  Car car = container.Resolve&lt;Car&gt;();
  mocknity.getRepository().ReplayAll();
  car.wheels.Spin(); // this will throw an exception
  mocknity.getRepository().VerifyAll();

}

</pre>
<p>You can download the code and the DLL binaries as well from <a title="Mocknity on github" href="https://github.com/karolsojko/Mocknity" target="_blank">github</a>. Hope this helps <img src='http://blog.karolsojko.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karolsojko.com/index.php/2011/05/mocknity-auto-mocking-container-for-unity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
