Skip to content

Commit

Permalink
Update Mailer::setLastResponse method
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Feb 8, 2024
1 parent 7638a97 commit 0d7c94f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ public function getConfigs() : array

protected function setLastResponse(?string $lastResponse) : static
{
$this->lastResponse = $lastResponse;
if ($lastResponse === null) {
$this->lastResponse = null;
return $this;
}
$parts = \explode(\PHP_EOL, $lastResponse);
$this->lastResponse = $parts[\array_key_last($parts)];
return $this;
}

Expand Down
17 changes: 17 additions & 0 deletions tests/MailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ public function testKeepAlive() : void
self::assertTrue($smtp->send($this->getMessage()));
}

public function testLastResponse() : void
{
$mailer = new class([]) extends Mailer {
public function setLastResponse(?string $lastResponse) : static
{
return parent::setLastResponse($lastResponse);
}
};
self::assertNull($mailer->getLastResponse());
$mailer->setLastResponse('250 foo');
self::assertSame('250 foo', $mailer->getLastResponse());
$mailer->setLastResponse('250 foo' . \PHP_EOL . '250 bar');
self::assertSame('250 bar', $mailer->getLastResponse());
$mailer->setLastResponse(null);
self::assertNull($mailer->getLastResponse());
}

public function testFailToAuthenticateUsernameNotSet() : void
{
\sleep(5);
Expand Down

0 comments on commit 0d7c94f

Please sign in to comment.