16.
Setup and Tearing It Down
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
6 Comments
I really enjoyed this course, many thanks. I found a lot of interesting practices that I will definitely use in the future. Looking forward to the next parts.
I have only one question (just kidding): why can dino length be zero or negative? They deserve to have an assert for that! =)
Howdy!
I'm glad that you not only enjoyed the new series, but it was also helpful to you! That's music to our ears...
This is actually a very good question! If PHP had native support for
unsigned integerswe could prevent a dino's length being "-100" or something silly like that. But, in all honesty, this isn't a use case I'd be too worried about. There's a balance between writing tests for every possible scenario, keeping your tests maintainable, and being practical. If the dino's size was used to determine if they could be let loose in the petting zoo, we'd probably would have a test to keep Big Eaty out of there... :)Thank you for the feedback. We appreciate it!
I agree about balance, but let me argue a little =) Since Dinosaur entity have only one place to change length (the constructor), then we can add a condition there, which would check length and otherwise throws an exception. Obviously, dino length can't be negative or zero on instantiation. Then in
\App\Tests\Unit\Entity\DinosuarTest::testDinosaurHasCorrectSizeDescriptionFromLengthwe can expect that exception, when data provider yields 0 or negative number. In that case, we can be sure, that each dino has a valid size. But, also it requires several changes in tests (instantiation with length or set non-negative default size), since right now default size is 0.That is definitely one way to do it, and probably how I would tackle it if it were a big enough concern of mine. But, again it's all about prioritizing area of concerns. If the app is only instantiating
Dinosaur's without using unsafe input, say from a form, then ya - I'm not going to bother... But, if we did something like that in episode 3, who knows what might happen...Great and good to follow tutorial ... i hope bob is happy.
Cant wait for part II
Awesome! I'm glad you enjoyed it. Episode 2 is in the works now and we can't wait to release it. Stay Tuned...
"Houston: no signs of life"
Start the conversation!