Build a test stub to both fake the API of another object that our class depends on, as well as providing a mocked results from our test stub to have our faked object do work.
- [Instructor] Now, we'll build the next feature…in our Receipt library,…which will take the amount from our total call…and the amount from our tax call and sum them together…and return the final total for our receipt.…Now, we'll build the next feature in your Receipt library,…which will take the amount from our total call…and the amount from our tax call and sum them together…and return the final amount for our receipt.…To do this, we'll add a method, postTaxTotal,…that calculates the total for a collection of items…and the tax total, and then sums those two values together.…
First, open the ReceiptTest.php class…in our tests directory.…Next, add a function call,…public function TestPostTaxTotal, on line 37.…Our test here will build a mock instance…of the Receipt class…so we can replace the instance we are using…and instead call it,…and then return the sum from the two calls…to the other methods,…so we're testing this in isolation.…Let's build this out and it'll start to make more sense.…
Building a mock PHPUnit is fairly easy.…
- 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
Skill Level Intermediate
PHP: Managing Persistent Sessionswith David Powers2h 41m Intermediate
1. The Basics of Test-Driven Development
2. Advanced Test-Driven Development
3. Test-Driven Development Tactics
4. PHPUnit Advanced Tactics
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.