Advanced Test Stubs will teach of the ways in which you can use your test doubles to test the exact use of your external dependencies for more complete testing of your architecture of your top level objects as well as your dependencies.
- [Instructor] Recall our key differences…between a plain stub and a mock object.…The differences are mock has expectations…about what stub methods are called…and the inputs to that stub.…We're going to modify our stub that we created…in the last video to add in these mock capabilities.…Open receipt test class which is located…in the test directory.…Let's first modify our test for the post tax total method…to use a predefined value for the items, tax, and coupon.…
We'll scroll down to our test on line 37…and we'll add in items is equal to an array…with the values 1, 2, 5, and 8.…We'll next add a tax amount which will be equal to 0.20.…After this, we'll add a coupon value on line 40…that will be equal to null.…We can now modify our stub to set up expectations…for both the number of times we will call our mark methods…as well as what inputs to expect.…
On line 44, we add before our method call,…we add arrow expects this once.…So line 44 will look like receipt arrow expects,…which is a method call and then this arrow once.…
- 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