Use TDD to refactor existing code into a more stable, less bug free and easier to understand solution. Gain insights into one of the many strengths of TDD, the ease at which refactors can occur.
- [Instructor] One of the strengths of TDD…is the ability to more easily refactor your existing code…to support new features…or to simply clean up,…making the code easier to read and to understand.…Let's open up the Receipt class…and look for a place to refactor our code.…Our Receipt class is found in our source directory.…As simple example is we might need to…rename our methods for Total.…Total no longer is an accurate name for the method…since it returns a total pretax.…
So as a simple refactor we'll change the name of the method…to instead be Subtotal.…To do so, we need to first open up our…test class for Receipt.…Keep in mind, our TDD pattern…is we modify the test first…and then we modify the code.…So we'll open up our test class…at ReceiptTest.php in the tests directory.…First we need to relabel our test methods…to be test subtotal.…So that will be on lines 20,…on line 37,…on line 48.…
We also need to update the total calls…for our data provider.…So we'll update that on provideTotal on line 30…to be provideSubtotal.…
- 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.