Jyxo\Mail\SenderTest::testSendErrors PHP Method

testSendErrors() public method

Tests possible sending errors.
public testSendErrors ( )
    public function testSendErrors()
    {
        $email = new Email();
        $email->setBody(new Email\Body(''));
        $sender = new Sender();
        $sender->setEmail($email);
        // Non-existent sending method
        try {
            $sender->send('dummy-mode');
            $this->fail(sprintf('Expected exception %s.', \InvalidArgumentException::class));
        } catch (\PHPUnit_Framework_AssertionFailedError $e) {
            throw $e;
        } catch (\Exception $e) {
            // Correctly thrown exception
            $this->assertInstanceOf(\InvalidArgumentException::class, $e);
        }
        // Missing sender
        try {
            $sender->send(Sender::MODE_NONE);
            $this->fail(sprintf('Expected exception %s.', \Jyxo\Mail\Sender\CreateException::class));
        } catch (\PHPUnit_Framework_AssertionFailedError $e) {
            throw $e;
        } catch (\Exception $e) {
            // Correctly thrown exception
            $this->assertInstanceOf(\Jyxo\Mail\Sender\CreateException::class, $e);
        }
        $email->setFrom(new Email\Address('[email protected]'));
        // Missing recipients
        try {
            $sender->send(Sender::MODE_NONE);
            $this->fail(sprintf('Expected exception %s.', \Jyxo\Mail\Sender\CreateException::class));
        } catch (\PHPUnit_Framework_AssertionFailedError $e) {
            throw $e;
        } catch (\Exception $e) {
            // Correctly thrown exception
            $this->assertInstanceOf(\Jyxo\Mail\Sender\CreateException::class, $e);
        }
        $email->addTo(new Email\Address('[email protected]'));
        // Empty body
        try {
            $sender->send(Sender::MODE_NONE);
            $this->fail(sprintf('Expected exception %s.', \Jyxo\Mail\Sender\CreateException::class));
        } catch (\PHPUnit_Framework_AssertionFailedError $e) {
            throw $e;
        } catch (\Exception $e) {
            // Correctly thrown exception
            $this->assertInstanceOf(\Jyxo\Mail\Sender\CreateException::class, $e);
        }
    }