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.
- View Offline
- [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