-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a41654b
commit 8f7fe30
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |