Problem/Motivation
Using @expectedException is not considered good testing practice because you cannot specify where exactly in the test method the exception should be triggered. Background info: https://thephp.cc/news/2016/02/questioning-phpunit-best-practices
Proposed resolution
We should use the method setExpectedException() instead right before the line that triggers the exception (usually right before the last line).
Remaining tasks
Review patch.