|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\Mailer\Envelope;
|
| 16 | +use Symfony\Component\Mailer\Exception\LogicException; |
16 | 17 | use Symfony\Component\Mailer\Exception\TransportException;
|
17 | 18 | use Symfony\Component\Mailer\Transport\Smtp\SmtpTransport;
|
18 | 19 | use Symfony\Component\Mailer\Transport\Smtp\Stream\AbstractStream;
|
@@ -133,6 +134,37 @@ public function testWriteEncodedRecipientAndSenderAddresses()
|
133 | 134 | $this->assertContains("RCPT TO:<recipient@xn--exmple-cua.org>\r\n", $stream->getCommands());
|
134 | 135 | $this->assertContains("RCPT TO:<recipient2@example.org>\r\n", $stream->getCommands());
|
135 | 136 | }
|
| 137 | + |
| 138 | + public function testAssertResponseCodeNoCodes() |
| 139 | + { |
| 140 | + $this->expectException(LogicException::class); |
| 141 | + $this->invokeAssertResponseCode('response', []); |
| 142 | + } |
| 143 | + |
| 144 | + public function testAssertResponseCodeWithEmptyResponse() |
| 145 | + { |
| 146 | + $this->expectException(TransportException::class); |
| 147 | + $this->expectExceptionMessage('Expected response code "220" but got empty code.'); |
| 148 | + $this->invokeAssertResponseCode('', [220]); |
| 149 | + } |
| 150 | + |
| 151 | + public function testAssertResponseCodeWithNotValidCode() |
| 152 | + { |
| 153 | + $this->expectException(TransportException::class); |
| 154 | + $this->expectExceptionMessage('Expected response code "220" but got code "550", with message "550 Access Denied".'); |
| 155 | + $this->expectExceptionCode(550); |
| 156 | + $this->invokeAssertResponseCode('550 Access Denied', [220]); |
| 157 | + } |
| 158 | + |
| 159 | + private function invokeAssertResponseCode(string $response, array $codes): void |
| 160 | + { |
| 161 | + |
| 162 | + $transport = new SmtpTransport($this->getMockForAbstractClass(AbstractStream::class)); |
| 163 | + $m = new \ReflectionMethod($transport, 'assertResponseCode'); |
| 164 | + $m->setAccessible(true); |
| 165 | + |
| 166 | + $m->invoke($transport, $response, $codes); |
| 167 | + } |
136 | 168 | }
|
137 | 169 |
|
138 | 170 | class DummyStream extends AbstractStream
|
|
0 commit comments