<?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, 19 Jun 2013 10:20:52 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Chris Hartjes' Blog: Monkey-patching Is for Closers]]></title>
      <guid>http://www.phpdeveloper.org/news/18227</guid>
      <link>http://www.phpdeveloper.org/news/18227</link>
      <description><![CDATA[<p>
In <a href="http://www.littlehart.net/atthekeyboard/2012/07/13/monkey-patching-is-for-closers/">this new post</a> to his blog <i>Chris Hartjes</i> looks at why "<a href="http://en.wikipedia.org/wiki/Monkey_patch">monkey patching</a> is for closers" - how it should be avoided in favor of making the code itself more testable rather than "hack" with the patching.
</p>
<blockquote>
The use of monkey-patching is extremely prevalent in the Ruby community and also to a certain extent in Python usage. I'm not going to go into length about their use of it except to say that it seems quite common and I think most developers are using it as a shortcut to counter what might be poor code architecture decisions. 
</blockquote>
<p>
He includes some example code, excerpted from a blogging system where <a href="http://php.net/manual/en/book.runkit.php">runkit</a> was originally use to test its functionally. He shows how some simple refactoring (adding input parameters, replacing a static method call, etc) makes it easier to unit test. Comments to the post include further refactoring ideas as well as a response from the <a href="http://antecedent.github.com/a-time-and-place-for-monkey-patching.html">original "offender"</a> whose post sparked <i>Chris'</i> response.
</p>]]></description>
      <pubDate>Mon, 16 Jul 2012 09:09:51 -0500</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[Till Klampaeckel's Blog: Monkey patching in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/14690</guid>
      <link>http://www.phpdeveloper.org/news/14690</link>
      <description><![CDATA[<p>
In a new post to his blog today <i>Till Klampaeckel</i> takes <a href="http://till.klampaeckel.de/blog/archives/105-Monkey-patching-in-PHP.html">a look at monkey patching</a> in PHP - a way to replace functions at runtime.
</p>
<blockquote>
I haven't really had the chance or time to play with PHP 5.3  until recently when Ubuntu 10.04 upgraded my local installations and kind of forced me to dive into it a little. And I'm also probably the last person on the planet to notice, but namespaces in PHP 5.3 allow you to monkey-patch core PHP code. [...] One of the more common applications is stubbing (or mocking) code in unit tests.
</blockquote>
<p>
He includes a code sample showing how you can use a simple namespace hack to call a function from another namespace named the same as an internal one - in this case <a href="http://php.net/strlen">strlen</a>.
</p>]]></description>
      <pubDate>Wed, 23 Jun 2010 10:31:09 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Benjamin Eberlei's Blog: Test your Legacy PHP Application with Function Mocks!]]></title>
      <guid>http://www.phpdeveloper.org/news/12243</guid>
      <link>http://www.phpdeveloper.org/news/12243</link>
      <description><![CDATA[<p>
<i>Benjamin Eberlei</i> <a href="http://www.whitewashing.de/blog/articles/115">has a suggestion</a> for testing your application without having to mess around with creating new resources just for testing - use mocks.
</p>
<blockquote>
Much talking is going on about Unit testing, Mocks and TDD in the PHP world. For the most this discussions surround object-oriented PHP code, frameworks and applications. Yet I would assert that the reality for PHP developers (me included) is dealing with PHP 4, PHP 5 migrated, or non-object oriented legacy applications which are near to impossible to bring under test.
</blockquote>
<p>
He includes a "proof of concept" for a replacement <a href="http://php.net/mysql_query">mysql_query</a> function (as created inside of Runkit) that sets up a "mocker" object that returns a "hello world" message when the mysql_query function is called.
</p>]]></description>
      <pubDate>Tue, 31 Mar 2009 11:18:31 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Arnold Daniels' Blog: PHP != Ruby (and why PHP needs more advanced OO stuff)]]></title>
      <guid>http://www.phpdeveloper.org/news/8427</guid>
      <link>http://www.phpdeveloper.org/news/8427</link>
      <description><![CDATA[<p>
In response to <a href="http://www.phpdeveloper.org/news/8418">this post on the ActsAsFlinn blog</a>'s comments on ActiveRecord in PHP, <i>Arnold Daniels</i> has some <a href="http://blog.adaniels.nl/?p=40">comments of his own</a> on the subject - specifically about the need for more work on the object oriented side of things in PHP natively.
</p>
<blockquote>
Today <a href="http://www.actsasflinn.com/articles/2007/08/08/php-and-activerecord">I read an article</a> about how Active Record is implemented in Ruby. In this article he lays down how things are done in Ruby and how that is not possible on PHP. Though I agree with him on a large part, there are a few site notes to make here.
</blockquote>
<p>
<i>Arnold</i> talks about a solution to an issue mentioned in the ActsAsFlinn blog - the addition of methods to a preexisting class - via the <a href="http://www.php.net/runkit">runkit extension</a>. He gives a PHP translation of the Ruby code from the other post and includes a few proof of concepts to show it in action. You can <a href="http://blog.adaniels.nl/downloads/sortable.tar.gz">download the code</a> if you'd like to try it out yourself.
</p>]]></description>
      <pubDate>Fri, 10 Aug 2007 10:22:00 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[David Sklar's Blog: Runkit, "static", and inheritance]]></title>
      <guid>http://www.phpdeveloper.org/news/7859</guid>
      <link>http://www.phpdeveloper.org/news/7859</link>
      <description><![CDATA[<p>
<i>David Sklar</i> <a href="http://www.sklar.com/blog/archives/108-Runkit,-static,-and-inheritance.html">points out</a> an issue that keeps coming up over and over again in the course of object-oriented applications - why the static keyword doesn't know about inheritance.
</p>
<blockquote>
<p>
There are plenty of good reasons why PHP 5 works this way and it seems that in PHP 6 the static keyword will be able to be used in place of self to get the dynamic behavior a lot of folks are looking for. [...] All well and good once PHP 6 is done.
</p>
<p>
In the meantime, I was noodling around with <a href="http://pecl.php.net/package/runkit">runkit</a> and came up with some glue that lets you do something like this.
</p>
</blockquote>
<p>
In his runkit example uses a glue class called MethodHelper that uses various things (including some reflection) to manually look into the classes and find the static information.
</p>
<blockquote>
A fun proof of concept, but not something (for efficiency reasons) you'd probably want to run on a busy production site. 
</blockquote>]]></description>
      <pubDate>Thu, 17 May 2007 08:43:00 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[OpenIdeasCompany.com: Redeclaring native PHP functions]]></title>
      <guid>http://www.phpdeveloper.org/news/5416</guid>
      <link>http://www.phpdeveloper.org/news/5416</link>
      <description><![CDATA[<p>
If you've ever really found a time when you needed to overwrite one of PHP's bult-in functions with your own custom one (maybe a custom handler or the like), you might want to check out <a href="http://openideascompany.com/bogomil/?p=42">this post</a> on OpenIdeasCompany.com.
</p>
<p>
The author needed to redeclare session_start in a few files to change the place the default sessions are located at (spanned across three machines). He didn't want to rewrite the application to make this change, so he used the runkit extension out of pecl (and the php-devel package) to create a solution redefining functions to match his needs.
</p>
<p>
Of course, there are some <a href="http://www.php.net/manual/en/function.session-save-path.php">easier</a> <a href="http://www.php.net/manual/en/function.session-set-save-handler.php">ways</a> to accomplish what he needed, but it's still an interesting method if there's really just no other way.
</p>]]></description>
      <pubDate>Mon, 22 May 2006 06:43:24 -0500</pubDate>
    </item>
  </channel>
</rss>
