Skip to content

Commit

Permalink
Add Message test
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records committed Mar 1, 2021
1 parent a41654b commit 8f7fe30
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/Unit/MessageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* This file is part of Simps
*
* @link https://github.com/simps/mqtt
* @contact Lu Fei <[email protected]>
*
* 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);
}
}

0 comments on commit 8f7fe30

Please sign in to comment.