0

I've already test this method before, but only the try block, I don't know so about PHP Exceptions, My goal is to do a test unit inside catch block body and all its logic.

public function send(User $user, Notification $notif, Request $request)
{
    $client = ElephantIO\Client();
    try {

        $client->initialize();
        $client->emit('notification', array(/*...*/));          
        $client->close();

    } catch (ServerConnectionFailureException $e) {
        //TODO:
    }
}
jjoselon
  • 2,641
  • 4
  • 23
  • 37
  • 1
    Possible duplicate of [PHPUnit assert that an exception was thrown?](https://stackoverflow.com/questions/5683592/phpunit-assert-that-an-exception-was-thrown) – Mehmet SÖĞÜNMEZ Oct 10 '17 at 14:32
  • 2
    You would need to use a mock for the `ElephantIO\Client` object, and cause it to throw an exception for any of the initialize/emit/close methods. Since you're not passing it in as a dependency, that's going to be harder to do. Do you have the option of refactoring the code? – iainn Oct 10 '17 at 14:50

0 Answers0