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
|
<?php
namespace PhpAmqpLib\Tests\Unit\Connection;
use PhpAmqpLib\Tests\TestCaseCompat;
use PHPUnit\Framework\Attributes\Test;
/**
* Test the library properties
*/
class LibraryPropertiesTest extends TestCaseCompat
{
/**
* Client properties.
*
* https://www.rabbitmq.com/amqp-0-9-1-reference.html#connection.start-ok.client-properties
* The properties SHOULD contain at least these fields:
* "product", giving the name of the client product,
* "version", giving the name of the client version,
* "platform", giving the name of the operating system,
* "copyright", if appropriate, and
* "information", giving other general information.
*/
#[Test]
public function requiredProperties()
{
$connection = $this->getMockBuilder('\PhpAmqpLib\Connection\AMQPStreamConnection')
->onlyMethods([])
->disableOriginalConstructor()
->getMock();
$properties = $connection->getLibraryProperties();
// Assert that the library properties method returns an array
$this->assertIsArray($properties);
// Ensure that the required properties exist in the array
$this->assertArrayHasKey('product', $properties);
$this->assertArrayHasKey('version', $properties);
$this->assertArrayHasKey('platform', $properties);
$this->assertArrayHasKey('copyright', $properties);
$this->assertArrayHasKey('information', $properties);
}
/**
* AMQPWriter::table_write expects values given with data types and values
* ensure each property is an array with the first value being a data type
*/
#[Test]
public function propertyTypes()
{
$connection = $this->getMockBuilder('\PhpAmqpLib\Connection\AMQPStreamConnection')
->onlyMethods([])
->disableOriginalConstructor()
->getMock();
$properties = $connection->getLibraryProperties();
// Assert that the library properties method returns an array
$this->assertIsArray($properties);
// Iterate array checking each value is suitable
foreach ($properties as $property) {
// Property should be an array with exactly 2 properties
$this->assertIsArray($property);
$this->assertCount(2, $property);
// Retreive the datatype and ensure it matches our signature
$dataType = $property[0];
$this->assertIsString($dataType);
$this->assertStringMatchesFormat('%c', $dataType);
}
}
}
|