From 4d1a6cb31471ff750a7676074522f69f41e3f981 Mon Sep 17 00:00:00 2001 From: Sebastian Molenda Date: Wed, 23 Oct 2024 21:00:59 +0200 Subject: [PATCH] Custom Message Type --- .github/workflows/run-tests.yml | 28 ++ behat.yml | 18 +- composer.json | 12 +- src/PubNub/Endpoints/History.php | 21 ++ .../MessagePersistance/FetchMessages.php | 16 +- src/PubNub/Endpoints/PubSub/Signal.php | 22 +- .../PNFetchMessagesItemResult.php | 34 ++- .../CustomMessageTypeContext.php | 176 +++++++++++ .../history-custom-mssg-type.feature | 26 ++ .../PubNubContext.php | 2 +- tests/bootstrap.php | 4 + .../features/PubNubFeatures/Access/Given.php | 257 ---------------- tests/features/PubNubFeatures/Access/Then.php | 289 ------------------ tests/features/PubNubFeatures/Access/When.php | 77 ----- .../PubNubFeatures/PNContextHelper.php | 21 -- .../bootstrap/AccessManagerContext.php | 34 --- tests/features/bootstrap/TimeContext.php | 31 -- tests/integrational/SubscribeTest.php | 31 +- 18 files changed, 350 insertions(+), 749 deletions(-) create mode 100644 tests/Acceptance/CustomMessageType/CustomMessageTypeContext.php create mode 100644 tests/Acceptance/CustomMessageType/history-custom-mssg-type.feature rename tests/{features/PubNubFeatures => Acceptance}/PubNubContext.php (97%) delete mode 100644 tests/features/PubNubFeatures/Access/Given.php delete mode 100644 tests/features/PubNubFeatures/Access/Then.php delete mode 100644 tests/features/PubNubFeatures/Access/When.php delete mode 100644 tests/features/PubNubFeatures/PNContextHelper.php delete mode 100644 tests/features/bootstrap/AccessManagerContext.php delete mode 100644 tests/features/bootstrap/TimeContext.php diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 9d870679..44e6750c 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -65,6 +65,34 @@ jobs: - name: Cancel workflow runs for commit on error if: failure() uses: ./.github/.release/actions/actions/utils/fast-jobs-failure + acceptance-tests: + name: Perform Acceptance BDD tests + runs-on: ubuntu-latest + steps: + - name: Checkout project + uses: actions/checkout@v3 + - name: Checkout mock-server action + uses: actions/checkout@v3 + with: + repository: pubnub/client-engineering-deployment-tools + ref: v1 + token: ${{ secrets.GH_TOKEN }} + path: .github/.release/actions + - name: Run mock server action + uses: ./.github/.release/actions/actions/mock-server + with: + token: ${{ secrets.GH_TOKEN }} + - name: Install Composer dev depenencies + run: | + composer install --dev + - name: Run acceptance tests + run: | + composer acceptance-test + - name: Expose acceptance tests reports + uses: actions/upload-artifact@v2 + with: + name: acceptance-test-reports + path: ./tests/Acceptance/reports all-tests: name: Tests needs: [tests] diff --git a/behat.yml b/behat.yml index cb64c869..77c4d0e8 100644 --- a/behat.yml +++ b/behat.yml @@ -1,10 +1,10 @@ default: - autoload: - - "%paths.base%/tests/features/bootstrap/" - suites: - access: - paths: [ "%paths.base%/tests/features/bootstrap/access" ] - contexts: [ AccessManagerContext ] - utilities: - paths: [ "%paths.base%/tests/features/bootstrap/utilities" ] - contexts: [ TimeContext ] \ No newline at end of file + autoload: + '': "%paths.base%/tests/Acceptance/" + + suites: + custom-message-type: + paths: + - "%paths.base%/tests/Acceptance/CustomMessageType" + contexts: + - PubNubTests\Acceptance\CustomMessageType\CustomMessageTypeContext \ No newline at end of file diff --git a/composer.json b/composer.json index 4ca0e30a..8af17687 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,14 @@ } ], "scripts": { - "test": "./vendor/bin/phpunit tests/ --verbose --coverage-clover=coverage.clover" + "test": "./vendor/bin/phpunit tests/ --verbose --coverage-clover=coverage.clover", + "acceptance-test": [ + "mkdir -p tests/Acceptance/reports", + "cp sdk-specifications/features/publish/publish-custom-mssg-type.feature tests/Acceptance/CustomMessageType/publish-custom-mssg-type.feature", + "cp sdk-specifications/features/publish/signal-custom-mssg-type.feature tests/Acceptance/CustomMessageType/signal-custom-mssg-type.feature", + "cp sdk-specifications/features/history/history-custom-mssg-type.feature tests/Acceptance/CustomMessageType/history-custom-mssg-type.feature", + "vendor/bin/behat -f junit -o tests/Acceptance/reports/" + ] }, "require": { "php": ">=8.0", @@ -29,7 +36,8 @@ }, "autoload": { "psr-4": { - "PubNub\\": "src/PubNub" + "PubNub\\": "src/PubNub", + "PubNubTests\\": "tests" } }, "autoload-dev": { diff --git a/src/PubNub/Endpoints/History.php b/src/PubNub/Endpoints/History.php index ff0fb528..b3149e9a 100644 --- a/src/PubNub/Endpoints/History.php +++ b/src/PubNub/Endpoints/History.php @@ -31,6 +31,8 @@ class History extends Endpoint /** @var bool */ protected ?bool $includeTimetoken; + protected ?bool $includeCustomMessageType; + /** * @param string $channel * @return $this @@ -97,6 +99,17 @@ public function includeTimetoken($includeTimetoken) return $this; } + /** + * @param bool $includeTimetoken + * @return $this + */ + public function includeCustomMessageType($includeCustomMessageType) + { + $this->includeCustomMessageType = $includeCustomMessageType; + + return $this; + } + /** * @throws PubNubValidationException */ @@ -138,6 +151,14 @@ protected function customParams() $this->includeTimetoken ? $params['include_token'] = "true" : $params['include_token'] = "false"; } + if (isset($this->includeCustomMessageType)) { + if ($this->includeCustomMessageType) { + $params['include_custom_message_type'] = "true"; + } else { + $params['include_custom_message_type'] = "false"; + } + } + return $params; } diff --git a/src/PubNub/Endpoints/MessagePersistance/FetchMessages.php b/src/PubNub/Endpoints/MessagePersistance/FetchMessages.php index 3a8f1441..90c2ae67 100644 --- a/src/PubNub/Endpoints/MessagePersistance/FetchMessages.php +++ b/src/PubNub/Endpoints/MessagePersistance/FetchMessages.php @@ -31,8 +31,9 @@ class FetchMessages extends Endpoint protected bool $includeMeta = false; protected bool $includeUuid = false; - protected bool $includeMessageType = false; + protected bool $includeMessageType = true; protected bool $includeMessageActions = false; + protected bool $includeCustomMessageType = true; protected array $customParamMapping = [ 'start' => 'start', @@ -41,6 +42,7 @@ class FetchMessages extends Endpoint 'includeMeta' => 'include_meta', 'includeUuid' => 'include_uuid', 'includeMessageType' => 'include_message_type', + 'includeCustomMessageType' => 'include_custom_message_type', ]; public function channels(...$channel) @@ -91,6 +93,12 @@ public function includeMessageType($includeMessageType) return $this; } + public function includeCustomMessageType($includeCustomMessageType) + { + $this->includeCustomMessageType = $includeCustomMessageType; + return $this; + } + public function includeMessageActions($includeMessageActions) { $this->includeMessageActions = $includeMessageActions; @@ -117,7 +125,11 @@ protected function customParams() { $params = []; foreach ($this->customParamMapping as $customParam => $requestParam) { - if (isset($this->$customParam) && !empty($this->$customParam)) { + if (isset($this->$customParam) && !is_null($this->$customParam)) { + if (strpos($customParam, 'include') === 0) { + $params[$requestParam] = $this->$customParam ? 'true' : 'false'; + continue; + } $params[$requestParam] = $this->$customParam; } } diff --git a/src/PubNub/Endpoints/PubSub/Signal.php b/src/PubNub/Endpoints/PubSub/Signal.php index e179e586..a4b11fe6 100644 --- a/src/PubNub/Endpoints/PubSub/Signal.php +++ b/src/PubNub/Endpoints/PubSub/Signal.php @@ -20,6 +20,9 @@ class Signal extends Endpoint /** @var string $channel to send message on*/ protected $channel; + /** @var string $customMessageType User defined message type */ + protected ?string $customMessageType; + /** * @param mixed $message * @return $this @@ -42,6 +45,17 @@ public function channel($channel) return $this; } + /** + * @param string $customMessageType + * @return $this + */ + public function customMessageType(?string $customMessageType) + { + $this->customMessageType = $customMessageType; + + return $this; + } + /** * @throws PubNubValidationException */ @@ -84,7 +98,13 @@ protected function buildData() protected function customParams() { - return []; + $params = []; + + if (isset($this->customMessageType)) { + $params['custom_message_type'] = $this->customMessageType; + } + + return $params; } /** diff --git a/src/PubNub/Models/Consumer/MessagePersistence/PNFetchMessagesItemResult.php b/src/PubNub/Models/Consumer/MessagePersistence/PNFetchMessagesItemResult.php index c65deb55..1514d4e9 100644 --- a/src/PubNub/Models/Consumer/MessagePersistence/PNFetchMessagesItemResult.php +++ b/src/PubNub/Models/Consumer/MessagePersistence/PNFetchMessagesItemResult.php @@ -4,12 +4,13 @@ class PNFetchMessagesItemResult { - protected mixed $message; - protected string $timetoken; - protected mixed $metadata; - protected mixed $actions; - protected string $uuid; - protected string $messageType; + protected mixed $message = null; + protected ?string $timetoken = null; + protected mixed $metadata = null; + protected mixed $actions = null; + protected ?string $uuid = null; + protected ?string $messageType = null; + protected ?string $customMessageType = null; public function __construct(mixed $message, string $timetoken) @@ -42,12 +43,18 @@ public function setMessageType(string $messageType) return $this; } + public function setCustomMessageType(string $customMessageType) + { + $this->customMessageType = $customMessageType; + return $this; + } + public function getMessage(): mixed { return $this->message; } - public function getTimetoken(): string + public function getTimetoken(): ?string { return $this->timetoken; } @@ -62,16 +69,21 @@ public function getActions(): mixed return $this->actions; } - public function getUuid(): string + public function getUuid(): ?string { return $this->uuid; } - public function getMessageType(): string + public function getMessageType(): ?string { return $this->messageType; } + public function getCustomMessageType(): ?string + { + return $this->customMessageType; + } + public static function fromJson($json, $crypto): static { $message = $json['message']; @@ -91,6 +103,10 @@ public static function fromJson($json, $crypto): static $item->setMessageType($json['message_type']); } + if (isset($json['custom_message_type'])) { + $item->setCustomMessageType($json['custom_message_type']); + } + if (isset($json['meta'])) { $item->setMetadata($json['meta']); } diff --git a/tests/Acceptance/CustomMessageType/CustomMessageTypeContext.php b/tests/Acceptance/CustomMessageType/CustomMessageTypeContext.php new file mode 100644 index 00000000..5d1990f8 --- /dev/null +++ b/tests/Acceptance/CustomMessageType/CustomMessageTypeContext.php @@ -0,0 +1,176 @@ +config = new PNConfiguration(); + } + + /** + * @Given the demo keyset + */ + public function theDemoKeyset() + { + $this->config->setOrigin("localhost:8090") + ->setSecure(false) + ->setPublishKey('demo') + ->setSubscribeKey('demo') + ->setUserId('demo'); + $this->pubnub = new PubNub($this->config); + } + + /** + * @Given the demo keyset with enabled storage + */ + public function theDemoKeysetWithEnabledStorage() + { + $this->config->setOrigin("localhost:8090") + ->setSecure(false) + ->setPublishKey('demo') + ->setSubscribeKey('demo') + ->setUserId('demo'); + $this->pubnub = new PubNub($this->config); + } + + /** + * @When I fetch message history for :channelName channel + */ + public function iFetchMessageHistoryForChannel($channelName) + { + $this->channelName = $channelName; + try { + $this->response = $this->pubnub->fetchMessages() + ->channels($this->channelName) + ->sync(); + } catch (PubNubServerException $e) { + $this->response = $e; + } + } + + /** + * @When I fetch message history with :attribute set to :value for :channelName channel + */ + public function iFetchMessageHistoryWithSetToForChannel($attribute, $value, $channelName) + { + $this->channelName = $channelName; + $builder = $this->pubnub->fetchMessages()->channels($this->channelName); + if ($attribute === "include_custom_message_type") { + $builder->includeCustomMessageType($value === "true" ? true : false); + } + try { + $this->response = $builder->sync(); + } catch (PubNubServerException $e) { + $this->response = $e; + } + } + + /** + * @Then history response contains messages with :messageType1 and :messageType2 message types + */ + public function historyResponseContainsMessagesWithAndMessageTypes($messageType1, $messageType2) + { + $messages = $this->response->getChannels()[$this->channelName]; + assert((int)$messages[0]->getMessageType() === (int)$messageType1); + assert((int)$messages[1]->getMessageType() === (int)$messageType2); + } + + /** + * @Then history response contains messages with :customMessageType1 and :customMessageType2 types + */ + public function historyResponseContainsMessagesWithAndTypes($customMessageType1, $customMessageType2) + { + $messages = $this->response->getChannels()[$this->channelName]; + assert($messages[0]->getCustomMessageType() === $customMessageType1); + assert($messages[1]->getCustomMessageType() === $customMessageType2); + } + + /** + * @Then history response contains messages without customMessageType + */ + public function historyResponseContainsMessagesWithoutCustommessagetype() + { + foreach ($this->response->getChannels()[$this->channelName] as $message) { + assert(is_null($message->getCustomMessageType())); + } + } + + /** + * @When I publish message with :customMessageType customMessageType + */ + public function iPublishMessageWithCustommessagetype($customMessageType) + { + try { + $this->response = $this->pubnub->publish() + ->channel("ch") + ->message("msg") + ->customMessageType($customMessageType) + ->sync(); + } catch (PubNubServerException $e) { + $this->response = $e; + } + } + + /** + * @Then I receive a successful response + */ + public function iReceiveASuccessfulResponse() + { + assert($this->response instanceof PNPublishResult || $this->response instanceof PNSignalResult + || $this->response instanceof PNFetchMessagesResult); + } + + /** + * @Then I receive an error response + */ + public function iReceiveAnErrorResponse() + { + assert($this->response instanceof PubNubServerException); + } + + /** + * @When I send a signal with :customMessageType customMessageType + */ + public function iSendASignalWithCustommessagetype($customMessageType) + { + try { + $this->response = $this->pubnub->signal() + ->channel("ch") + ->message("msg") + ->customMessageType($customMessageType) + ->sync(); + } catch (PubNubServerException $e) { + $this->response = $e; + } + } +} diff --git a/tests/Acceptance/CustomMessageType/history-custom-mssg-type.feature b/tests/Acceptance/CustomMessageType/history-custom-mssg-type.feature new file mode 100644 index 00000000..29573ea2 --- /dev/null +++ b/tests/Acceptance/CustomMessageType/history-custom-mssg-type.feature @@ -0,0 +1,26 @@ + +@featureSet=historyCustomMssgType @beta +Feature: History for VSP + As a PubNub user I want to fetch history with message type. + Client should be able to opt-out default `includeType`. + + Background: + Given the demo keyset with enabled storage + + @contract=fetchHistoryWithPubNubMessageTypes + Scenario: Client can fetch history with message types + When I fetch message history for 'simple-channel' channel + Then I receive a successful response + And history response contains messages with '0' and '4' message types + + @contract=fetchHistoryWithUserAndPubNubTypes + Scenario: Client can fetch history with customMessageType + When I fetch message history for 'some-channel' channel + Then I receive a successful response + And history response contains messages with 'custom-message-type' and 'user-custom-message-type' types + + @contract=fetchHistoryWithoutTypes + Scenario: Client can fetch history without customMessageType enabled by default + When I fetch message history with 'include_custom_message_type' set to 'false' for 'some-channel' channel + Then I receive a successful response + And history response contains messages without customMessageType diff --git a/tests/features/PubNubFeatures/PubNubContext.php b/tests/Acceptance/PubNubContext.php similarity index 97% rename from tests/features/PubNubFeatures/PubNubContext.php rename to tests/Acceptance/PubNubContext.php index abc7a50d..baa2d0f8 100644 --- a/tests/features/PubNubFeatures/PubNubContext.php +++ b/tests/Acceptance/PubNubContext.php @@ -1,6 +1,6 @@ context['ttl'] = (int)$ttl; - } - - /** - * @Given the authorized UUID :uuid - */ - public function theAuthorizedUuid($uuid) - { - $this->context['authorizedUuid'] = $uuid; - } - - /** - * @Given the :channel CHANNEL resource access permissions - */ - public function theChannelResourceAccessPermissions($channel) - { - $this->context['resource']['channel'][$channel] = []; - $this->resource = &$this->context['resource']['channel'][$channel]; - } - - /** - * @Given the :channelGroup CHANNEL_GROUP resource access permissions - */ - public function theChannelGroupResourceAccessPermissions($channelGroup) - { - $this->context['resource']['channelGroup'][$channelGroup] = []; - $this->resource = &$this->context['resource']['channelGroup'][$channelGroup]; - } - - /** - * @Given the :uuid UUID resource access permissions - */ - public function theUuidResourceAccessPermissions($uuid) - { - $this->context['resource']['uuid'][$uuid] = []; - $this->resource = &$this->context['resource']['uuid'][$uuid]; - } - - /** - * @Given grant resource permission READ - */ - public function grantResourcePermissionRead() - { - $this->resource['read'] = true; - } - - /** - * @Given grant resource permission WRITE - */ - public function grantResourcePermissionWrite() - { - $this->resource['write'] = true; - } - - /** - * @Given grant resource permission GET - */ - public function grantResourcePermissionGet() - { - $this->resource['get'] = true; - } - - /** - * @Given grant resource permission MANAGE - */ - public function grantResourcePermissionManage() - { - $this->resource['manage'] = true; - } - - /** - * @Given grant resource permission UPDATE - */ - public function grantResourcePermissionUpdate() - { - $this->resource['update'] = true; - } - - /** - * @Given grant resource permission JOIN - */ - public function grantResourcePermissionJoin() - { - $this->resource['join'] = true; - } - - /** - * @Given grant resource permission DELETE - */ - public function grantResourcePermissionDelete() - { - $this->resource['delete'] = true; - } - - /** - * @Given I have a keyset with access manager enabled - */ - public function iHaveAKeysetWithAccessManagerEnabled() - { - $this->pubnub = new PubNub($this->pnConfig); - } - - /** - * @Given the :channel CHANNEL pattern access permissions - */ - public function theChannelPatternAccessPermissions($channel) - { - $this->context['pattern']['channel'][$channel] = []; - $this->resource = &$this->context['pattern']['channel'][$channel]; - } - - /** - * @Given the :channelGroup CHANNEL_GROUP pattern access permissions - */ - public function theChannelGroupPatternAccessPermissions($channelGroup) - { - $this->context['pattern']['channelGroup'][$channelGroup] = []; - $this->resource = &$this->context['pattern']['channelGroup'][$channelGroup]; - } - - /** - * @Given the :uuid UUID pattern access permissions - */ - public function theUuidPatternAccessPermissions($uuid) - { - $this->context['pattern']['uuid'][$uuid] = []; - $this->resource = &$this->context['pattern']['uuid'][$uuid]; - } - - /** - * @Given grant pattern permission READ - */ - public function grantPatternPermissionRead() - { - $this->resource['read'] = true; - } - - /** - * @Given grant pattern permission WRITE - */ - public function grantPatternPermissionWrite() - { - $this->resource['write'] = true; - } - - /** - * @Given grant pattern permission GET - */ - public function grantPatternPermissionGet() - { - $this->resource['get'] = true; - } - - /** - * @Given grant pattern permission MANAGE - */ - public function grantPatternPermissionManage() - { - $this->resource['manage'] = true; - } - - /** - * @Given grant pattern permission UPDATE - */ - public function grantPatternPermissionUpdate() - { - $this->resource['update'] = true; - } - - /** - * @Given grant pattern permission JOIN - */ - public function grantPatternPermissionJoin() - { - $this->resource['join'] = true; - } - - /** - * @Given grant pattern permission DELETE - */ - public function grantPatternPermissionDelete() - { - $this->resource['delete'] = true; - } - - /** - * @Given deny resource permission GET - */ - public function denyResourcePermissionGet() - { - $this->resource['read'] = false; - } - - /** - * @Given I have a known token containing an authorized UUID - */ - public function iHaveAKnownTokenContainingAnAuthorizedUuid() - { - $this->token = 'qEF2AkF0GmGEQqhDdHRsGDxDcmVzpURjaGFuoWljaGFubmVsLTEY70NncnChb2NoYW5uZWxfZ3JvdXAtMQVDdXNyoENzcGO' - . 'gRHV1aWShZnV1aWQtMRhoQ3BhdKVEY2hhbqFtXmNoYW5uZWwtXFMqJBjvQ2dycKF0XjpjaGFubmVsX2dyb3VwLVxTKiQFQ3VzcqBDc3B' - . 'joER1dWlkoWpedXVpZC1cUyokGGhEbWV0YaBEdXVpZHR0ZXN0LWF1dGhvcml6ZWQtdXVpZENzaWdYIDuyE8oo74oI9LVWTwp_OBrvirh' - . 'srR88KgoMPmQT7Cqo'; - } - - /** - * @Given I have a known token containing UUID resource permissions - */ - public function iHaveAKnownTokenContainingUuidResourcePermissions() - { - $this->token = 'qEF2AkF0GmGEQqhDdHRsGDxDcmVzpURjaGFuoWljaGFubmVsLTEY70NncnChb2NoYW5uZWxfZ3JvdXAtMQVDdXNyoENzcGO' - . 'gRHV1aWShZnV1aWQtMRhoQ3BhdKVEY2hhbqFtXmNoYW5uZWwtXFMqJBjvQ2dycKF0XjpjaGFubmVsX2dyb3VwLVxTKiQFQ3VzcqBDc3B' - . 'joER1dWlkoWpedXVpZC1cUyokGGhEbWV0YaBEdXVpZHR0ZXN0LWF1dGhvcml6ZWQtdXVpZENzaWdYIDuyE8oo74oI9LVWTwp_OBrvirh' - . 'srR88KgoMPmQT7Cqo'; - } - - /** - * @Given I have a known token containing UUID pattern Permissions - */ - public function iHaveAKnownTokenContainingUuidPatternPermissions() - { - $this->token = 'qEF2AkF0GmGEQqhDdHRsGDxDcmVzpURjaGFuoWljaGFubmVsLTEY70NncnChb2NoYW5uZWxfZ3JvdXAtMQVDdXNyoENzcGO' - . 'gRHV1aWShZnV1aWQtMRhoQ3BhdKVEY2hhbqFtXmNoYW5uZWwtXFMqJBjvQ2dycKF0XjpjaGFubmVsX2dyb3VwLVxTKiQFQ3VzcqBDc3B' - . 'joER1dWlkoWpedXVpZC1cUyokGGhEbWV0YaBEdXVpZHR0ZXN0LWF1dGhvcml6ZWQtdXVpZENzaWdYIDuyE8oo74oI9LVWTwp_OBrvirh' - . 'srR88KgoMPmQT7Cqo'; - } - - /** - * @Given a token - */ - public function aToken() - { - $this->token = PNContextHelper::PAM_TOKEN_WITH_ALL_PERMS_GRANTED; - return true; - } - - /** - * @Given the token string :token - */ - public function theTokenString($token) - { - $this->token = $token; - } -} diff --git a/tests/features/PubNubFeatures/Access/Then.php b/tests/features/PubNubFeatures/Access/Then.php deleted file mode 100644 index a2638064..00000000 --- a/tests/features/PubNubFeatures/Access/Then.php +++ /dev/null @@ -1,289 +0,0 @@ -token->getUuid()); - } - - /** - * @Then the token contains the TTL :ttl - */ - public function theTokenContainsTheTtl($ttl) - { - Assert::assertEquals($ttl, $this->token->getTtl()); - } - - /** - * @Then the token has :channel CHANNEL resource access permissions - */ - public function theTokenHasChannelResourceAccessPermissions($channel) - { - $this->resource = $this->token->getChannelResource($channel); - Assert::assertNotEquals(false, $this->resource); - } - - /** - * @Then token resource permission READ - */ - public function tokenResourcePermissionRead() - { - Assert::assertTrue($this->resource->hasRead()); - } - - /** - * @Then token resource permission WRITE - */ - public function tokenResourcePermissionWrite() - { - Assert::assertTrue($this->resource->hasWrite()); - } - - /** - * @Then token resource permission GET - */ - public function tokenResourcePermissionGet() - { - Assert::assertTrue($this->resource->hasGet()); - } - - /** - * @Then token resource permission MANAGE - */ - public function tokenResourcePermissionManage() - { - Assert::assertTrue($this->resource->hasManage()); - } - - /** - * @Then token resource permission UPDATE - */ - public function tokenResourcePermissionUpdate() - { - Assert::assertTrue($this->resource->hasUpdate()); - } - - /** - * @Then token resource permission JOIN - */ - public function tokenResourcePermissionJoin() - { - Assert::assertTrue($this->resource->hasJoin()); - } - - /** - * @Then token resource permission DELETE - */ - public function tokenResourcePermissionDelete() - { - Assert::assertTrue($this->resource->hasDelete()); - } - - /** - * @Then the token has :channelGroup CHANNEL_GROUP resource access permissions - */ - public function theTokenHasChannelGroupResourceAccessPermissions($channelGroup) - { - $this->resource = $this->token->getChannelGroupResource($channelGroup); - Assert::assertNotEquals(false, $this->resource); - } - - /** - * @Then the token has :uuid UUID resource access permissions - */ - public function theTokenHasUuidResourceAccessPermissions($uuid) - { - $this->resource = $this->token->getUuidResource($uuid); - Assert::assertNotEquals(false, $this->resource); - } - - /** - * @Then the token has :channel CHANNEL pattern access permissions - */ - public function theTokenHasChannelPatternAccessPermissions($channel) - { - $this->pattern = $this->token->getChannelPattern($channel); - Assert::assertNotEquals(false, $this->pattern); - } - - /** - * @Then token pattern permission READ - */ - public function tokenPatternPermissionRead() - { - Assert::assertTrue($this->pattern->hasRead()); - } - - /** - * @Then token pattern permission WRITE - */ - public function tokenPatternPermissionWrite() - { - Assert::assertTrue($this->pattern->hasWrite()); - } - - /** - * @Then token pattern permission GET - */ - public function tokenPatternPermissionGet() - { - Assert::assertTrue($this->pattern->hasGet()); - } - - /** - * @Then token pattern permission MANAGE - */ - public function tokenPatternPermissionManage() - { - Assert::assertTrue($this->pattern->hasManage()); - } - - /** - * @Then token pattern permission UPDATE - */ - public function tokenPatternPermissionUpdate() - { - Assert::assertTrue($this->pattern->hasUpdate()); - } - - /** - * @Then token pattern permission JOIN - */ - public function tokenPatternPermissionJoin() - { - Assert::assertTrue($this->pattern->hasJoin()); - } - - /** - * @Then token pattern permission DELETE - */ - public function tokenPatternPermissionDelete() - { - Assert::assertTrue($this->pattern->hasDelete()); - } - - /** - * @Then the token has :channelGroup CHANNEL_GROUP pattern access permissions - */ - public function theTokenHasChannelGroupPatternAccessPermissions($channelGroup) - { - $this->pattern = $this->token->getChannelGroupPattern($channelGroup); - Assert::assertNotEquals(false, $this->pattern); - } - - /** - * @Then the token has :uuid UUID pattern access permissions - */ - public function theTokenHasUuidPatternAccessPermissions($uuid) - { - $this->pattern = $this->token->getUuidPattern($uuid); - Assert::assertNotEquals(false, $this->pattern); - } - - /** - * @Then the token does not contain an authorized uuid - */ - public function theTokenDoesNotContainAnAuthorizedUuid() - { - Assert::assertNull($this->token->getUuid()); - } - - /** - * @Then the error status code is :statusCode - */ - public function theErrorStatusCodeIs($statusCode) - { - Assert::assertEquals($statusCode, $this->error->getStatusCode()); - } - - /** - * @Then the error message is :errorMessage - */ - public function theErrorMessageIs($errorMessage) - { - Assert::assertEquals($errorMessage, $this->error->getServerErrorMessage()); - } - - /** - * @Then the error source is :source - */ - public function theErrorSourceIs($source) - { - Assert::assertEquals($source, $this->error->getServerErrorSource()); - } - - /** - * @Then the error detail message is :detailMessage - */ - public function theErrorDetailMessageIs($detailMessage) - { - Assert::assertEquals($detailMessage, $this->error->getServerErrorDetails()->message); - } - - /** - * @Then the error detail location is :detailLocation - */ - public function theErrorDetailLocationIs($detailLocation) - { - Assert::assertEquals($detailLocation, $this->error->getServerErrorDetails()->location); - } - - /** - * @Then the error detail location type is :detailLocationType - */ - public function theErrorDetailLocationTypeIs($detailLocationType) - { - Assert::assertEquals($detailLocationType, $this->error->getServerErrorDetails()->locationType); - } - - /** - * @Then the parsed token output contains the authorized UUID :uuid - */ - public function theParsedTokenOutputContainsTheAuthorizedUuid($uuid) - { - Assert::assertEquals($uuid, $this->token->getUuid()); - } - - /** - * @Then I get confirmation that token has been revoked - */ - public function iGetConfirmationThatTokenHasBeenRevoked() - { - Assert::assertEquals(PNRequestResult::class, get_class($this->result)); - Assert::assertEquals('Success'::class, $this->result->getMessage()); - } - - /** - * @Then an error is returned - */ - public function anErrorIsReturned() - { - Assert::assertEquals(PubNubServerException::class, get_class($this->error)); - } - - /** - * @Then the error detail message is not empty - */ - public function theErrorDetailMessageIsNotEmpty() - { - Assert::assertNotEmpty($this->error->getServerErrorDetails()->message); - } - - /** - * @Then the error service is :service - */ - public function theErrorServiceIs($service) - { - Assert::assertEquals($service, $this->error->getBody()->service); - } -} diff --git a/tests/features/PubNubFeatures/Access/When.php b/tests/features/PubNubFeatures/Access/When.php deleted file mode 100644 index 14934896..00000000 --- a/tests/features/PubNubFeatures/Access/When.php +++ /dev/null @@ -1,77 +0,0 @@ -pubnub->grantToken(); - $token = $grantToken->ttl($this->context['ttl']) - ->authorizedUuid($this->context['authorizedUuid'] ?? null) - ->addChannelResources($this->context['resource']['channel'] ?? null) - ->addChannelGroupResources($this->context['resource']['channelGroup'] ?? null) - ->addUuidResources($this->context['resource']['uuid'] ?? null) - ->addChannelPatterns($this->context['pattern']['channel'] ?? null) - ->addChannelGroupPatterns($this->context['pattern']['channelGroup'] ?? null) - ->addUuidPatterns($this->context['pattern']['uuid'] ?? null) - ->sync(); - $this->token = $this->pubnub->parseToken($token); - } - - /** - * @When I attempt to grant a token specifying those permissions - */ - public function iAttemptToGrantATokenSpecifyingThosePermissions() - { - $this->error = false; - try { - /** @var GrantToken */ - $grantToken = $this->pubnub->grantToken(); - $grantToken->ttl($this->context['ttl']) - ->authorizedUuid($this->context['authorizedUuid'] ?? null) - ->addChannelResources($this->context['resource']['channel'] ?? null) - ->addChannelGroupResources($this->context['resource']['channelGroup'] ?? null) - ->addUuidResources($this->context['resource']['uuid'] ?? null) - ->addChannelPatterns($this->context['pattern']['channel'] ?? null) - ->addChannelGroupPatterns($this->context['pattern']['channelGroup'] ?? null) - ->addUuidPatterns($this->context['pattern']['uuid'] ?? null) - ->sync(); - } catch (PubNubServerException $exception) { - $this->error = $exception; - return true; - } - - return false; - } - - /** - * @When I parse the token - */ - public function iParseTheToken() - { - $this->pubnub = new PubNub($this->pnConfig); - $this->token = $this->pubnub->parseToken($this->token); - } - - /** - * @When I revoke a token - */ - public function iRevokeAToken() - { - try { - $this->result = $this->pubnub->revokeToken() - ->token($this->token) - ->sync(); - } catch (PubNubServerException $exception) { - $this->error = $exception; - } - } -} diff --git a/tests/features/PubNubFeatures/PNContextHelper.php b/tests/features/PubNubFeatures/PNContextHelper.php deleted file mode 100644 index 3abb655c..00000000 --- a/tests/features/PubNubFeatures/PNContextHelper.php +++ /dev/null @@ -1,21 +0,0 @@ -pnConfig = new PNConfiguration(); - $this->pnConfig->setPublishKey('pub-c-mock-key'); - $this->pnConfig->setSubscribeKey('sub-c-mock-key'); - $this->pnConfig->setSecretKey('sec-c-mock-key'); - $this->pnConfig->setOrigin($this->origin); - $this->pnConfig->setSecure(false); - } -} diff --git a/tests/features/bootstrap/TimeContext.php b/tests/features/bootstrap/TimeContext.php deleted file mode 100644 index 1799c9fb..00000000 --- a/tests/features/bootstrap/TimeContext.php +++ /dev/null @@ -1,31 +0,0 @@ -response = $pubnub->time()->sync(); - return true; - } - - /** - * @Then I receive successful response - */ - public function iReceiveSuccessfulResponse() - { - return ('PubNub\Models\Consumer\PNTimeResult' === get_class($this->response)); - } -} diff --git a/tests/integrational/SubscribeTest.php b/tests/integrational/SubscribeTest.php index ab42f3b8..91331070 100644 --- a/tests/integrational/SubscribeTest.php +++ b/tests/integrational/SubscribeTest.php @@ -2,7 +2,6 @@ namespace Tests\Integrational; - use PubNub\Enums\PNStatusCategory; use PubNub\Exceptions\PubNubUnsubscribeException; use PubNub\Models\Consumer\PubSub\PNMessageResult; @@ -11,12 +10,10 @@ use PubNub\Models\ResponseHelpers\PNStatus; use PubNub\PubNub; - const CHANNEL = 'ch1'; const MESSAGE = 'hey'; const GROUP = 'gr1'; - /** * Class SubscribeTest * @requires extension pthreads @@ -59,6 +56,7 @@ public function xtestCGSubscribePublishUnsubscribe() } } +//phpcs:ignore PSR1.Classes.ClassDeclaration class MySubscribeCallback extends SubscribeCallback { protected $config; @@ -67,12 +65,12 @@ class MySubscribeCallback extends SubscribeCallback * MySubscribeCallback constructor. * @param $config */ - function __construct(PNConfiguration $config) + public function __construct(PNConfiguration $config) { $this->config = $config; } - function status($pubnub, $status) + public function status($pubnub, $status) { if ($status->getCategory() === PNStatusCategory::PNConnectedCategory) { throw new PubNubUnsubscribeException(); @@ -84,22 +82,22 @@ function status($pubnub, $status) * @param PNMessageResult $message * @throws PubNubUnsubscribeException */ - function message($pubnub, $message) + public function message($pubnub, $message) { } - function presence($pubnub, $presence) + public function presence($pubnub, $presence) { } } - +//phpcs:ignore PSR1.Classes.ClassDeclaration class MySubscribePublishCallback extends SubscribeCallback { /** @var PNConfiguration */ protected $config; - function __construct($config) + public function __construct($config) { $this->config = $config; } @@ -108,7 +106,7 @@ function __construct($config) * @param PubNub $pubnub * @param PNStatus $status */ - function status($pubnub, $status) + public function status($pubnub, $status) { if ($status->getCategory() === PNStatusCategory::PNConnectedCategory) { $publishThread = new PublishThread($this->config, false); @@ -122,20 +120,21 @@ function status($pubnub, $status) * @param PNMessageResult $message * @throws PubNubUnsubscribeException */ - function message($pubnub, $message) + public function message($pubnub, $message) { if ($message->getMessage() === MESSAGE) { throw new PubNubUnsubscribeException(); } } - function presence($pubnub, $presence) + public function presence($pubnub, $presence) { } } - -class PublishThread extends \Thread { +//phpcs:ignore PSR1.Classes.ClassDeclaration +class PublishThread extends \Thread +{ /** @var PNConfiguration */ protected $config; @@ -156,11 +155,11 @@ public function run() $pubnub->publish()->channel(CHANNEL)->message(MESSAGE)->sync(); } - function message($pubnub, $message) + public function message($pubnub, $message) { } - function presence($pubnub, $presence) + public function presence($pubnub, $presence) { } }