<?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 09:13:48 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[NetTuts.com: Expressive Tests with Hamcrest]]></title>
      <guid>http://www.phpdeveloper.org/news/18855</guid>
      <link>http://www.phpdeveloper.org/news/18855</link>
      <description><![CDATA[<p>
On the NetTuts.com site today there's a new tutorial introducing <a href="http://net.tutsplus.com/articles/news/expressive-tests-with-hamcrest/">the Hamcrest validation matchers</a> and how to use them in your PHPUnit testing to enhance both the readability and functionality of the assertions.
</p>
<blockquote>
Hamcrest is a set of matchers for writing more expressive code. It just so happens that these matchers are especially useful when writing tests. In this article, we'll look at <a href="http://code.google.com/p/hamcrest/">Hamcrest</a> for PHP. [...] Hamcret's expressiveness originated with JMock, but it wasn't until the addition of the unique assertThat() method that it was refactored into a self-contained library and independently usable in testing frameworks.
</blockquote>
<p>
He talks about the "generations" of unit testing tools, a division based on their assertion functionality - simple, exact or using matchers. Installation instructions via PEAR are included (though there's also <a href="https://packagist.org/packages/davedevelopment/hamcrest-php">a composer package</a> for it too) as well as code for an example test. More samples are given for comparing things like numeric values, strings and setting up inclusions and exclusions with the anyOf/noneOf matchers.
</p>]]></description>
      <pubDate>Thu, 06 Dec 2012 12:25:12 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPFreaks.com: PCRE Regex Spotlight: K]]></title>
      <guid>http://www.phpdeveloper.org/news/13104</guid>
      <link>http://www.phpdeveloper.org/news/13104</link>
      <description><![CDATA[<p>
On the PHPFreaks.com blog today there's <a href="http://www.phpfreaks.com/blog/pcre-regex-spotlight-k">a quick new post</a> looking at one of the special backslash strings that doesn't get talked about very much - K - but is quite powerful.
</p>
<blockquote>
One backslash sequence that doesn't get much attention is K. What this handy little assertion does is match the position of whatever string comes before it in the pattern, then it in essence resets the match. At that point it starts a new match with whatever comes after K from the current location in the subject string.
</blockquote>
<p>
They include a series of PHP code examples showing how use can use it to work around some of the issues with lookbehind assertions. They also include a few benefits and drawbacks of using them over lookbehinds.
</p>]]></description>
      <pubDate>Tue, 25 Aug 2009 10:28:44 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Ralph Schindler's Blog: Dynamic Assertions for Zend_Acl in ZF]]></title>
      <guid>http://www.phpdeveloper.org/news/13054</guid>
      <link>http://www.phpdeveloper.org/news/13054</link>
      <description><![CDATA[<p>
<i>Ralph Schindler</i> has <a href="http://ralphschindler.com/2009/08/13/dynamic-assertions-for-zend_acl-in-zf">a new post to his blog</a> today looking at using dynamic assertions with the access control component (Zend_Acl) of the Zend Framework.
</p>
<blockquote>
Over the last two years, I've seen a variety of duplicate issues come into the issue tracker, which stem from two fundamental flaws in Zend_Acl [...] In this article, we'll explore the API changes that alleviate these two problems, and we'll demonstrate how to leverage the Zend_Acl assertion system to create expressive, dynamic assertions that work with your applications models.
</blockquote>
<p>
He mentions some of the backwards compatible changes that have been made to the ACL API including changes in the add() method and the ability to create Zend_Acl_Role and Zend_Acl_Resource objects explicitly. The rest of the post gives a great example of setting up users in a role, creating an action to test them against (can they work with a blog post?) and running a series of checks against the ACL component as a guest, contributor and publisher.
</p>]]></description>
      <pubDate>Mon, 17 Aug 2009 12:37:17 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[PHP in Action Blog: One behavior != one assertion]]></title>
      <guid>http://www.phpdeveloper.org/news/12011</guid>
      <link>http://www.phpdeveloper.org/news/12011</link>
      <description><![CDATA[<p>
On the PHP in Action blog, despite some agreement with <i>Padraic Brady</i> on his <a href="http://www.phpdeveloper.org/news/11958">one behavior, one assertion</a> method for writing unit tests, <i>Dagfinn Reiersol</i> still <a href="http://blog.agilephp.com/2009/02/21/one-behavior-one-assertion/">has his reservations</a>.
</p>
<blockquote>
Pádraic maintains that one assertion per test is a rule that should always be followed unless there is a specific good reason to break it. I prefer it as a guideline, as does Robert C. Martin in the book <a href="http://www.amazon.com/gp/product/0132350882?ie=UTF8&tag=phinac-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0132350882">Clean Code</a>. The reference is not intended as an appeal to authority to "prove" that I'm right. I'm just making the point that I think this reflects the current state of the art, which is not necessarily perfect, of course.
</blockquote>
<p>
<i>Dagfinn</i> talks about behavior-driven development and illustrates how a two assertions could be combined into one but that the end result "isn't very pretty" - and that's just testing two proterties of a single object. Imagine what would happen if things got more complex.
</p>]]></description>
      <pubDate>Tue, 24 Feb 2009 11:13:17 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Padraic Brady's Blog: Unit Testing: One Test, One Assertion - Why It Works]]></title>
      <guid>http://www.phpdeveloper.org/news/11958</guid>
      <link>http://www.phpdeveloper.org/news/11958</link>
      <description><![CDATA[<p>
<i>Padraic Brady</i> has <a href="http://blog.astrumfutura.com/archives/388-Unit-Testing-One-Test,-One-Assertion-Why-It-Works.html">pormoted simplicity</a> for unit testing in his latest blog post. He suggests that, for each test in your suite, you have only one assertion inside.
</p>
<blockquote>
Obviously, a ratio of 1:1 would be perfect - but I'm sure we can accept some multiple assertions within a tolerance level. A ratio of more than 1.1:1 would indicate creeping obscurity (a signal it's time for me to intervene, refactor, and do some mutation testing for extra assurance). A ratio of 2:1 indicates a lost cause.
</blockquote>
<p>
He <a href="http://blog.astrumfutura.com/archives/388-Unit-Testing-One-Test,-One-Assertion-Why-It-Works.html">notes</a> that it probably sounds like a bad idea from the start, but he reinforces the suggestion with a bit of reasoning:
</p>
<blockquote>
It's this notion of complexity that is often used to justify multiple assertions - if you break it down into the simple components that that complexity was built out of, multiple assertions don't have a leg to stand on (just the rare instances out of your control because they absolutely must be done).
</blockquote>
<p>
You can see <a href="http://blog.agilephp.com/2009/02/15/one-assertion-per-test%E2%80%94always/">response that's been posted</a> over on the PHP in Action blog in response to <i>Padraic</i>'s thoughts.
</p>]]></description>
      <pubDate>Tue, 17 Feb 2009 07:56:09 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Padraic Brady's Blog: Unit Testing: Multiple Assertions And Lazy/Shallow Testing Are Evil]]></title>
      <guid>http://www.phpdeveloper.org/news/11945</guid>
      <link>http://www.phpdeveloper.org/news/11945</link>
      <description><![CDATA[<p>
In <a href="http://blog.astrumfutura.com/archives/387-Unit-Testing-Multiple-Assertions-And-LazyShallow-Testing-Are-Evil.html">a new post</a> today <i>Padraic Brady</i> takes a look at unit testing and two of the bad practices that can develop over time when writing your tests - overloading tests with assertions and lazy/shallow tests.
</p>
<blockquote>
In short, every test you write requires that you setup the test environment, create a scenario for possible failure, add an assertion, and then ensure the source code makes that assertion pass. This requires code - sometimes a lot of code. So adding multiple assertions to each test minimizes the work needed to write tests, since using multiple assertions takes advantage of existing code to avoid writing new stuff to clutter your test classes. It can also help to tackle multiple but related results in the same test.
</blockquote>
<p>
He gives brief examples of both instances and some of the problems associated with them. Multiple assertions, while nice for fine tuning the results of the testing, can also confuse since, if one assertion fails, the whole test fails too. The other end of the spectrum is a problem too - writing tests that don't do enough to really check the information passed in. These shallow tests can lead to issues down the line if unanticipated data might come along. 
</p>
<p>
Really, its all about finding that "sweet spot" in developing tests - not too much, not too little - and keeping it simple while not missing out on assertions that need to be made.
</p>]]></description>
      <pubDate>Fri, 13 Feb 2009 09:31:33 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Raphael Stolt's Blog: Creating custom PHPUnit assertions]]></title>
      <guid>http://www.phpdeveloper.org/news/10705</guid>
      <link>http://www.phpdeveloper.org/news/10705</link>
      <description><![CDATA[<p>
<i>Raphael Stolt</i> has <a href="http://raphaelstolt.blogspot.com/2008/07/creating-custom-phpunit-assertions.html">written up a post</a> for his blog talking about custom PHPUnit assertions and a simple method to create them.
</p>
<blockquote>
In this blog post I'd like to set the focus on some of the aspects of the <a href="http://xunitpatterns.com/Custom%20Assertion.html">Custom Assertion</a> pattern, by showing how to create custom <a href="http://www.phpunit.de/">PHPUnit</a> assertions, which attacks the above mentioned smell [of bad test code] and its retroactive effects with a huge antiperspirant flagon, while also providing the chance to build a customer friendly and domain related test vocabulary.
</blockquote>
<p>
His first assertion is simple, checking the contents of a bag object to be sure that there are no duplicate items and that its content count is reduced by one if something is removed. Then, he moves on to making the custom assertion for his "IdShouldFollowAgreedConvention" test. He explains how to use the assertion class and how it all fits together in the final, functional test case.
</p>]]></description>
      <pubDate>Tue, 29 Jul 2008 10:25:15 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Felix Geisendorfer's Blog: Assert the yummyness of your cake]]></title>
      <guid>http://www.phpdeveloper.org/news/8906</guid>
      <link>http://www.phpdeveloper.org/news/8906</link>
      <description><![CDATA[<p>
<i>Felix Geisendorfer</i> has <a href="http://www.thinkingphp.org/2007/10/22/assert-the-yummyness-of-your-cake/">posted an addition</a> to his previous <a href="http://www.phpdeveloper.org/news/8878">look at exceptions</a> in CakePHP with a modification that uses assertions instead of an if to check the value of a variable.
</p>
<blockquote>
I suddenly remembered what assertions are and how they could make my code more readable, while making it shorter. I took a quick look at <a href="http://us.php.net/assert">PHP's assert function</a>, but decided that I don't like it. [...] What I ended up doing was basically to create a class called Assert, and abuse it as a name-space for a whole bunch of useful assertion functions.
</blockquote>
<p>
He includes two examples of how this new class would look, checking to see if a value is empty and to see if a task ID exists in a given value. The code for the assertion class is also included and has methods for checking things like "not empty", "equals to", "is not numeric" and "is an object". And, no, it's not CakePHP specific, so you could take it an use it anywhere.
</p>]]></description>
      <pubDate>Thu, 25 Oct 2007 12:16:00 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[SitePoint PHP Blog: pTest: PHP Unit Tester in 9 Lines Of Code]]></title>
      <guid>http://www.phpdeveloper.org/news/8438</guid>
      <link>http://www.phpdeveloper.org/news/8438</link>
      <description><![CDATA[<p>
On the SitePoint PHP blog, there's <a href="http://www.sitepoint.com/blogs/2007/08/13/ptest-php-unit-tester-in-9-lines-of-code/">a new post</a> from <i>Paul Annesley</i> about his latest creation - a nine line unit tester for PHP, pTest.
</p>
<blockquote>
I was recently working on a command line PHP tool, and didn't have easy access to our normal PHP unit testing framework built around <a href="http://simpletest.org/">SimpleTest</a>. [...] I didn't need support for <a href="http://en.wikipedia.org/wiki/Mock_object">mock objects</a> or complicated assertions - just a bare basic assertTrue() would do the trick.
</blockquote>
<p>
He <a href="http://www.sitepoint.com/blogs/2007/08/13/ptest-php-unit-tester-in-9-lines-of-code/">includes the code</a> (of course) and an example of it in action, three tests with their assertions. It's a simple little tool made of a simple purpose, a starting place for developers just learning unit testing to learn from.
</p>]]></description>
      <pubDate>Mon, 13 Aug 2007 12:05:00 -0500</pubDate>
    </item>
  </channel>
</rss>
