Welcome to PHPUnit!PHPUnit is a programmer-oriented testing framework for PHP. Show Take the first steps Let me help you Get the eBook Copyright © Sebastian Bergmann. IntroLet's have a shamefully simple class like this:
Back in the days, there were three options for how to test the exception. From PHPunit 9.0 onwards, only two remain. expectedException annotation was deprecated and removed. Now we can concentrate on existing solutions. Try CatchFirst one is a try-catch pair. I've seen Adam Wathan used it and advocate for it in his TDD course. Some devs consider this to be a big old fashioned. However, it has one advantage. Inside catch block, you can run additional assertion related to exception or even some other parts of the code, e.g. user wasn't updated.
ExpectationsThis approach is the PHPunit's recommended one. You can use four different methods
ConclusionThey are both excellent strategies to test PHP exceptions. Personally, I use the second one by default. I would use the first one only if additional assertions are needed.
PHPUnit for VSCodeThis extension aims to need zero config and to be highly configurable. If you have Features
Manual setup
Remote configsFor Manual ssh
Manual docker container
Manual docker image
Manual docker-compose service
ExamplesRun with (
Keybinding example: |