<?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>Sat, 18 May 2013 22:51:47 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[QaFoo.com: Mocking with Phake]]></title>
      <guid>http://www.phpdeveloper.org/news/19308</guid>
      <link>http://www.phpdeveloper.org/news/19308</link>
      <description><![CDATA[<p>
On the QaFoo blog today there's a new tutorial posted showing you how to <a href="http://qafoo.com/blog/037_phake.html">make unit test mocks with Phake</a>, a <a href="http://phake.digitalsandwich.com/">testing tool</a> that works a bit differently that other options (PHPUnit's own mocking and <a href="https://github.com/padraic/mockery">Mockery</a>).
</p>
<blockquote>
The use of Mock and Stub Objects is an important skill to learn when using Test Driven Development (TDD). Mock objects allow you to replace dependencies of an object with lookalikes, much like crash test dummies are used during automobile safety tests so humans aren't harmed. [...] Using Mocks in PHPUnit tests means using the built-in <a href="https://github.com/sebastianbergmann/phpunit-mock-objects">MockObjects library</a> for quite some years. In the last years two contenders emerged that can be used as optional dependencies in PHPUnit. [...] This blog post introduces Phake, because it works quite differently than both PHPUnit Mock Objects and Mockery.
</blockquote>
<p>
They include a code example of how to create mocks with Phake, showing it's different approach to defining the mocked methods. They explain each part of the code, detailing the use of the "when", "thenReturn" and "verify" methods. You can find out more about Phake and see other examples in <a href="http://phake.digitalsandwich.com/docs/html/">the project's documentation</a>.
</p>]]></description>
      <pubDate>Wed, 13 Mar 2013 12:53:26 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Zumba Engineering Blog: Mocking Singleton PHP classes with PHPUnit]]></title>
      <guid>http://www.phpdeveloper.org/news/18801</guid>
      <link>http://www.phpdeveloper.org/news/18801</link>
      <description><![CDATA[<p>
On the Zumba Engineering blog today <i>Chris Taylor</i> has a new post about <a href="http://engineering.zumba.com/2012/11/26/singleton-class-phpunit-mocking/">mocking in PHPUnit</a>, specifically how to handle those pesky Singleton methods lurking around your codebase.
</p>
<blockquote>
In many of our projects, utilities and vendor classes are implemented with a <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>. [...] In this post, we'll cover a nice way to inject a PHPUnit mock object for use in testing methods that utilize singleton classes.
</blockquote>
<p>
He starts by introducing mocking and how to use mock classes in PHPUnit with a simple "sayHello" example. Adding on another layer, he creates a "SomeclassMock" class, defining its own "expects" and "cleanup" methods. This class forces the Singleton method to act more like a regular non-static method and "resets" it after each use.
</p>]]></description>
      <pubDate>Mon, 26 Nov 2012 09:51:04 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[NetTuts.com: All About Mocking with PHPUnit]]></title>
      <guid>http://www.phpdeveloper.org/news/18531</guid>
      <link>http://www.phpdeveloper.org/news/18531</link>
      <description><![CDATA[<p>
NetTuts.com has another post for those out there wanting to further their PHP unit testing knowledge. In <a href="http://net.tutsplus.com/tutorials/php/all-about-mocking-with-phpunit/">this new tutorial</a>, <i>Csaba Patkos</i> introduces you to mocking objects with PHP Unit - a powerful method to help test some of the more difficult things.
</p>
<blockquote>
There are two styles of testing: "black box" and "white box" styles. Black box testing focuses on the object's state; whereas, white box testing focuses on behavior. The two styles complement each other and can be combined to thoroughly test code. Mocking allows us to test behavior, and this tutorial combines the mocking concept with TDD to build an example class that uses several other components to achieve its goal.
</blockquote>
<p>
He illustrates mocking with his sample "toy car" application and shows how to use a few different types of mocks (test doubles) to create some tests. These types include dummy objects, test stubs, test mocks and test fakes. Code is included for all test examples, including some showing the use of the actual PHPUnit mocking functionality.
</p>]]></description>
      <pubDate>Fri, 28 Sep 2012 09:46:21 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[SitePoint.com: Advanced PHPUnit Testing: Annotations and Mocking]]></title>
      <guid>http://www.phpdeveloper.org/news/15920</guid>
      <link>http://www.phpdeveloper.org/news/15920</link>
      <description><![CDATA[<p>
On SitePoint.com today there's a new article in their unit testing series posted today - a look at <a href="http://blogs.sitepoint.com/2011/02/17/advanced-phpunit-testing-annotations-and-mocking/">annotations and mocking</a> in advanced unit testing with <a href="http://phpunit.de">PHPUnit</a>. (Disclaimer: I am the author of this article series.)
</p>
<blockquote>
PHPUnit has lots of advanced features that can be amazingly helpful when that special case comes around. This includes extending the framework itself, making test suites, building static datasets, and the focus of this article: annotations and mocking. Don't worry if you're unsure what either of these are; I'm here to help. I trust by the end that you'll see how these two features can be useful to both you and your tests.
</blockquote>
<p>
The article starts with annotations showing how they can be used both on the class side to help with test generation and on the test side to help in evaluation (like expectedException). In the mocking section, it shows you how create simple and complex mock objects to replace a sample database query.
</p>]]></description>
      <pubDate>Thu, 17 Feb 2011 09:33:08 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Devis Lucato's Blog: Anonymous objects in PHP - Composition, Mocks, Refactoring]]></title>
      <guid>http://www.phpdeveloper.org/news/15480</guid>
      <link>http://www.phpdeveloper.org/news/15480</link>
      <description><![CDATA[<p>
In <a href="http://lucato.it/php-anonymous-objects">a new post</a> to his blog <i>Devis Lucato</i> points out something he noticed when working with objects and anonymous functions/closures - they're not all as they seem.
</p>
<blockquote>
Both solutions allow to instantiate an anonymous object with properties. They are used as value objects and have no other purpose than storing values, so no logic can be included and they don't come with methods.  They can be used as function parameters instead of arrays, for instance. PHP 5.3.0 introduced anonymous functions and closures, so it is now possible to attach functions to these VOs (*). [...] The first thing to notice is that these properties are not methods but callable functions:
</blockquote>
<p>
In his example, an anonymous function dynamically appended to an object doesn't have access to a property set on the object just one line before. There's a way around it with <a href="http://php.net/call_user_func">call_user_func</a>, but it's not practical. His proposed solution is to create a type of Anonymous class that uses the __call method to catch the methods and translate them into calls to <a href="http://php.net/call_user_func_array">call_user_func_array</a> automatically. 
</p>]]></description>
      <pubDate>Tue, 23 Nov 2010 13:17:53 -0600</pubDate>
    </item>
  </channel>
</rss>
