<?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>Wed, 23 May 2012 20:14:39 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Kevin Schroeder's Blog: ZF2 Dependency Injection - Multiple Object Instances]]></title>
      <guid>http://www.phpdeveloper.org/news/17884</guid>
      <link>http://www.phpdeveloper.org/news/17884</link>
      <description><![CDATA[<p>
<i>Kevin Schroeder</i> has <a href="http://www.eschrade.com/page/zf2-dependency-injection-multiple-object-instances">a quick new post</a> about using dependency injection in Zend Framework 2 applications using multiple object instances.
</p>
<blockquote>
When you work with the ZF2 Dependency Injection Container (DiC) when you make multiple requests for an instance of an object you will get the same object back each time. [...] But what if you want the injection benefits of the DiC but don't want to share the object?  Use the DiC's newInstance method instead with the third parameter being false.
</blockquote>
<p>
He includes code examples of requesting the object both ways - the usual way that returns the same object and the alternative that passes in a "false" value, complete with a <a href="http://php.net/var_dump">debug output</a> of each object proving they're different.
</p>]]></description>
      <pubDate>Mon, 30 Apr 2012 12:15:34 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: An Intro to Virtual Proxies, Part 2]]></title>
      <guid>http://www.phpdeveloper.org/news/17869</guid>
      <link>http://www.phpdeveloper.org/news/17869</link>
      <description><![CDATA[<p>
Following up on his <a href="http://phpdeveloper.org/news/17838">previous article</a>, <i>Alejandro Gervasio</i> has a new post to PHPMaster.com with the <a href="http://phpmaster.com/intro-to-virtual-proxies-2/">second part of his series</a> on using virtual proxies in PHP.
</p>
<blockquote>
Resting on the foundation of Polymorphism (dynamic Polymorphism, not the ad-hoc one often achieved through plain method overriding), Virtual Proxies are a simple yet solid concept which allows you to defer the construction/loading of expensive object graphs without having to modify client code.
</blockquote>
<p>
He shows how to create a collection of domain objects that use proxies to populate their data. He includes the code for creating a "Post" interface/object as well as a Comment interface/object. These are put into a "CommentCollection" and, when it's accessed, pull the item in the collection out, only populating the data on demand.
</p>]]></description>
      <pubDate>Thu, 26 Apr 2012 09:24:23 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Chris Hartjes' Blog: Metatesting: Testing Constructors]]></title>
      <guid>http://www.phpdeveloper.org/news/17784</guid>
      <link>http://www.phpdeveloper.org/news/17784</link>
      <description><![CDATA[<p>
In a new post to his blog <i>Chris Hartjes</i>, promoter of all things testing, looks a <a href="http://www.littlehart.net/atthekeyboard/2012/04/05/metatesting-testing-constructors/">a method for testing constructors</a> - an effective way to validate the things that happen when your objects are generated.
</p>
<blockquote>
If you have a PHP application that makes heavy use of objects (which is probably 95% of you reading this) then you will have objects with constructor methods in them. It is also very likely that there is some stuff going on in those constructors. So how do you test things like this?
</blockquote>
<p>
He includes a sample constructor that creates a container, pulls out some configuration values and reassigns them to class properties. He first tests that these properties have been set correctly by mocking out the object and overriding the configuration settings in the (dependency injection) container.
</p>]]></description>
      <pubDate>Fri, 06 Apr 2012 08:28:00 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Chris Hartjes' Blog: Metatesting: Understanding Mock Objects]]></title>
      <guid>http://www.phpdeveloper.org/news/17741</guid>
      <link>http://www.phpdeveloper.org/news/17741</link>
      <description><![CDATA[<p>
In <a href="http://www.littlehart.net/atthekeyboard/2012/03/27/metatesting-understanding-mock-objects/">this new post</a> to his blog <i>Chris Hartjes</i> gets into some details about some complex mocking he recently had to do in a project for work. He includes code snippets to illustrate.
</p>
<blockquote>
With such an extensive array of tests [at work], I have received an education in what it really means to write unit tests for live, production-ready code that really takes unit testing seriously. [...] If you are really writing your unit tests the way you should, each test is focusing on testing one bit of functionality in isolation, which means that you will be heavily relying on mock objects to make things work. I've come up with an example scenario that I hope goes a long way to explaining how to effectively use mock objects.
</blockquote>
<p>
In his example, he shows how to mock out two objects, "Foo" and "Bar" that are passed into a method in his "Alpha" class. He looks at the code for the "Foo" class and creates a mock object based on its contents - two methods: "getId" and "getDetails". He does the same with the "Bar" class, mocking the "getStartDate" and "getEndDate" methods and showing how to pass those into the "munge" method on the "Alpha" class, complete with return values to match the tests.
</p>
<p>
For more information on PHPUnit's mock object support, see <a href="http://www.phpunit.de/manual/3.0/en/mock-objects.html">this page</a> in its manual. You might also explore another popular option, <a href="https://github.com/padraic/mockery">Mockery</a>.
</p>]]></description>
      <pubDate>Wed, 28 Mar 2012 08:19:20 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Emran Hasan's Blog: Using Mockery as a mocking framework with PHPUnit]]></title>
      <guid>http://www.phpdeveloper.org/news/17732</guid>
      <link>http://www.phpdeveloper.org/news/17732</link>
      <description><![CDATA[<p>
<i>Emran Hasan</i> has <a href="http://phpfour.com/blog/2012/03/using-mockery-as-a-mocking-framework-with-phpunit/">posted an introduction</a> to using the <a href="https://github.com/padraic/mockery">Mockery</a> mocking tool with <a href="http://phpunit.de">PHPUnit</a> for a more powerful, easier to use object mocking system.
</p>
<blockquote>
A few days ago I was explaining mocking to a few colleagues. I came up with the following quick n dirty code to show them the elegance of Mockery as a mocking framework. The code is straight-forward: it checks the health of a server using a tiny heart beat script.
</blockquote>
<p>
He provides both sides of the code - a simple "heartbeat" script that just responds with a JSON result, the class to consume it, a HTTP wrapper class that will be the target of the mock and his PHPUnit tests (testSystemIsOnlineWhenServiceRuns). You can see the use of the Mockery tool in this test.
</p>]]></description>
      <pubDate>Mon, 26 Mar 2012 14:52:03 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[DZone.com: PHP objects in MongoDB with Doctrine]]></title>
      <guid>http://www.phpdeveloper.org/news/17705</guid>
      <link>http://www.phpdeveloper.org/news/17705</link>
      <description><![CDATA[<p>
On DZone.com today <i>Giorgio Sironi</i> has a new post showing how you can <a href="http://css.dzone.com/articles/php-objects-mongodb-doctrine">use Doctrine with MongoDB</a> to work with Document objects from the database.
</p>
<blockquote>
In the PHP world, probably the Doctrine ODM for MongoDB is the most successful. This followes to the opularity of Mongo, which is a transitional product between SQL and NoSQL, still based on some relational concepts like queries. [...] The case for an ODM over a plain Mongo connection object is easy to make: you will still be able to use objects with proper encapsulation (like private fields and associations) and behavior (many methods) instead of extracting just a JSON package from your database.
</blockquote>
<p>
He briefly mentions that the PECL extension for Mongo needs to be installed prior to trying out any of the examples. His first example shows how to create a DocumentManager (similar to the normal EntityManager for those familiar with Doctrine). He also shows an integration with the ORM and shares some of the findings he's made when it comes to versioning the resources (hint: annotations are your friend).
</p>
]]></description>
      <pubDate>Wed, 21 Mar 2012 10:03:59 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Refulz.com: The __toString() Method - Objects as Strings]]></title>
      <guid>http://www.phpdeveloper.org/news/17523</guid>
      <link>http://www.phpdeveloper.org/news/17523</link>
      <description><![CDATA[<p>
On the Refulz.com blog there's a <a href="http://php.refulz.com/magic-methods-in-php-tostring-method/">recent post</a> introducing the __toString() magic method in PHP. This handy method allows you to define how to return an object when it's referenced as a string.
</p>
<blockquote>
We started the study of PHP magic methods by learning about <a href="http://php.refulz.com/magic-methods-in-php-__get-method/">__get() magic method</a>. [...] PHP is loosely typed language and same variable can be used or referred as string, number or object. The __toString() method is called when the code attempts to treat an object like a string. This function does not accept any arguments and should return a string.
</blockquote>
<p>
Some quick code is included showing how it works - returning a combined string made from two private class properties when the object ($obj) is echoed out. They also show multiple ways of using the method in both pre- and post-PHP 5.2.
</p>]]></description>
      <pubDate>Thu, 09 Feb 2012 09:27:19 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Developer Drive: Building a PHP Ad Tracker: Data Object Design and Coding]]></title>
      <guid>http://www.phpdeveloper.org/news/17518</guid>
      <link>http://www.phpdeveloper.org/news/17518</link>
      <description><![CDATA[<p>
Continuing on from <a href="http://phpdeveloper.org/news/17400">the first part</a> of their tutorial series about creating a simple ad tracker for your web application, Developer Drive is back with <a href="http://www.developerdrive.com/2012/02/php-ad-tracker-part-ii-data-object-design/">part two</a>, a more in-depth look at the actual object design and code.
</p>
<blockquote>
In our last PHP Ad Tracker lesson, we constructed the database tables for our ad banner application. Now we are ready to construct the data object that will hold the variables and functions that will display, add, edit and delete the data in those tables.
</blockquote>
<p>
They cover each of the variables they'll be using with a summary of what they're used for as well as the various functions to be defined and what they'll return. Following this, they get into the actual development - creating an "ads" class and defining the methods to get the current ad count, get the number of clients and pull the actual client/ad data.
</p>]]></description>
      <pubDate>Wed, 08 Feb 2012 12:57:54 -0600</pubDate>
    </item>
    <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[Davey Shafik's Blog: The Closure Puzzle]]></title>
      <guid>http://www.phpdeveloper.org/news/17397</guid>
      <link>http://www.phpdeveloper.org/news/17397</link>
      <description><![CDATA[<p>
<i>Davey Shafik</i> has <a href="http://daveyshafik.com/archives/32789-the-closure-puzzle.html">posted about an interesting find with closures</a> in PHP revolving around an update to add "$this" access inside the closure.
</p>
<blockquote>
However, it didn't stop there; there was also the addition of Closure::bind() and Closure->bindTo(). These methods are identical except one is a static method into which the closure is passed, the second an instance method on the closure itself. These methods both take two arguments (on top of the closure for the static version): $newthis and $newscope. What this means is that unlike the regular object model the concept of $this and lexical scope (what is in scope for the function with regards to private/protected methods inside objects) are completely separated.
</blockquote>
<p>
He also mentions that you can change the "$this" to a different object (complex) or swapping out the object the closure is bound to while keeping "$this" the same (simpler). He mentions that it could be useful for unit testing but can have its drawbacks. He's <a href="https://gist.github.com/1607647">included code</a> to illustrate 
 the breakage it can cause in the PHP OOP model (with an explanation).
</p>]]></description>
      <pubDate>Mon, 16 Jan 2012 09:52:38 -0600</pubDate>
    </item>
  </channel>
</rss>

