Skip to content

Commit

Permalink
rewind message stream before sending data request over smtp
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikbosch committed Nov 7, 2017
1 parent a3b02eb commit 05dea08
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Protocol/Smtp/Request/DataRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function execute(ConnectionInterface $connection): void
{
$bytes = '';

$this->stream->rewind();
while (!$this->stream->eof()) {
$bytes .= $this->stream->read(1000);

Expand Down
35 changes: 35 additions & 0 deletions test/Unit/Protocol/Smtp/Request/DataRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 05dea08

Please sign in to comment.