I want to test a method that can take, as a parameter, either an instance of class Foo
or a string. If anything else is passed it throws an Exception
.
How do I test that if I don't pass one of the valid types the exception is thrown? How can I make sure that anything other than one of those types will yield an exception?
$this->expectException(WhateverTheException::class)
and call your method with the wrong parameter type. Check out phpunit.readthedocs.io/en/8.0/…