Setting up a sample application

Before we start writing some PHPUnit test scripts, let's go ahead and create a very simple application consisting of merely a few files. This will allow us to focus on the essence of writing a test later on.

Test driven development (TDD), such as the one done with PHPUnit, encourages writing tests before the implementations. This way, the tests set the expectations for the functionality and not the other way around. This approach requires a certain level of experience and discipline, which might not sit well with newcomers to PHPUnit.

Let's assume that we are making a part of the web shopping functionality, thus dealing with product and category entities for a start. The first class we address is the Product ...

Get Mastering PHP 7 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.