Skip to content

Commit

Permalink
Merge pull request #172 from laminas/2.15.x-merge-up-into-2.16.x_hDM0…
Browse files Browse the repository at this point in the history
…Y8HZ

Merge release 2.15.1 into 2.16.x
  • Loading branch information
Slamdunk authored Sep 23, 2021
2 parents d219bfd + 70c3476 commit b9c896e
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 7 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"laminas/laminas-servicemanager": "^3.7",
"phpunit/phpunit": "^9.5.5",
"psalm/plugin-phpunit": "^0.15.1",
"symfony/process": "^5.3.7",
"vimeo/psalm": "^4.7"
},
"suggest": {
Expand Down
74 changes: 68 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2751,6 +2751,12 @@
<code>$sender</code>
</UnusedVariable>
</file>
<file src="test/Protocol/AbstractProtocolTest.php">
<PropertyNotSetInConstructor occurrences="2"/>
<UnusedClosureParam occurrences="1">
<code>$type</code>
</UnusedClosureParam>
</file>
<file src="test/Protocol/ProtocolTraitTest.php">
<InvalidScalarArgument occurrences="1">
<code>ProtocolTrait::class</code>
Expand Down
2 changes: 1 addition & 1 deletion src/Protocol/AbstractProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ protected function _receive($timeout = null)
// Check meta data to ensure connection is still valid
$info = stream_get_meta_data($this->socket);

if (! $info['timed_out']) {
if ($info['timed_out']) {
throw new Exception\RuntimeException($this->host . ' has timed out');
}

Expand Down
81 changes: 81 additions & 0 deletions test/Protocol/AbstractProtocolTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

/**
* @see https://github.com/laminas/laminas-mail for the canonical source repository
* @copyright https://github.com/laminas/laminas-mail/blob/master/COPYRIGHT.md
* @license https://github.com/laminas/laminas-mail/blob/master/LICENSE.md New BSD License
*/

namespace LaminasTest\Mail\Protocol;

use Laminas\Mail\Headers;
use Laminas\Mail\Message;
use Laminas\Mail\Protocol\AbstractProtocol;
use Laminas\Mail\Protocol\Exception;
use Laminas\Mail\Protocol\ProtocolTrait;
use Laminas\Mail\Transport\Smtp;
use LaminasTest\Mail\TestAsset\SmtpProtocolSpy;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;

/**
* @group Laminas_Mail
* @covers Laminas\Mail\Protocol\AbstractProtocol<extended>
*/
final class AbstractProtocolTest extends TestCase
{
/** @var Process */
private $process;

protected function setUp(): void
{
$this->process = new Process([
PHP_BINARY,
'-S',
'127.0.0.1:8080',
'-t',
__DIR__ . '/HttpStatusService',
]);
$this->process->start();
$this->process->waitUntil(static function (string $type, string $output): bool {
return false !== strpos($output, 'started');
});
}

protected function tearDown(): void
{
$this->process->stop();
}

/**
* @requires PHP >= 7.4
*/
public function testExceptionShouldBeRaisedWhenConnectionHasTimedOut(): void
{
$protocol = new class('127.0.0.1', 8080) extends AbstractProtocol {
use ProtocolTrait;

public function connect(): void
{
$this->_disconnect();
$this->socket = $this->setupSocket('tcp', $this->host, $this->port, 2);
}

public function send(string $path, ?int $readTimeout): string
{
$this->_send('GET ' . $path . ' HTTP/1.1');
$this->_send('Host: ' . $this->host);
$this->_send('');

return $this->_receive($readTimeout);
}
};

$protocol->connect();
self::assertSame('HTTP/1.1 200 OK' . AbstractProtocol::EOL, $protocol->send('/', null));

$protocol->connect();
$this->expectExceptionObject(new \Laminas\Mail\Protocol\Exception\RuntimeException('127.0.0.1 has timed out'));
$protocol->send('/?sleep=3', 1);
}
}
7 changes: 7 additions & 0 deletions test/Protocol/HttpStatusService/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

if (isset($_GET['sleep'])) {
sleep((int) $_GET['sleep']);
}

header('HTTP/1.1 200 OK');

0 comments on commit b9c896e

Please sign in to comment.