<?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, 25 May 2013 03:20:35 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[NetTuts.com: How to Write Testable and Maintainable Code in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/19594</guid>
      <link>http://www.phpdeveloper.org/news/19594</link>
      <description><![CDATA[<p>
NetTuts.com has a new tutorial posted suggesting a few ways you can make <a href="http://net.tutsplus.com/tutorials/php/how-to-write-testable-and-maintainable-code-in-php/">testable and maintainable code</a> in PHP applications.
</p>
<blockquote>
Frameworks provide a tool for rapid application development, but often accrue technical debt as rapidly as they allow you to create functionality. Technical debt is created when maintainability isn't a purposeful focus of the developer. Future changes and debugging become costly, due to a lack of unit testing and structure. Here's how to begin structuring your code to achieve testability and maintainability - and save you time.
</blockquote>
<p>
There's a few concepts they cover in the tutorial including DRY (don't repeat yourself), working with dependency injection and actually writing the tests with PHPUnit. They start with a bit of code that needs some work and use the tests to help refactor it into something that can be easily mocked (using <a href="http://net.tutsplus.com/tutorials/php/mockery-a-better-way/">Mockery</a>). 
</p>
Link: http://net.tutsplus.com/tutorials/php/how-to-write-testable-and-maintainable-code-in-php]]></description>
      <pubDate>Thu, 16 May 2013 11:53:18 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[DZone.com: PHPUnit vs. Phake cheatsheet]]></title>
      <guid>http://www.phpdeveloper.org/news/19483</guid>
      <link>http://www.phpdeveloper.org/news/19483</link>
      <description><![CDATA[<p>
On DZone.com today <i>Giorgio Sironi</i> has posted a "cheat sheet" to help you correlate the functionality of two PHP unit testing tools - <a href="http://css.dzone.com/articles/phpunit-vs-phake-cheatsheet">PHPUnit vs Phake</a> (for mocking objects).
</p>
<blockquote>
Benjamin Eberlei introduced me to Phake with his recent article: it is a Composer-ready PHP library that integrates easily with PHPUnit and provides an independent Test Doubles framework, capable of producing Stubs, Mocks, and Spies. The syntax and object model reminds me of Mockito, the Java Test Double framework from the authors of Growing Object-Oriented Software. I like tools that do one thing and do it well, and after experimenting with Phake I'm using it on all new code. 
</blockquote>
<p>
He compares the two tools on a few different pieces of functionality including creating stubs, mocks and spies. Sample code is included for both sides. It's not a detailed guide by any means, but it can give you a better picture of how the two compare.
</p>
Link: http://css.dzone.com/articles/phpunit-vs-phake-cheatsheet]]></description>
      <pubDate>Fri, 19 Apr 2013 09:53:45 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Juan Treminio: Unit Testing Tutorial Part V: Mock Methods and Overriding Constructors]]></title>
      <guid>http://www.phpdeveloper.org/news/19416</guid>
      <link>http://www.phpdeveloper.org/news/19416</link>
      <description><![CDATA[<p>
<i>Juan Treminio</i> has posted the <a href="http://jtreminio.com/2013/03/unit-testing-tutorial-part-5-mock-methods-and-overriding-constructors/">latest part of his unit testing series</a> to his site today - the fifth part that looks at using mock methods on mock objects and overriding constructors.
</p>
<blockquote>
Previously in my PHPUnit tutorial series, you learned about the very powerful concept of mock objects and stub methods. This concept is central to successful unit testing, and once it fully 'clicks' in your head you will start to realize how useful and simple testing can be. There is also another thing I want to make clear: creating tests is basically a puzzle - you simply have to go step by step, making sure all the pieces fit together correctly so you can get your green. I hope to make clear what I mean by the end of this tutorial.
</blockquote>
<p>
He assumes you already know about mock objects and introduces the concept of "stub methods" and "mock methods", noting the difference between them. He then gets into what he calls the "four pathways of getMockBuilder" and talks about the rationale behind mocking methods in the first place. He then gets into constructors and how you can work around the "bad" ones with help from mock object functionality. 
</p>
<p>
If you're interested in reading the rest of the series, you can find links to them <a href="http://jtreminio.com/tag/phpunit/">here</a>.
</p>
Link: http://jtreminio.com/2013/03/unit-testing-tutorial-part-5-mock-methods-and-overriding-constructors/]]></description>
      <pubDate>Fri, 05 Apr 2013 09:38:49 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Michelangelo van Dam: Look mama, no databases]]></title>
      <guid>http://www.phpdeveloper.org/news/19325</guid>
      <link>http://www.phpdeveloper.org/news/19325</link>
      <description><![CDATA[<p>
In his most recent post <i>Michelangelo van Dam</i> talks about <a href="http://www.dragonbe.com/2013/03/look-mama-no-databases.html">unit testing and databases</a> and how, to effectively test what should be tested (the code, not "the ability to fetch data") you need to correctly mock your database objects.
</p>
<blockquote>
When I state "as is", I truly mean the way it's being used in production. So the database call collects real data on which business logic is applied. You can see this is not a healthy situation, especially when you also have services that apply business logic on data and store it back into the database. In "<a href="https://leanpub.com/grumpy-phpunit?ref=dragonbe>The Grumpy Programmer's PHPUnit Cookbook</a>", author <a href="https://twitter.com/grmpyprogrammer">Chris Hartjes</a> wrote this one sentence that says it all: "Unit test suites are meant to be testing code, not the ability of a database server to return results". And he's right, you shouldn't use database connections when your testing business rules and functional logic.
</blockquote>
<p>
He goes on to show a few code examples that show a pre-mocked state of testing where the Product information is pulled directly from a PDO connection. The more correct version mocks out this object, though, and overrides the "execute" and "fetchAll" methods to return mocked results. 
</p>]]></description>
      <pubDate>Mon, 18 Mar 2013 10:11:46 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Matt Frost: Mocking SoapClient]]></title>
      <guid>http://www.phpdeveloper.org/news/18932</guid>
      <link>http://www.phpdeveloper.org/news/18932</link>
      <description><![CDATA[<p>
<i>Matt Frost</i> has <a href="http://shortwhitebaldguy.com/blog/2012/12/mocking-soapclient">shared some of his work</a> he's done with the <a href="http://php.net/soap">SoapClient</a> in PHP and how he mocked it out for his unit tests (since it's an external resource).
</p>
<blockquote>
The concept of mocking web services for testability took a little while to sink in for me. A big part of it was that my job doesn't see me consuming web services all that often, but I had an opportunity to give it a shot with SOAP. I found that I learned a lot more about testing in general having worked through this. I used SoapClient and wrapped it, so here's a little bit about some of things I learned. Hopefully you don't have to work with SOAP, but if you do you can test it pretty easily.
</blockquote>
<p>
He walks through the mocking of the client itself and how he handled it's ability to translate function calls into SOAP method calls (using "__call") and how he mocked that. He also makes the suggestion that you actually wrap the SoapClient inside of another class rather than trying to mock the actual SoapClient. He also touches on the testing of exceptions that might be thrown by the service and how he tested those using his wrapper class.
</p>]]></description>
      <pubDate>Fri, 21 Dec 2012 10:23:02 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[NetTuts.com: Mockery: A Better Way]]></title>
      <guid>http://www.phpdeveloper.org/news/18790</guid>
      <link>http://www.phpdeveloper.org/news/18790</link>
      <description><![CDATA[<p>
On NetTuts.com there's a new tutorial posted showing you how to <a href="http://net.tutsplus.com/tutorials/php/mockery-a-better-way/">use Mockery in your unit testing</a> as an alternative to the built-in mocking tools of something like <a href="http://phpunit.de">PHPUnit</a>.
<p>
<blockquote>
<a href="https://github.com/padraic/mockery">Mockery</a> is a PHP extension that offers a superior mocking experience, particularly when compared to <a href="http://www.phpunit.de/manual/current/en/index.html">PHPUnit</a>. While PHPUnit's mocking framework is powerful, Mockery offers a more natural language with a Hamcrest-like set of matchers. In this article, I'll compare the two mocking frameworks and highlight the best features of Mockery.
</blockquote>
<p>
He walks you through the installation of Mockery and includes the code for a sample PHPUnit test that creates a Mockery instance and mocks out a class object for testing. He moves on to more examples including:
</p>
<ul>
<li>Adding expects for method calls (single and multiple)
<li>Returning values from the methods
<li>Calling multiple methods
<li>Returning different things based on parameters
<li>Partial mocks
<li>Handling constructor parameters
</ul>]]></description>
      <pubDate>Thu, 22 Nov 2012 12:06:02 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Michelangelo van Dam: Learning lessons at ZendUncon]]></title>
      <guid>http://www.phpdeveloper.org/news/18737</guid>
      <link>http://www.phpdeveloper.org/news/18737</link>
      <description><![CDATA[<p>
<i>Michelangelo van Dam</i> has shared something new he learned at the recent ZendCon conference about <a href="http://www.dragonbe.com/2012/11/learning-lessons-at-zenduncon.html">using fixtures with his PHPUnit testing</a>.
</p>
<blockquote>
In <a href="http://www.dragonbe.com/2012/11/zendcon-2012.html">my previous post</a> I already mentioned Sebastian Jerzy Wilczy&#324;ski (<a href="http://twitter.com/dj_sebastian_w">@dj_sebastian_w</a>) and his uncon session "<a href="https://github.com/swilczynski/unittesting">Unit Testing for Databases using fixtures and phpunit</a>". It made me wonder how much difference it would make if you use fixtures instead of testing database interactions using predefined sets of data. Since I work a lot with Zend Framework I was looking at how I could use fixtures and mock objects to follow Sebastian's guidelines. So I gave it a try. This is what I came up with.
</blockquote>
<p>
He illustrates with some example code - a set of database data (the fixtures) and sample tests that use the Zend Framework's mapper and table gateway functionality to work with the tables. His test then mocks out the DbTable class for the "Order" object and forces a return of the database fixture data.
</p>]]></description>
      <pubDate>Tue, 13 Nov 2012 10:04:55 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: An Introduction to Mock Object Testing]]></title>
      <guid>http://www.phpdeveloper.org/news/18256</guid>
      <link>http://www.phpdeveloper.org/news/18256</link>
      <description><![CDATA[<p>
In <a href="http://phpmaster.com/an-introduction-to-mock-object-testing/">this new tutorial</a> on PHPMaster.com <i>Jose Asuncion</i> walks you through the use of mock objects in your unit testing.
</p>
<blockquote>
If you are part of a development team, more often than not your code will also depend on code written by your teammates. But what if their code isn't available at the moment - say, your teammate hasn't finished writing it yet? Or, what if the code you need requires other external dependencies that are hard to set up? And what if you cannot test code because of other factors beyond your control? Will you just hang around, do nothing, and wait until your team is done or when everything is in place? Of course not! In this this article, I'll illustrate how to write code that works around this problem with dependencies.
</blockquote>
<p>
He starts off by making a case for using mock objects and having them replace things that either aren't finished or depends on things that are hard to replicate (like external dependencies). He includes some example code showing them in use in a PHPUnit-based test and how to use its own mocking abilities so you don't have to manually make mock classes yourself.
</p>]]></description>
      <pubDate>Fri, 20 Jul 2012 17:18:06 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[DZone.com: Testing PHP scripts]]></title>
      <guid>http://www.phpdeveloper.org/news/17870</guid>
      <link>http://www.phpdeveloper.org/news/17870</link>
      <description><![CDATA[<p>
In <a href="http://css.dzone.com/articles/testing-php-scripts">this new post</a> to DZone.com, <i>Giorgio Sironi</i> talks about a method of testing that's non-invasive when you're in a chicken-and-egg kind of situation:
</p>
<blockquote>
The legacy code dilemma, however, is always present: you can't refactor the code before putting up some tests on it to avoid regressions and putting your application offline. At the same time, you can't easily unit test the code until some refactoring is introduced.
</blockquote>
<p>
He suggests making copies of some files to allow you to make small changes where needed to "mock" resources in the application to prevent it from accessing the actual data sources. His method fakes HTTP requests to the script and uses the copy of the script as an internal resource. Don't worry, code is included showing how its done - a basic "ForumPosting" class that includes the needed file and wraps the output in a buffer.
</p>]]></description>
      <pubDate>Thu, 26 Apr 2012 10:50:24 -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>
  </channel>
</rss>
