-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support custom message type in subscribe
- Loading branch information
Showing
11 changed files
with
175 additions
and
26 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,12 @@ | ||
<?php | ||
|
||
namespace PubNub\Models\Server; | ||
|
||
abstract class MessageType | ||
{ | ||
public const MESSAGE = 0; | ||
public const SIGNAL = 1; | ||
public const OBJECT = 2; | ||
public const MESSAGE_ACTION = 3; | ||
public const FILE_MESSAGE = 4; | ||
} |
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
1 change: 0 additions & 1 deletion
1
tests/Acceptance/CustomMessageType/history-custom-mssg-type.feature
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
37 changes: 37 additions & 0 deletions
37
tests/Acceptance/Subscribe/AcceptanceTestSubscribeCallback.php
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,37 @@ | ||
<?php | ||
|
||
namespace PubNubTests\Acceptance\Subscribe; | ||
|
||
use PubNub\Callbacks\SubscribeCallback; | ||
use PubNubTests\Acceptance\Subscribe\SubscribeContext; | ||
|
||
class AcceptanceTestSubscribeCallback extends SubscribeCallback | ||
{ | ||
private SubscribeContext $context; | ||
|
||
public function __construct(SubscribeContext $context) | ||
{ | ||
$this->context = $context; | ||
} | ||
|
||
/** @phpstan-ignore-next-line */ | ||
public function status($pubnub, $status) | ||
{ | ||
} | ||
|
||
/** @phpstan-ignore-next-line */ | ||
public function message($pubnub, $messageResult) | ||
{ | ||
$this->context->addMessage($messageResult); | ||
} | ||
|
||
/** @phpstan-ignore-next-line */ | ||
public function presence($pubnub, $presence) | ||
{ | ||
} | ||
|
||
/** @phpstan-ignore-next-line */ | ||
public function signal($pubnub, $signal) | ||
{ | ||
} | ||
} |
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,74 @@ | ||
<?php | ||
|
||
namespace PubNubTests\Acceptance\Subscribe; | ||
|
||
use Behat\Behat\Context\Context; | ||
use PubNub\Models\Consumer\PubSub\PNMessageResult; | ||
use PubNub\Models\Server\MessageType; | ||
use PubNubTests\Acceptance\PubNubContext; | ||
use PubNub\PubNub; | ||
use PubNub\PNConfiguration; | ||
|
||
/** | ||
* Defines application features from the specific context. | ||
*/ | ||
class SubscribeContext extends PubNubContext implements Context | ||
{ | ||
private PubNub $pubnub; | ||
private PNConfiguration $config; | ||
private string $channelName; | ||
/** @var PNMessageResult[] */ | ||
private array $messageResults = []; | ||
|
||
public function __construct() | ||
{ | ||
$this->config = new PNConfiguration(); | ||
} | ||
|
||
public function addMessage(PNMessageResult $message): void | ||
{ | ||
$this->messageResults[] = $message; | ||
} | ||
|
||
/** | ||
* @Given the demo keyset | ||
*/ | ||
public function theDemoKeyset(): void | ||
{ | ||
$this->config->setOrigin("localhost:8090") | ||
->setSecure(false) | ||
->setPublishKey('demo') | ||
->setSubscribeKey('demo') | ||
->setUserId('demo') | ||
->setSubscribeTimeout(1); | ||
$this->pubnub = new PubNub($this->config); | ||
} | ||
|
||
/** | ||
* @When I subscribe to :channelName channel | ||
*/ | ||
public function iSubscribeToChannel(string $channelName): void | ||
{ | ||
$callback = new AcceptanceTestSubscribeCallback($this); | ||
$this->pubnub->addListener($callback); | ||
$this->channelName = $channelName; | ||
$this->pubnub->subscribe()->channels($this->channelName)->execute(); | ||
} | ||
|
||
/** | ||
* @Then I receive :numberOf messages in my subscribe response | ||
*/ | ||
public function iReceiveMessagesInMySubscribeResponse(string $numberOf): void | ||
{ | ||
assert(count($this->messageResults) === (int)$numberOf); | ||
} | ||
|
||
/** | ||
* @Then response contains messages with :firstCustomType and :secondCustomType types | ||
*/ | ||
public function responseContainsMessagesWithAndTypes(string $firstCustomType, string $secondCustomType): void | ||
{ | ||
assert($this->messageResults[0]->getCustomMessageType() === $firstCustomType); | ||
assert($this->messageResults[1]->getCustomMessageType() === $secondCustomType); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/Acceptance/Subscribe/subscribe-custom-mssg-type.feature
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 @@ | ||
@featureSet=subscribeCustomMssgType @beta | ||
Feature: Subscribe for VSP | ||
As a PubNub user I want to subscribe and receive custom message type. | ||
Client should be able to receive custom message type from subscribe response without any | ||
additional options set (like `include_custom_message_type`for other API). | ||
|
||
Background: | ||
Given the demo keyset | ||
|
||
@contract=subscribeReceiveMessagesWithTypes | ||
Scenario: Client can subscribe and receive messages with types | ||
When I subscribe to 'some-channel' channel | ||
Then I receive 2 messages in my subscribe response | ||
And response contains messages with 'custom-message-type' and 'user-custom-message-type' types |