PHPUnit is a unit testing software framework for PHP. It provides both a framework that makes writing unit tests easy as well as the functionality to easily run the tests and analyze their results. This video shows you how to build a relatively simple class, using TDD techniques. It also discusses various PHPUnit methods and explains how to create mock objects.
There are solutions which provide the ability to automatically run your tests as you code. This tutorial shows how to use a Ruby gem, called watchr to monitor your code and automatically run the appropriate tests whenever you save your work. This is how you can automated Test-Driven Development (TDD) on your PHP code. The watchr gem is an executable program written in Ruby, and it wraps around features found in an operating system’s file system to provide the ability to watch for changes made to a specific file or folder. The tutorial provides a step by step approach on how to use it and integrate it in your PHP coding activities.
Codeception is a Behavior Driven Development (BDD) testing PHP framework. It aims to provide an original way to write acceptance, functional and unit tests. It uses a scenario approach where you declare what you are doing and what results you expect from your tests. The first post introduces the tool and explains how to write tests with Codeception. A second post digs deeper into the code and shows you how Codeception could be used for unit testing.
This article proposes strategies to refactor problematic PHP code, making it easier to test it with unit testing tools, while reducing dependencies that improves your code base.