This repository has been archived by the owner on Aug 9, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for MQTT and FCM services
Signed-off-by: Domingo Oropeza <[email protected]>
- Loading branch information
Showing
5 changed files
with
292 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/** | ||
* LICENSE | ||
* | ||
* Copyright © 2016-2018 Teclib' | ||
* Copyright © 2010-2018 by the FusionInventory Development Team. | ||
* | ||
* This file is part of Flyve MDM Plugin for GLPI. | ||
* | ||
* Flyve MDM Plugin for GLPI is a subproject of Flyve MDM. Flyve MDM is a mobile | ||
* device management software. | ||
* | ||
* Flyve MDM Plugin for GLPI is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* Flyve MDM Plugin for GLPI is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Flyve MDM Plugin for GLPI. If not, see http://www.gnu.org/licenses/. | ||
* ------------------------------------------------------------------------------ | ||
* @author Thierry Bugier | ||
* @copyright Copyright © 2018 Teclib | ||
* @license AGPLv3+ http://www.gnu.org/licenses/agpl.txt | ||
* @link https://github.com/flyve-mdm/glpi-plugin | ||
* @link https://flyve-mdm.com/ | ||
* ------------------------------------------------------------------------------ | ||
*/ | ||
|
||
namespace tests\units\GlpiPlugin\Flyvemdm\Fcm; | ||
|
||
|
||
use Flyvemdm\Tests\CommonTestCase; | ||
|
||
class FcmEnvelope extends CommonTestCase { | ||
|
||
private $scope = [['type' => 'fcm', 'token' => 'Sup3rT0k3n']]; | ||
private $topic = ['lorem/ipsum/dolor']; | ||
|
||
protected function providerContext() { | ||
return [ | ||
'empty' => [ | ||
'context' => [[]], | ||
'expected' => 'The scope argument is needed (push type and token)', | ||
], | ||
'invalid scope' => [ | ||
'context' => ['lorem' => ['key' => '']], | ||
'expected' => 'The scope argument is needed (push type and token)', | ||
], | ||
'invalid type' => [ | ||
'context' => ['scope' => [['key' => '']]], | ||
'expected' => 'The scope argument is needed (push type and token)', | ||
], | ||
'invalid token' => [ | ||
'context' => ['scope' => [['type' => 'fcm']]], | ||
'expected' => 'The scope argument is needed (push type and token)', | ||
], | ||
'invalid topic' => [ | ||
'context' => ['scope' => $this->scope], | ||
'expected' => 'A topic argument is needed', | ||
], | ||
]; | ||
} | ||
/** | ||
* @tags testException | ||
* @dataProvider providerContext | ||
* @param array $context | ||
* @param string $expected | ||
*/ | ||
public function testException($context, $expected) { | ||
$this->exception(function () use ($context) { | ||
$this->newTestedInstance($context); | ||
})->hasMessage($expected); | ||
} | ||
|
||
/** | ||
* @tags testEnvelope | ||
*/ | ||
public function testEnvelope() { | ||
$instance = $this->newTestedInstance(['scope' => $this->scope, 'topic' => $this->topic]); | ||
$this->array($instance->getContext('scope'))->child[0](function ($child) { | ||
$scope = $this->scope[0]; | ||
$child->hasKeys(['type', 'token'])->values | ||
->string[0]->isEqualTo($scope['type']) | ||
->string[1]->isEqualTo($scope['token']); | ||
}); | ||
$context = $instance->getContext('topic'); | ||
$this->string($context[0])->isEqualTo('lorem-ipsum-dolor'); | ||
} | ||
|
||
} |
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,66 @@ | ||
<?php | ||
/** | ||
* LICENSE | ||
* | ||
* Copyright © 2016-2018 Teclib' | ||
* Copyright © 2010-2018 by the FusionInventory Development Team. | ||
* | ||
* This file is part of Flyve MDM Plugin for GLPI. | ||
* | ||
* Flyve MDM Plugin for GLPI is a subproject of Flyve MDM. Flyve MDM is a mobile | ||
* device management software. | ||
* | ||
* Flyve MDM Plugin for GLPI is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* Flyve MDM Plugin for GLPI is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Flyve MDM Plugin for GLPI. If not, see http://www.gnu.org/licenses/. | ||
* ------------------------------------------------------------------------------ | ||
* @author Thierry Bugier | ||
* @copyright Copyright © 2018 Teclib | ||
* @license AGPLv3+ http://www.gnu.org/licenses/agpl.txt | ||
* @link https://github.com/flyve-mdm/glpi-plugin | ||
* @link https://flyve-mdm.com/ | ||
* ------------------------------------------------------------------------------ | ||
*/ | ||
|
||
namespace tests\units\GlpiPlugin\Flyvemdm\Fcm; | ||
|
||
|
||
use Flyvemdm\Tests\CommonTestCase; | ||
use GlpiPlugin\Flyvemdm\Broker\BrokerMessage; | ||
use GlpiPlugin\Flyvemdm\Fcm\FcmEnvelope; | ||
use GlpiPlugin\Flyvemdm\Fcm\FcmSendMessageHandler as SendMessageHandler; | ||
use Sly\NotificationPusher\Adapter\Gcm; | ||
use Sly\NotificationPusher\PushManager; | ||
|
||
class FcmSendMessageHandler extends CommonTestCase { | ||
|
||
/** | ||
* @tags testSendMessageHandler | ||
*/ | ||
public function testSendMessageHandler() { | ||
$pushManager = new PushManager(); | ||
$adapter = new Gcm(['apiKey' => 'ServerApikey']); | ||
$toolbox = new \Toolbox(); | ||
|
||
$message = 'Hello world'; | ||
$topic = 'lorem/ipsum/dolor'; | ||
$scope = [['type' => 'fcm', 'token' => 'Sup3rT0k3n']]; | ||
$envelope = new FcmEnvelope(['scope' => $scope, 'topic' => $topic]); | ||
$brokerMessage = new BrokerMessage($message); | ||
$mockedConnection = $this->newMockInstance('\GlpiPlugin\Flyvemdm\Fcm\FcmConnection', null, | ||
null, [$pushManager, $adapter, $toolbox]); | ||
$mockedConnection->getMockController()->push = function () {}; | ||
$instance = new SendMessageHandler($envelope, $mockedConnection); | ||
$this->object($instance)->isCallable(); | ||
$instance($brokerMessage); | ||
$this->mock($mockedConnection)->call('push')->once(); | ||
} | ||
|
||
} |
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,64 @@ | ||
<?php | ||
/** | ||
* LICENSE | ||
* | ||
* Copyright © 2016-2018 Teclib' | ||
* Copyright © 2010-2018 by the FusionInventory Development Team. | ||
* | ||
* This file is part of Flyve MDM Plugin for GLPI. | ||
* | ||
* Flyve MDM Plugin for GLPI is a subproject of Flyve MDM. Flyve MDM is a mobile | ||
* device management software. | ||
* | ||
* Flyve MDM Plugin for GLPI is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* Flyve MDM Plugin for GLPI is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Flyve MDM Plugin for GLPI. If not, see http://www.gnu.org/licenses/. | ||
* ------------------------------------------------------------------------------ | ||
* @author Domingo Oropeza <[email protected]> | ||
* @copyright Copyright © 2018 Teclib | ||
* @license AGPLv3+ http://www.gnu.org/licenses/agpl.txt | ||
* @link https://github.com/flyve-mdm/glpi-plugin | ||
* @link https://flyve-mdm.com/ | ||
* ------------------------------------------------------------------------------ | ||
*/ | ||
|
||
namespace tests\units\GlpiPlugin\Flyvemdm\Mqtt; | ||
|
||
|
||
use Flyvemdm\Tests\CommonTestCase; | ||
|
||
class MqttEnvelope extends CommonTestCase { | ||
|
||
/** | ||
* @tags testEnvelope | ||
*/ | ||
public function testEnvelope() { | ||
// try the exception | ||
$this->exception(function () { | ||
$this->newTestedInstance([]); | ||
})->hasMessage('A topic argument is needed'); | ||
|
||
$topic = 'lorem'; | ||
$qos = 2; | ||
$retain = 1; | ||
|
||
// Defaut values | ||
$instance = $this->newTestedInstance(['topic' => $topic]); | ||
$this->string($instance->getContext('topic'))->isEqualTo($topic); | ||
$this->integer($instance->getContext('qos'))->isEqualTo(0); | ||
$this->integer($instance->getContext('retain'))->isEqualTo(0); | ||
|
||
// set context values | ||
$instance = $this->newTestedInstance(['topic' => $topic, 'qos' => $qos, 'retain' => $retain]); | ||
$this->integer($instance->getContext('qos'))->isEqualTo($qos); | ||
$this->integer($instance->getContext('retain'))->isEqualTo($retain); | ||
} | ||
|
||
} |
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,59 @@ | ||
<?php | ||
/** | ||
* LICENSE | ||
* | ||
* Copyright © 2016-2018 Teclib' | ||
* Copyright © 2010-2018 by the FusionInventory Development Team. | ||
* | ||
* This file is part of Flyve MDM Plugin for GLPI. | ||
* | ||
* Flyve MDM Plugin for GLPI is a subproject of Flyve MDM. Flyve MDM is a mobile | ||
* device management software. | ||
* | ||
* Flyve MDM Plugin for GLPI is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* Flyve MDM Plugin for GLPI is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Flyve MDM Plugin for GLPI. If not, see http://www.gnu.org/licenses/. | ||
* ------------------------------------------------------------------------------ | ||
* @author Thierry Bugier | ||
* @copyright Copyright © 2018 Teclib | ||
* @license AGPLv3+ http://www.gnu.org/licenses/agpl.txt | ||
* @link https://github.com/flyve-mdm/glpi-plugin | ||
* @link https://flyve-mdm.com/ | ||
* ------------------------------------------------------------------------------ | ||
*/ | ||
|
||
namespace tests\units\GlpiPlugin\Flyvemdm\Mqtt; | ||
|
||
|
||
use Flyvemdm\Tests\CommonTestCase; | ||
use GlpiPlugin\Flyvemdm\Broker\BrokerMessage; | ||
use GlpiPlugin\Flyvemdm\Mqtt\MqttEnvelope; | ||
use GlpiPlugin\Flyvemdm\Mqtt\MqttSendMessageHandler as SendMessageHandler; | ||
|
||
class MqttSendMessageHandler extends CommonTestCase { | ||
|
||
/** | ||
* @tags testSendMessageHandler | ||
*/ | ||
public function testSendMessageHandler() { | ||
$topic = 'lorem'; | ||
$message = 'Hello world'; | ||
$envelope = new MqttEnvelope(['topic' => $topic]); | ||
$brokerMessage = new BrokerMessage($message); | ||
$mockedConnection = $this->newMockInstance('\GlpiPlugin\Flyvemdm\Mqtt\MqttConnection'); | ||
$mockedConnection->getMockController()->publish = function () {}; | ||
$instance = new SendMessageHandler($mockedConnection, $envelope); | ||
$this->object($instance)->isCallable(); | ||
$instance($brokerMessage); | ||
$this->mock($mockedConnection)->call('publish') | ||
->withIdenticalArguments($topic, $message, 0, 0)->once(); | ||
} | ||
|
||
} |