Skip to content

Commit 70c3476

Browse files
authored
Merge pull request #171 from laminas/2.14.x-merge-up-into-2.15.x_Ik50M5d2
Merge release 2.14.3 into 2.15.x
2 parents d219bfd + 2b7a0a2 commit 70c3476

File tree

6 files changed

+164
-7
lines changed

6 files changed

+164
-7
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"laminas/laminas-servicemanager": "^3.7",
2929
"phpunit/phpunit": "^9.5.5",
3030
"psalm/plugin-phpunit": "^0.15.1",
31+
"symfony/process": "^5.3.7",
3132
"vimeo/psalm": "^4.7"
3233
},
3334
"suggest": {

composer.lock

Lines changed: 68 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

psalm-baseline.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,6 +2751,12 @@
27512751
<code>$sender</code>
27522752
</UnusedVariable>
27532753
</file>
2754+
<file src="test/Protocol/AbstractProtocolTest.php">
2755+
<PropertyNotSetInConstructor occurrences="2"/>
2756+
<UnusedClosureParam occurrences="1">
2757+
<code>$type</code>
2758+
</UnusedClosureParam>
2759+
</file>
27542760
<file src="test/Protocol/ProtocolTraitTest.php">
27552761
<InvalidScalarArgument occurrences="1">
27562762
<code>ProtocolTrait::class</code>

src/Protocol/AbstractProtocol.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ protected function _receive($timeout = null)
290290
// Check meta data to ensure connection is still valid
291291
$info = stream_get_meta_data($this->socket);
292292

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

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
/**
4+
* @see https://github.com/laminas/laminas-mail for the canonical source repository
5+
* @copyright https://github.com/laminas/laminas-mail/blob/master/COPYRIGHT.md
6+
* @license https://github.com/laminas/laminas-mail/blob/master/LICENSE.md New BSD License
7+
*/
8+
9+
namespace LaminasTest\Mail\Protocol;
10+
11+
use Laminas\Mail\Headers;
12+
use Laminas\Mail\Message;
13+
use Laminas\Mail\Protocol\AbstractProtocol;
14+
use Laminas\Mail\Protocol\Exception;
15+
use Laminas\Mail\Protocol\ProtocolTrait;
16+
use Laminas\Mail\Transport\Smtp;
17+
use LaminasTest\Mail\TestAsset\SmtpProtocolSpy;
18+
use PHPUnit\Framework\TestCase;
19+
use Symfony\Component\Process\Process;
20+
21+
/**
22+
* @group Laminas_Mail
23+
* @covers Laminas\Mail\Protocol\AbstractProtocol<extended>
24+
*/
25+
final class AbstractProtocolTest extends TestCase
26+
{
27+
/** @var Process */
28+
private $process;
29+
30+
protected function setUp(): void
31+
{
32+
$this->process = new Process([
33+
PHP_BINARY,
34+
'-S',
35+
'127.0.0.1:8080',
36+
'-t',
37+
__DIR__ . '/HttpStatusService',
38+
]);
39+
$this->process->start();
40+
$this->process->waitUntil(static function (string $type, string $output): bool {
41+
return false !== strpos($output, 'started');
42+
});
43+
}
44+
45+
protected function tearDown(): void
46+
{
47+
$this->process->stop();
48+
}
49+
50+
/**
51+
* @requires PHP >= 7.4
52+
*/
53+
public function testExceptionShouldBeRaisedWhenConnectionHasTimedOut(): void
54+
{
55+
$protocol = new class('127.0.0.1', 8080) extends AbstractProtocol {
56+
use ProtocolTrait;
57+
58+
public function connect(): void
59+
{
60+
$this->_disconnect();
61+
$this->socket = $this->setupSocket('tcp', $this->host, $this->port, 2);
62+
}
63+
64+
public function send(string $path, ?int $readTimeout): string
65+
{
66+
$this->_send('GET ' . $path . ' HTTP/1.1');
67+
$this->_send('Host: ' . $this->host);
68+
$this->_send('');
69+
70+
return $this->_receive($readTimeout);
71+
}
72+
};
73+
74+
$protocol->connect();
75+
self::assertSame('HTTP/1.1 200 OK' . AbstractProtocol::EOL, $protocol->send('/', null));
76+
77+
$protocol->connect();
78+
$this->expectExceptionObject(new \Laminas\Mail\Protocol\Exception\RuntimeException('127.0.0.1 has timed out'));
79+
$protocol->send('/?sleep=3', 1);
80+
}
81+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
if (isset($_GET['sleep'])) {
4+
sleep((int) $_GET['sleep']);
5+
}
6+
7+
header('HTTP/1.1 200 OK');

0 commit comments

Comments
 (0)