Build your first dummy object. A dummy object is an object that replicates the API of an object to enable us to fake objects that our classes depend upon without providing any functionality for this dummy object.
- [Instructor] So, let's build our first test double…using a dummy object.…Recall a dummy object is an object or value…that has no use in our method under test,…but is needed for the signature.…We'll update the total method to take a coupon value…and to apply that coupon value off of our total.…Let's open up our ReceiptTest.php file in our test directory…and let's add a second input for the coupon percentage off.…We will pass an nt or null value.…
That null value will be our dummy object.…So, first add a null coupon value…to our test total method on line 18.…We'll add coupon is equal to null,…and then we'll pass this into our test on line 19.…Now, if we run our test by going over…to out terminal application…and running the command vendor bin phpunit,…all of our tests pass.…After all php doesn't care that we…passed an extra input to our total method.…
It just ignores it anyways.…Notice that this is practically…the definition of a dummy object.…Nothing really cares about it.…Let's copy this test so we can get a failing test…
- 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
Managing PHP 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?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
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.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.