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

SitePoint PHP Blog:
Re-Introducing PHPUnit – Getting Started with TDD in PHP
Aug 01, 2017 @ 15:16:02

The SitePoint PHP blog has posted a tutorial that re-introduces PHPUnit and TDD (Test-Driven Development) showing you how to get started with this pre-code testing process if you want to integrate it into your development.

There are a lot of PHPUnit posts on our site already (just check the tag), but it’s been a while since we’ve actually introduced people to it, and the tool has evolved significantly since then.

This article aims to re-introduce the tool in a modern way, to a modern audience, in a modern PHP environment – if you’re unfamiliar with PHPUnit or testing, this post is for you.

They assume you're already familiar with PHPUnit and have an environment already set up with PHP and PHPUnit. They start by briefly introducing Test-Driven Development and the PHPUnit for those not overly familiar with the basics. They then bootstrap a sample application using the PDS-Skeleton project. The tutorial then walks you through the setup of the testing environment, Composer configuration and the creation of your first test. With all of that in place they start in with some failing tests (remember, TDD is "test first") and then writing the code to make it pass. They add more tests and use a data provider to set up different cases and run them all through the same test. The post then looks at code coverage reports and the results showing how much of the code is covered by tests.

tagged: tutorial phpunit tdd testdrivendevelopment introduction

Link: https://www.sitepoint.com/re-introducing-phpunit-getting-started-tdd-php/


Trending Topics: