<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>PHPDeveloper.org</title>
    <link>http://www.phpdeveloper.org</link>
    <description>Up-to-the Minute PHP News, views and community</description>
    <language>en-us</language>
    <pubDate>Sun, 12 Feb 2012 16:05:39 -0600</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Jakub Zalas' Blog: Mocking Symfony Container services in Behat scenarios with Mockery]]></title>
      <guid>http://www.phpdeveloper.org/news/17428</guid>
      <link>http://www.phpdeveloper.org/news/17428</link>
      <description><![CDATA[<p>
<i>Jakub Zalas</i> has <a href="http://www.zalas.eu/mocking-symfony-container-services-in-behat-scenarios-with-mockery">a recent post</a> to his blog with a hint about how to test Symfony container services by mocking them (when testing with <A href="http://behat.org/">Behat</a>) with the help of <a href="https://github.com/padraic/mockery">Mockery</a> (and the <a href="https://github.com/PolishSymfonyCommunity/PSSMockeryBundle">PSSMockeryBundle</a>).
</p>
<blockquote>
Mocking objects in unit tests is pretty straightforward as every object used in a test case is usually created in a scope of one test class. In functional tests it's a bit harder since we either don't have full control over objects being created or it's simply too laborious to mock half the framework. [...] We're getting the service from a container [in the example] and calling a method which should send a lead. The problem is we don't want to actually call an API while executing Behat scenarios.
</blockquote>
<p>
Rather than hitting up the API for each test, he opts to create mock objects and results with the tools <a href="https://github.com/padraic/mockery">Mockery</a> has to offer. He gives code for a "is API available" method that either returns a valid container or a mocked object, depending on how it was called.
</p>]]></description>
      <pubDate>Fri, 20 Jan 2012 13:54:52 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Kurt Payne's Blog: How to Unit Test pcntl_fork()]]></title>
      <guid>http://www.phpdeveloper.org/news/17421</guid>
      <link>http://www.phpdeveloper.org/news/17421</link>
      <description><![CDATA[<p>
<i>Kurt Payne</i> has a new post to his blog showing how you can <a href="http://kpayne.me/2012/01/17/how-to-unit-test-fork/">unit test your process forking</a> in your PHP application (<a href="http://php.net/pcntl">pcntl</a>).
</p>
<blockquote>
At some point, many php developers turn to the pcntl functions in php to write a daemon, or server, or simulate threading. But how do you unit test this with complete code coverage? [...] We need to engage some black arts php extensions to make this happen.  An installation guide follows, and the post ends with a complete listing of the unit test.
</blockquote>
<p>
He uses the <a href="https://github.com/sebastianbergmann/php-test-helpers">test_helpers</a> extension (as provided by <i>Sebastian Bergmann</i>) and <a href="https://github.com/zenovich/runkit/">Runkit</a> to allow the test to define new methods copying the current pcntl methods and mocks up the responses. Tests are included to check the parent of a process, checking the children of a process and testing that a fork could be made. Hes's even included <a href="http://kurtpayne.files.wordpress.com/2012/01/forktest_code_coverage.png?w=614&h=464">visual proof</a> of this working.
</p>]]></description>
      <pubDate>Thu, 19 Jan 2012 13:40:20 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[VG Tech Blog: Mocking the File System Using PHPUnit and vfsStream]]></title>
      <guid>http://www.phpdeveloper.org/news/17235</guid>
      <link>http://www.phpdeveloper.org/news/17235</link>
      <description><![CDATA[<p>
On the VG Tech blog today there's another post related to unit testing (<a href="http://phpdeveloper.org/news/17229">here's</a> one from before) but this time they're talking about <a href="http://tech.vg.no/2011/03/09/mocking-the-file-system-using-phpunit-and-vfsstream/">mocking the filesystem with vfsStream</a>, a powerful tool that lets you interact with PHP streams as a virtual file system.
</p>
<blockquote>
This article is about how to mock the file system when writing unit tests, and it will be rather code-heavy. [...] <a href="http://phpunit.de/">PHPUnit</a> is the de-facto standard for unit testing in PHP projects, and this is what we will be using together with <a href="http://code.google.com/p/bovigo/wiki/vfsStream">vfsStream</a> in this article.
</blockquote>
<p>
The include the code for a simple storage driver (VGF_Storage_Driver_Filesystem) to use with vfsStream  with "store", "delete" and "get" methods. Also included are examples of using vfsStream to check things like directory existence, if a file exists, or if a file can be read. A few simple assertions are set up in their sample test to check the methods in their "VGF_Storage_Driver_Filesystem" class.
</p>]]></description>
      <pubDate>Fri, 09 Dec 2011 09:40:13 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[VG Tech Blog: Unit Testing with Streams in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/17229</guid>
      <link>http://www.phpdeveloper.org/news/17229</link>
      <description><![CDATA[<p>
On the VG Tech blog today there's a new post from <i>Andr&eacute; Roaldseth</i> about using <a href="http://phpunit.de">PHPUnit</a> to <a href="http://tech.vg.no/2011/06/27/unit-testing-with-streams-in-php/">test PHP streams</a>, basing the assertions on the data rather than the functionality itself.
</p>
<blockquote>
Using the memory/temporary stream provided by php:// stream wrapper you  can create a stream with read and write access directly to RAM or to a temporary file [using "php://memory"]. This gives you the possibilty to write unit tests that does not rely on a specific file, resource or stream, but rather on data provided by the test itself.
</blockquote>
<p>
There's no specific code examples here, but you can refer to the <a href="http://us3.php.net/manual/en/wrappers.php.php">stream wrappers</a> section of the PHP manual for more details on this and other handy built-in streams. Once created, it can then be used just as <a href="http://no.php.net/manual/en/book.stream.php">any other stream resource</a> can. This could be useful to provide mocks in your testing, replacing any other stream-able resource with a "memory" or "temp" placeholder.
</p>]]></description>
      <pubDate>Thu, 08 Dec 2011 09:13:28 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Wojciech Sznapka's Blog: Why Mockery is better than PHPUnit Mock Builder (with Symfony2)]]></title>
      <guid>http://www.phpdeveloper.org/news/17074</guid>
      <link>http://www.phpdeveloper.org/news/17074</link>
      <description><![CDATA[<p>
<i>Wojciech Sznapka</i> has a new post today sharing his opinions as to why <a href="http://blog.sznapka.pl/why-mockery-is-better-than-phpunit-mock-builder-and-how-to-integrate-it-with-symfony2">Mockery is better than PHPUnit Mock Builder</a> in testing Symfony2-based applications.
</p>
<blockquote>
Recently I did a lot of Test Driven Development on my Symfony2 bundle. I used PHPUnit's built-in <a href="http://www.phpunit.de/manual/3.5/en/test-doubles.html">mocks and stubs</a> for many projects, so I took it again. But while I was working on mocking Symfony2 core objects I found those mocks very uncomfortable in use. I tried <a href="http://blog.astrumfutura.com/2009/03/the-mockery-an-independent-mock-object-and-stub-framework-for-php5/">Mockery</a> and it saved my day. Let's see how to get it working with Symfony2 and how it kicks ass!
</blockquote>
<p>
He shows how to get things set up - adding Mockery to the dependencies file (deps), getting the latest version from their git repository and an example mock method that shows the difference in mocking the Doctrine2 entity manager - PHPUnit vs Mockery.
</p>]]></description>
      <pubDate>Wed, 02 Nov 2011 13:02:06 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Lars Tesmer's Blog: How to Unit Test a Class Making Calls to an URL (or the Filesystem) With PHPUnit]]></title>
      <guid>http://www.phpdeveloper.org/news/16889</guid>
      <link>http://www.phpdeveloper.org/news/16889</link>
      <description><![CDATA[<p>
<i>Lars Tesmer</i> has a suggestion for all of the unit testers out there (you do unit test your code, right?) when needing to test a piece of code that makes a call to something on the file system or a remote resource. Their examples come from tests written against the <a href="https://github.com/kriswallsmith/assetic">Assetic</a> codebase.
</p>
<blockquote>
For our most recent <a href="http://lars-tesmer.com/blog/categories/after-work-hacking/">After Work Hacking</a> my co-workers and me decided to write unit tests for the open source project <a href="https://github.com/kriswallsmith/assetic">Assetic</a>. That turned out to be a better decision than our last one, yet we still ran into an interesting challenge.
</blockquote>
<p>
In testing the HttpAsset class from the tool, they came across the problem - a call to a remote/file resource that could not be tested because of a <a href="http://php.net/manual/en/function.file-get-contents.php">file_get_contents</a> call that depends on an external source. They came up with a few options to try to test this example, some better than others:
</p>
<ul>
<li>Give it a real URL to test with
<li>Wrap the file_get_contents inside of a new class (ex. a "ContentFetcher")
<li>Use <a href="https://github.com/mikey179/vfsStream">vfsStream</a> to mock out the file system in the unit test
</ul>
<p>
In their case, vfsStream couldn't be used due to how the fetch call was made, but the tool can be very handy if you need to mock out an external file system resource.
</p>]]></description>
      <pubDate>Wed, 21 Sep 2011 12:04:47 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Till Klampaeckel's Blog: RFC: Mocking protected methods]]></title>
      <guid>http://www.phpdeveloper.org/news/16481</guid>
      <link>http://www.phpdeveloper.org/news/16481</link>
      <description><![CDATA[<p>
<i>Till Klampaeckel</i> has <a href="http://till.klampaeckel.de/blog/archives/158-RFC-Mocking-protected-methods.html">a new post</a> to his blog today looking at the method he's found (through some help from others) to be able to mock out protected methods in his unit tests.
</p>
<blockquote>
I wrote a couple tests for a small CouchDB access wrapper today. But when I wrote the implementation itself, I realized that my class setup depends on an actual CouchDB server being available and here my journey began.
</blockquote>
<p>
It was his first experience trying to mock out parts of a class, and he found it a bit difficult to use even after reading <a href="http://sebastian-bergmann.de/archives/881-Testing-Your-Privates.html">this article</a> from <i>Sebastian Bergmann</i>. He ended up, as a first solution, making a "fake" (a term from Ruby testing) that just returned the basic JSON string of an error. Thanks to comments on the post, though, he was able to come up with a more correct solution using getMock() to create a stub and apply an expects() to his "makeRequest" method.
</p>]]></description>
      <pubDate>Thu, 16 Jun 2011 13:48:33 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[DZone.com: A Mockery Review]]></title>
      <guid>http://www.phpdeveloper.org/news/16315</guid>
      <link>http://www.phpdeveloper.org/news/16315</link>
      <description><![CDATA[<p>
On the Web Builder Zone (a part of <a href="http://dzone.com">DZone.com</a>) there's a recent post from <i>Giorgio Sironi</i> <a href="http://css.dzone.com/articles/mockery-review">reviewing the Mockery library</a>, a mock object framework created by <a href="http://blog.astrumfutura.com/">Padraic Brady</a>.
</p>
<blockquote>
<a href="https://github.com/padraic/mockery">Mockery</a> is a mock object framework (more properly Test Double framework) from <a href="http://twitter.com/padraicb">@padraicb</a>, independent from testing frameworks like PHPUnit. It can be used to quickly prepare Mocks, Stubs and other Test Doubles to use inside your unit tests. I've tried Mockery via a PEAR installation and I must say its expressive power is higher than that of PHPUnit mocking system. However, it may be too powerful for effective usage.
</blockquote>
<p>
He talks about some of the features that are in Mockery that aren't in <a href="http://phpunit.de">PHPUnit</a> like alternative expectations, recording of the expected calls and the mocking of non-existent methods. He notes that it can be too overwhelming at times, though, with so many features that may or may not be useful for the large majority of testers. He includes some sample code showing a set of five tests on a simple class implementing an interface.
</p>]]></description>
      <pubDate>Mon, 09 May 2011 13:05:14 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Fabian Schmengler's Blog: "Mocking" built-in functions like time() in Unit ]]></title>
      <guid>http://www.phpdeveloper.org/news/16065</guid>
      <link>http://www.phpdeveloper.org/news/16065</link>
      <description><![CDATA[<p>
In a recent post to his blog <i>Fabian Schmengler</i> looks at mocking something in your unit tests that could cause problems in certain situations - needing a specific kind of response from a built-in PHP function. In his case, he <a href="http://www.schmengler-se.de/-php-mocking-built-in-functions-like-time-in-unit-tests">shows how to mock</a> <a href="http://php.net/time">time</a> to return the same formatted date.
</p>
<blockquote>
A common problem in Unit Testing in PHP is testing something that depends on the current time. For a determined test it should be possible to set the time in your test script without really changing the system settings. In this article I'll describe how it is usually done with OOP and then come to an alternative solution with much less code that makes use of the new features in PHP 5.3.
</blockquote>
<p>
He shows a usual approach using dependency injection and a class wrapper to handle the set and fetch of the date value. His alternative uses namespacing to redefine the internal PHP function into something custom. Then, when the test is executed, it can use that custom namespace's version, overriding the default. It's a pretty seamless option and can save you a good bit of time and hassle with other classes each time you need to customize the results.
</p>]]></description>
      <pubDate>Fri, 18 Mar 2011 08:52:03 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Mike Lively's Blog: Pear Channel set up for Phake]]></title>
      <guid>http://www.phpdeveloper.org/news/15665</guid>
      <link>http://www.phpdeveloper.org/news/15665</link>
      <description><![CDATA[<p>
<i>Mike Lively</i> has <a href="http://digitalsandwich.com/archives/93-pear-channel-set-up-for-phake.html">a new post about a PEAR channel</a> he's set up for his <a href="https://github.com/mlively/Phake">Phake</a> mocking tool on his digitalsandwich.com domain.
</p>
<blockquote>
For those that may not have caught my first post on the subject, <a href="https://github.com/mlively/Phake">Phake</a> is a mock framework that I announced a couple of days ago in <a href="http://digitalsandwich.com/archives/84-introducing-phake-mocking-framework.html">Introducing Phake Mocking Framework</a>. It was recommended in the comments that I get it on a pear channel somewhere, which is something I have wanted to do but hadn't had a reason to do until this week. Well, now there is an official <a href="http://pear.digitalsandwich.com/">Digital Sandwich Pear Channel</a> that is hosting Phake.
</blockquote>
<p>
Discover the channel with the PEAR installer and run the install with the path provided. He notes that the release is alpha because of the lack of documentation but, despite this, the API is stable. Also, you'll need to be using PHP 5.2+ to use the tool.
</p>]]></description>
      <pubDate>Fri, 31 Dec 2010 13:30:42 -0600</pubDate>
    </item>
  </channel>
</rss>

