Test mock

Keyboard Shortcuts

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.…

Resume Transcript Auto-Scroll

Author

Released

11/3/2016

Develop better software with less bugs, and save more time for developing new features, with test-driven development. This course takes developers from writing their first unit test in PHPUnit to improving code coverage in their applications. Justin Yost covers writing test doubles to deal with dependencies in software, writing exception-based tests, and rapidly adding test cases to the core suite of unit tests. Developers will come away with a basic understanding of the test-driven development (TDD) cycle and understand how to use unit tests to write code, as well as refactor legacy code.