1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
<?php
declare(strict_types=1);
namespace Pheanstalk\Tests\Integration;
use Pheanstalk\Connection;
use Pheanstalk\Exception\ConnectionException;
use Pheanstalk\PheanstalkManager;
use Pheanstalk\PheanstalkPublisher;
use Pheanstalk\PheanstalkSubscriber;
use Pheanstalk\Socket\SocketSocket;
use Pheanstalk\SocketFactory;
use Pheanstalk\Values\SocketImplementation;
use Pheanstalk\Values\Timeout;
use PHPUnit\Framework\Attributes\CoversClass;
#[CoversClass(SocketSocket::class)]
#[CoversClass(PheanstalkSubscriber::class)]
#[CoversClass(PheanstalkManager::class)]
#[CoversClass(PheanstalkPublisher::class)]
final class SocketPheanstalkTest extends PheanstalkTestBase
{
use ConstructWithConnectionObjectTests;
protected function getConnection(): Connection
{
return new Connection(new SocketFactory($this->getHost(), 11300, SocketImplementation::SOCKET, connectTimeout: new Timeout(1)));
}
public function testConnectTimeout(): void
{
// We use a non routable IP address to force a connection timeout
$start = microtime(true);
$factory = new SocketFactory("240.0.0.1", 11300, SocketImplementation::SOCKET, connectTimeout: new Timeout(1, 1));
$this->expectException(ConnectionException::class);
$this->expectExceptionMessage('Connection failed or timed out');
try {
$factory->create();
} catch (\Throwable $t) {
self::assertGreaterThanOrEqual(1, microtime(true) - $start);
throw $t;
}
}
}
|