Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
Upgrading Sylius the TDD Way: Exploring PhpSpec & Behat
May 02, 2017 @ 11:49:02

On the SitePoint PHP blog they've continued their series looking at upgrading Sylius, an e-commerce application based on Symfony, with the help of test-driven development methods to ensure nothing breaks along the way. These next two articles cover the use of PhpSpec and using Behat for the different types of testing.

Last time, we developed some new features on top of Sylius’ core to indicate which products and their variants are low on stock and need replenishing. Now, we move on to seeing our changes in the UI, which means we will need to do a bit of StoryBDD testing.

In [the third] part, [we] extend some core classes to indicate color-coded inventory status. First, we’ll deal with the back end part. In a followup post, we’ll use Behat and test the visual changes. Please follow the instructions in the previous post to get a working instance up and running.

In each of the tutorials they walk you through the changes you'll need to make on the Sylius side to test both the Inventory and Product functionality that already come with the package. Examples of each kind of test are included as well as the output from the example test runs.

tagged: testing sylius tdd testdrivendevelopment phpspec behat

Link: https://www.sitepoint.com/upgrading-sylius-tdd-way-exploring-phpspec

SitePoint PHP Blog:
API Client TDD with Mocked Responses
Feb 19, 2015 @ 12:57:51

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.

tagged: mock response tutorial unittest testdrivendevelopment api client

Link: http://www.sitepoint.com/api-client-tdd-mocked-responses/

Mathias Verraes:
How Much Testing is Too Much?
Jan 02, 2015 @ 11:55:43

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.

tagged: unittest testdrivendevelopment tdd too much overdesign refactor delete

Link: http://verraes.net/2014/12/how-much-testing-is-too-much/

Inviqa Blog:
How clean is your code?
Jun 13, 2014 @ 10:55:44

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.

tagged: testdrivendevelopment tdd code hygiene training bdd

Link: http://inviqa.com/blog/how-clean-is-your-code/

Dave Marshall's Blog:
How I'm doing TDD with PHP
Jun 07, 2012 @ 11:31:51

Dave Marshall has shared his method behind using test-driven development in his recent development.

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.

tagged: tdd testdrivendevelopment tool execution


Freek Lijten's Blog:
Book Review - Growing Object-oriented software guided by tests
Mar 12, 2012 @ 13:57:57

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.

tagged: objectoriented tdd testdrivendevelopment software book review


Community News:
Learn Test-Driven Development with Munchkin
Aug 04, 2010 @ 12:09:04

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.

tagged: testdrivendevelopment tdd unittest munchkin


MakeGood - A test runner for doing Test Driven Development with Eclipse PDT
Jul 07, 2010 @ 13:39:56

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.

tagged: eclipse ide eclipsepdt testdrivendevelopment tdd plugin makegood


Avnet Labs Blog:
TDD with Zend Framework
Nov 03, 2009 @ 12:55:57

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.

tagged: ttd testdrivendevelopment zendframework tutorial


Jani Hartikainen's Blog:
Unit testing 5: test-driven development
Jul 06, 2009 @ 22:06:27

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.

tagged: tutorial testdrivendevelopment tdd unittest