Our first unit test cover writing our first test case for an application. See how quick and easy it is to get started writing tests for any PHP application to validate and ensure your code works as you intend.
- [Instructor] We'll begin by first working…on a simple unit test to get the concept of a unit test down…before we try writing our code using the TDD process.…To begin, we'll start in our PHPUnit directory…in our computer and add first a source directory.…So, we'll create a new folder…inside of our PHPUnit directory labeled src, or source.…Inside of this source directory,…we'll add a new file, Receipt.php…We'll work on building out some code…here in our Receipt class…that will calculate totals for a receipt.…
We'll open up this file…and add first our opening PHP tags on line one.…After this, we'll add a namespace…to make some future work easier to wrangle.…In this case, we'll add the namespace of TDD…to this file on line two.…After this, we need to add a new class, Receipt,…so line three will read as class Receipt.…
After this, we can add a simple function, total.…Now, we'll take an array of items…with a default of an empty array…and return the array sum of those items.…So, line four will read as public function total.…
- Why use unit testing?
- Writing unit tests
- Extending unit tests
- Filtering PHPUnit tests
- Building dummy objects
- Working with data providers
- Writing an exception-based test
- Using TDD tactics
- Using PHPUnit advanced tactics, such as database tests