From 8f7fe30e39b3235f6f4792ae5605da2f66c25cbd Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Mon, 1 Mar 2021 15:07:27 +0800 Subject: [PATCH] Add Message test --- tests/Unit/MessageTest.php | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/Unit/MessageTest.php diff --git a/tests/Unit/MessageTest.php b/tests/Unit/MessageTest.php new file mode 100644 index 0000000..b8c1c1a --- /dev/null +++ b/tests/Unit/MessageTest.php @@ -0,0 +1,57 @@ + + * + * For the full copyright and license information, + * please view the LICENSE file that was distributed with this source code + */ + +declare(strict_types=1); + +namespace SimpsTest\MQTT\Unit; + +use PHPUnit\Framework\TestCase; +use Simps\MQTT\Message; +use Simps\MQTT\Protocol\ProtocolInterface; +use Simps\MQTT\Protocol\Types; + +/** + * @internal + * @coversNothing + */ +class MessageTest extends TestCase +{ + public function testPublishMessage() + { + $message = new Message\Publish(); + $message->setProtocolLevel(ProtocolInterface::MQTT_PROTOCOL_LEVEL_5_0) + ->setTopic('simps/mqtt/message') + ->setQos(ProtocolInterface::MQTT_QOS_1) + ->setDup(1) + ->setRetain(0) + ->setMessage('this is content') + ->setMessageId(1) + ->setProperties(['message_expiry_interval' => 100]); + $this->assertEquals( + $message->getContents(), + (string) $message, + 'The results of getContents and toString should be the same' + ); + $this->assertIsArray($message->getContents(true)); + } + + public function testPingRespMessage() + { + $message = new Message\PingResp(); + $this->assertEquals( + $message->getContents(), + (string) $message, + 'The results of getContents and toString should be the same' + ); + $this->assertIsArray($message->getContents(true)); + $this->assertEquals($message->getContents(true)['type'], Types::PINGRESP); + } +}