-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from laminas/2.15.x-merge-up-into-2.16.x_hDM0…
…Y8HZ Merge release 2.15.1 into 2.16.x
- Loading branch information
Showing
6 changed files
with
164 additions
and
7 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
if (isset($_GET['sleep'])) { | ||
sleep((int) $_GET['sleep']); | ||
} | ||
|
||
header('HTTP/1.1 200 OK'); |