-
-
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
f06d0c9
commit c0be169
Showing
9 changed files
with
356 additions
and
5 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
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
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
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
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,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" bootstrap="tests/bootstrap.php" beStrictAboutTestsThatDoNotTestAnything="false" verbose="true"> | ||
<testsuite name="default"> | ||
<directory suffix="Test.php">tests</directory> | ||
</testsuite> | ||
<php> | ||
<ini name="error_reporting" value="-1" /> | ||
<ini name="display_errors" value="On" /> | ||
<ini name="display_startup_errors" value="On" /> | ||
</php> | ||
</phpunit> |
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,110 @@ | ||
<?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\V3; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Simps\MQTT\Client; | ||
use Simps\MQTT\Hex\ReasonCode; | ||
use Simps\MQTT\Types; | ||
|
||
/** | ||
* @internal | ||
* @coversNothing | ||
*/ | ||
class PacketTest extends TestCase | ||
{ | ||
public function testConnect() | ||
{ | ||
$config = getTestConnectConfig('broker.emqx.io'); | ||
$client = new Client($config, SWOOLE_MQTT_CONFIG); | ||
$res = $client->connect(); | ||
$this->assertIsArray($res); | ||
$this->assertSame($res['type'], Types::CONNACK); | ||
|
||
return $client; | ||
} | ||
|
||
/** | ||
* @depends testConnect | ||
*/ | ||
public function testSubscribe(Client $client) | ||
{ | ||
$topics['simpsmqtt/get'] = 1; | ||
$res = $client->subscribe($topics); | ||
$this->assertIsArray($res); | ||
$this->assertSame($res['type'], Types::SUBACK); | ||
$this->assertSame($res['codes'][0], ReasonCode::GRANTED_QOS_1); | ||
|
||
return $client; | ||
} | ||
|
||
/** | ||
* @depends testSubscribe | ||
*/ | ||
public function testPublish(Client $client) | ||
{ | ||
$buffer = $client->publish('simpsmqtt/get', 'hello,simps', 1); | ||
$this->assertIsArray($buffer); | ||
$this->assertSame($buffer['type'], Types::PUBACK); | ||
|
||
return $client; | ||
} | ||
|
||
/** | ||
* @depends testPublish | ||
*/ | ||
public function testRecv(Client $client) | ||
{ | ||
$buffer = $client->recv(); | ||
$this->assertIsArray($buffer); | ||
$this->assertSame($buffer['type'], Types::PUBLISH); | ||
$this->assertSame($buffer['topic'], 'simpsmqtt/get'); | ||
$this->assertSame($buffer['message'], 'hello,simps'); | ||
|
||
return $client; | ||
} | ||
|
||
/** | ||
* @depends testRecv | ||
*/ | ||
public function testPing(Client $client) | ||
{ | ||
$buffer = $client->ping(); | ||
$this->assertIsArray($buffer); | ||
$this->assertSame($buffer['type'], Types::PINGRESP); | ||
|
||
return $client; | ||
} | ||
|
||
/** | ||
* @depends testRecv | ||
*/ | ||
public function testUnsubscribe(Client $client) | ||
{ | ||
$status = $client->unSubscribe(['simpsmqtt/get']); | ||
$this->assertIsArray($status); | ||
$this->assertSame($status['type'], Types::UNSUBACK); | ||
|
||
return $client; | ||
} | ||
|
||
/** | ||
* @depends testUnsubscribe | ||
*/ | ||
public function testClose(Client $client) | ||
{ | ||
$status = $client->close(); | ||
$this->assertTrue($status); | ||
} | ||
} |
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,126 @@ | ||
<?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\V5; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Simps\MQTT\Client; | ||
use Simps\MQTT\Hex\ReasonCode; | ||
use Simps\MQTT\Types; | ||
|
||
/** | ||
* @internal | ||
* @coversNothing | ||
*/ | ||
class PacketTest extends TestCase | ||
{ | ||
public function testConnect() | ||
{ | ||
$config = getTestMQTT5ConnectConfig('broker.emqx.io'); | ||
$client = new Client($config, SWOOLE_MQTT_CONFIG); | ||
$res = $client->connect(); | ||
$this->assertIsArray($res); | ||
$this->assertSame($res['type'], Types::CONNACK); | ||
|
||
return $client; | ||
} | ||
|
||
/** | ||
* @depends testConnect | ||
*/ | ||
public function testSubscribe(Client $client) | ||
{ | ||
$topics['simps-mqtt/user001/get'] = [ | ||
'qos' => 1, | ||
'no_local' => true, | ||
'retain_as_published' => true, | ||
'retain_handling' => 2, | ||
]; | ||
$topics['simps-mqtt/user001/update'] = [ | ||
'qos' => 2, | ||
'no_local' => false, | ||
'retain_as_published' => true, | ||
'retain_handling' => 2, | ||
]; | ||
$topics['testtopic/#'] = [ | ||
'qos' => 0, | ||
]; | ||
$res = $client->subscribe($topics); | ||
$this->assertIsArray($res); | ||
$this->assertSame($res['type'], Types::SUBACK); | ||
$this->assertIsArray($res['codes']); | ||
$this->assertSame($res['codes'][0], ReasonCode::GRANTED_QOS_1); | ||
$this->assertSame($res['codes'][1], ReasonCode::GRANTED_QOS_2); | ||
|
||
return $client; | ||
} | ||
|
||
/** | ||
* @depends testSubscribe | ||
*/ | ||
public function testPublish(Client $client) | ||
{ | ||
$buffer = $client->publish('simps-mqtt/user001/get', 'hello,simps', 1); | ||
$this->assertIsArray($buffer); | ||
$this->assertSame($buffer['type'], Types::PUBACK); | ||
$this->assertSame(ReasonCode::getReasonPhrase($buffer['code']), 'Success'); | ||
return $client; | ||
} | ||
|
||
/** | ||
* @depends testPublish | ||
*/ | ||
public function testRecv(Client $client) | ||
{ | ||
$buffer = $client->recv(); | ||
$this->assertIsArray($buffer); | ||
$this->assertSame($buffer['type'], Types::PUBLISH); | ||
$this->assertIsString($buffer['topic']); | ||
|
||
return $client; | ||
} | ||
|
||
/** | ||
* @depends testSubscribe | ||
*/ | ||
public function testPing(Client $client) | ||
{ | ||
$buffer = $client->ping(); | ||
$this->assertIsArray($buffer); | ||
$this->assertSame($buffer['type'], Types::PINGRESP); | ||
|
||
return $client; | ||
} | ||
|
||
/** | ||
* @depends testSubscribe | ||
*/ | ||
public function testUnsubscribe(Client $client) | ||
{ | ||
$status = $client->unSubscribe(['simps-mqtt/user001/get']); | ||
$this->assertIsArray($status); | ||
$this->assertSame($status['type'], Types::UNSUBACK); | ||
$this->assertSame(ReasonCode::getReasonPhrase($status['code']), 'Success'); | ||
|
||
return $client; | ||
} | ||
|
||
/** | ||
* @depends testUnsubscribe | ||
*/ | ||
public function testClose(Client $client) | ||
{ | ||
$status = $client->close(); | ||
$this->assertTrue($status); | ||
} | ||
} |
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,14 @@ | ||
<?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); | ||
|
||
require_once dirname(__DIR__) . '/examples/bootstrap.php'; |
Oops, something went wrong.