PHPDeveloper.orghttp://www.phpdeveloper.org
Up-to-the Minute PHP News, views and communityen-usTue, 31 Mar 2015 17:04:19 -050030http://www.phpdeveloper.org/news/22392http://www.phpdeveloper.org/news/22392
The SitePoint PHP blog has posted the third part of their series guiding you through the creation of your first PHP package with a look at mocking API responses in unit tests created via the TDD (test-driven development) process.

In parts one and two, we built some very basic functionality and used TDD with PHPUnit to make sure our classes are well tested. We also learned how to test an abstract class in order to make sure its concrete methods worked. Now, let's continue building our library.

He starts with a bit of catching up to ensure everyone is on the same page in the development process. From there he starts in on the mocking of the API, preventing the need for the (slow) external requests. He shows some updates that are needed to the main DiffBot class, the factories/entities for making objects for requests and examples of putting these to use in a few tests. Finally he shows the creation of the mocks themselves and the result from a sample test.

Link: http://www.sitepoint.com/api-client-tdd-mocked-responses/]]>Thu, 19 Feb 2015 12:57:51 -0600http://www.phpdeveloper.org/news/22178http://www.phpdeveloper.org/news/22178
In his latest post Mathias Verraes poses the question of how much testing is too much? At what point does testing actually become less useful and how much you really need.

Figuring out how much unit tests you need to write, can be tricky, especially if you are new to Test-Driven Development. Some teams strive for 100% code coverage. Some open source projects even announce their test coverage on their GitHub profiles - as if coverage is an indicator of quality. Coverage only measures the lines of code that are executed by the test suite. It doesn't tell you whether the outcome of the execution is actually tested, let alone how valuable that test is. Because of that, code coverage of your entire code base is a pretty lousy metric.

He suggests that the "it depends" answer to "how much testing is enough" question just isn't good enough. He puts most of this in the context of TDD (where testing is built-in to the development time) but some of the thoughts could apply to post-code testing as well. He also talks about over-design and how it relates to refactoring with deeper insight. Finally, he talks about a subject not mentioned much in testing articles - when to delete tests.

Link: http://verraes.net/2014/12/how-much-testing-is-too-much/]]>Fri, 02 Jan 2015 11:55:43 -0600http://www.phpdeveloper.org/news/21300http://www.phpdeveloper.org/news/21300
In this latest post to the Inviqa blog they ask the question "how clean is your code?" and offer a few tips to help it get that way (and stay that way).

During the Test Driven Development training (which includes Behat, and PHPspec) run by Marcello Duarte, I was particularly blown away by one of his many and funny analogies… "Would you have any surgery carried out by a doctor who does not wash his hands?" Everybody in the room shook their heads. Of course nobody would. There is too a high risk of complications. In software development 'infected' code can translate to bugs, bad user experience, poor performance and the complete failure of web applications.

He talks briefly about some of the lessons learned in this training session, pointing out that while it's not the easiest method to apply, it pays off in the long run of your code's "hygiene". He points out that the [Inviqa] group's success rate with TDD/BDD has reflected in the bottom line of their enterprise clients too.

I've been watching the Destroy All Software back catalog over the last couple of months and it's really inspired me to up my TDD game. I'm still fairly new to TDD, I've written tests for a long time, but never really let it lead my development…

He talks about the testing tool he uses and some of the ideals he keeps in mind when developing his tests. He also comments on testing isolation, speed of execution, the "fail fast" idea as well as integration testing and continuous integration.

]]>Thu, 07 Jun 2012 11:31:51 -0500http://www.phpdeveloper.org/news/17661http://www.phpdeveloper.org/news/17661
Freek Lijten has a new post to his blog - a review of a book (from Freeman & Price) called "Growing Object-Oriented Software Guided by Tests". It's based on Java, but the ideas presented can be applied pretty universally.

It may seem strange but I'd like to start out with giving my opinion on this book: It is brilliant! If you don't like reading my post you at least know what you should do next: buy the friggin' book. The book offers some theory concerning agile development, (unit-)testing and code quality but its killer feature is the almost 200 page long example of developing an application the TDD way! In the rest of this post I will shortly highlight different parts of the books and stuff I enjoyed or learned from it.

He breaks up the review in to a few different parts - the process of test-driven development, his "first real lesson", their working example and a section about the more advanced topic of sustainable test driven development.

]]>Mon, 12 Mar 2012 13:57:57 -0500http://www.phpdeveloper.org/news/14904http://www.phpdeveloper.org/news/14904
In this new post to his blog Giorgio Sironi points out a new project that wants to help you get started with test-driven development - Munchkin.

Meszaros Marton and other PHP coders have started a Test-Driven Development project centered on showing the methodology to new adopters in a green field. The goal of the project, named Munchkin, is creating a feed aggregator - like Google Reader - from scratch. The authors will post a series of articles about their development process along the way. If you want to follow a step-by-step guide to implementing an Agile project with TDD in PHP, follow them.

Their goal is to show you not only how TDD can make your application better but detailed tutorials on setting up your environment and making effective use of the tools in an agile environment.

]]>Wed, 04 Aug 2010 12:09:04 -0500http://www.phpdeveloper.org/news/14759http://www.phpdeveloper.org/news/14759
Goran has pointed out a plugin for Eclipse that can help those out there wanting to adopt Test-Driven Development into their process - MakeGood (screenshot here).

MakeGood provides a test runner to run unit tests on Eclipse PDT. MakeGood strongly supports Test Driven Development (TDD) by various features.

Features in the plugin include:

Runs all tests when a file is saved.

Debugs a test.

Reruns the last test.

Can use the system include path when running tests.

It supports both PHPUnit and SimpleTest so you're covered either way. It also supports the Zend Debugger and Xdebug for help with your debugging needs.

]]>Wed, 07 Jul 2010 13:39:56 -0500http://www.phpdeveloper.org/news/13475http://www.phpdeveloper.org/news/13475
On the Avnet Labs blog today Ekerete has kicked off a new series looking specifically at using test-driven design to create Zend Framework-based applications:

However, as useful as the series [from Jani Hartikainen on TTD] is, it doesn't provide answers to Zend Framework specific testing issues (and considering all the ZF-specific posts on his site, that's quite surprising). [...] In the coming weeks, I'll put together a how-to on testing ZF applications using a Test Driven Development (TDD) approach. With TDD tests are written first and as such the test suite guides the design of the production code.

He shows how to set up a sample application, the Jira Base, and how to set up a simple base-level test.

]]>Tue, 03 Nov 2009 12:55:57 -0600http://www.phpdeveloper.org/news/12817http://www.phpdeveloper.org/news/12817
Jani Hartikainen has posted part five of his look at unit testing in PHP (with PHPUnit) focusing on test-driven development.

The difference between "normal" and test-driven development (TDD) is that when doing TDD, you write unit tests for your new code before writing the code itself. This way you ensure good test coverage for your code, and your code will also be more flexible and reusable, as you have to design the class interfaces for easy testing.

He looks at some of the basics - like preconditions and postconditions - and how to create the tests for your application before you write a single line of (non-test) code. His examples show evaluations for testing for an empty order and to see if an object has an item in it after it's been added.

Symfony is one of the few PHP frameworks that gives you basic tools for starting to write tests. [...] Symfony also provides an extension of this class called sfTestBrowser, designed especially for functional tests, which has all the abilities of the sfBrowser object plus some smart assert methods.

He uses this sfTestBrowser object to run an example test on a same get() call's response. It should match the regular expression of "/This is a temporary page/" but doesn't so it fails. Writing up tests like this for new parts of your application first would be considered test-driven development and the Symfony framework makes that simple.