diff --git a/src/Protocol/Smtp/Request/DataRequest.php b/src/Protocol/Smtp/Request/DataRequest.php index 8c99f703..f8b2e742 100644 --- a/src/Protocol/Smtp/Request/DataRequest.php +++ b/src/Protocol/Smtp/Request/DataRequest.php @@ -31,6 +31,7 @@ public function execute(ConnectionInterface $connection): void { $bytes = ''; + $this->stream->rewind(); while (!$this->stream->eof()) { $bytes .= $this->stream->read(1000); diff --git a/test/Unit/Protocol/Smtp/Request/DataRequestTest.php b/test/Unit/Protocol/Smtp/Request/DataRequestTest.php index 8975be83..0b710f8f 100644 --- a/test/Unit/Protocol/Smtp/Request/DataRequestTest.php +++ b/test/Unit/Protocol/Smtp/Request/DataRequestTest.php @@ -124,4 +124,39 @@ public function it_does_not_add_lines() $command->execute($connection); } + /** + * @test + */ + public function it_rewinds_stream_beforehand() + { + $connection = $this->createMock(ConnectionInterface::class); + $connection + ->expects($this->at(0)) + ->method('send') + ->with("test"); + + $connection + ->expects($this->at(1)) + ->method('send') + ->with("."); + + $connection + ->expects($this->at(2)) + ->method('send') + ->with("test"); + + $connection + ->expects($this->at(3)) + ->method('send') + ->with("."); + + $stream = new StringStream('test'); + + $command1 = new DataRequest($stream); + $command1->execute($connection); + + $command2 = new DataRequest($stream); + $command2->execute($connection); + } + } \ No newline at end of file