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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
<?php
namespace PhpAmqpLib\Tests\Functional\Connection;
use PhpAmqpLib\Connection\AbstractConnection;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Tests\Functional\AbstractConnectionTestCase;
use PhpAmqpLib\Wire\AMQPBufferReader;
use PhpAmqpLib\Wire\AMQPWriter;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\TestWith;
/**
* @group connection
*/
class ConnectionCreationTest extends AbstractConnectionTestCase
{
public static function hostDataProvider(): array
{
return array(
'plain' => array(
array(
array('host' => HOST, 'port' => PORT, 'user' => USER, 'password' => PASS),
array('host' => HOST, 'port' => PORT, 'user' => USER, 'password' => PASS)
)
),
'keys' => array(
array(
'host1' => array('host' => HOST, 'port' => PORT, 'user' => USER, 'password' => PASS),
'host2' => array('host' => HOST, 'port' => PORT, 'user' => USER, 'password' => PASS)
)
)
);
}
/**
* @covers \PhpAmqpLib\Connection\AbstractConnection::create_connection()
*/
#[DataProvider('hostDataProvider')]
#[Test]
public function create_connection(array $hosts)
{
$conn = AMQPStreamConnection::create_connection($hosts);
$this->assertInstanceOf(AMQPStreamConnection::class, $conn);
}
/**
* @covers \PhpAmqpLib\Connection\AbstractConnection::__construct()
* @covers \PhpAmqpLib\Connection\AbstractConnection::connection_tune()
*/
#[Test]
#[TestWith([0, 0, 0])]
#[TestWith([0, 10, 0])]
#[TestWith([10, 0, 10])]
#[TestWith([10, 20, 10])]
#[TestWith([20, 10, 10])]
public function heartbeat_negotiation(int $client, int $broker, int $expected)
{
$class = new \ReflectionClass(AbstractConnection::class);
$method = $class->getMethod('connection_tune');
$method->setAccessible(true);
$writer = new AMQPWriter();
$writer->write_short(0);
$writer->write_long(0);
$writer->write_short($broker); // broker heartbeat
$args = new AMQPBufferReader($writer->getvalue());
$connection = $this->connection_create('stream', HOST, PORT, ['heartbeat' => $client]);
$method->invoke($connection, $args);
self::assertEquals($expected, $connection->getHeartbeat());
}
}
|