-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
33 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,13 +21,42 @@ public function testDispatchOneMail(): void | |
$stream = StreamClientMock::createFromGenerator($this->mailMe(quit: true)); | ||
|
||
$this->runInFiber(static function () use ($stream): void { | ||
$cnt = 0; | ||
foreach ((new Smtp())->dispatch($stream) as $frame) { | ||
self::assertInstanceOf(SmtpFrame::class, $frame); | ||
self::assertSame('Test email', $frame->message->getSubject()); | ||
return; | ||
++$cnt; | ||
} | ||
|
||
self::fail('No frame was yielded.'); | ||
self::assertSame(1, $cnt, 'Only one frame should be yielded.'); | ||
}); | ||
} | ||
|
||
public function testDispatchOneMailWithRset(): void | ||
{ | ||
$stream = StreamClientMock::createFromGenerator((function (\Generator ...$generators) { | ||
yield "EHLO\r\n"; | ||
yield "MAIL FROM: <[email protected]>\r\n"; | ||
yield "RCPT TO: <[email protected]>\r\n"; | ||
yield "RCPT TO: <[email protected]>\r\n"; | ||
yield "RSET\r\n"; | ||
yield from $this->mailMe('Test email'); | ||
})()); | ||
|
||
$this->runInFiber(static function () use ($stream): void { | ||
$cnt = 0; | ||
foreach ((new Smtp())->dispatch($stream) as $frame) { | ||
self::assertInstanceOf(SmtpFrame::class, $frame); | ||
self::assertSame("Test email", $frame->message->getSubject()); | ||
self::assertSame( | ||
['[email protected]', '[email protected]'], | ||
$frame->message->getProtocol()['BCC'], | ||
'RSET should clear the buffered data.', | ||
); | ||
++$cnt; | ||
} | ||
|
||
self::assertSame(1, $cnt, 'Only one frame should be yielded.'); | ||
}); | ||
} | ||
|
||
|
@@ -64,6 +93,7 @@ private function mailMe(string $subject = 'Test email', bool $quit = false): \Ge | |
yield "MAIL FROM: <[email protected]>\r\n"; | ||
yield "RCPT TO: <[email protected]>\r\n"; | ||
yield "RCPT TO: <[email protected]>\r\n"; | ||
yield "NOOP\r\n"; | ||
yield "DATA\r\n"; | ||
yield "From: [email protected]\r\n"; | ||
yield "To: [email protected]\r\n"; | ||
|
@@ -72,6 +102,7 @@ private function mailMe(string $subject = 'Test email', bool $quit = false): \Ge | |
yield "\r\n"; | ||
yield "Hello, this is a test email.\r\n"; | ||
yield ".\r\n"; | ||
yield "NOOP\r\n"; | ||
if ($quit) { | ||
yield "QUIT\r\n"; | ||
} | ||
|