Skip to content

Commit

Permalink
Custom Message Type
Browse files Browse the repository at this point in the history
  • Loading branch information
seba-aln committed Oct 23, 2024
1 parent 8118a32 commit 4d1a6cb
Show file tree
Hide file tree
Showing 18 changed files with 350 additions and 749 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
18 changes: 9 additions & 9 deletions behat.yml
Original file line number Diff line number Diff line change
@@ -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 ]
autoload:
'': "%paths.base%/tests/Acceptance/"

suites:
custom-message-type:
paths:
- "%paths.base%/tests/Acceptance/CustomMessageType"
contexts:
- PubNubTests\Acceptance\CustomMessageType\CustomMessageTypeContext
12 changes: 10 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -29,7 +36,8 @@
},
"autoload": {
"psr-4": {
"PubNub\\": "src/PubNub"
"PubNub\\": "src/PubNub",
"PubNubTests\\": "tests"
}
},
"autoload-dev": {
Expand Down
21 changes: 21 additions & 0 deletions src/PubNub/Endpoints/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class History extends Endpoint
/** @var bool */
protected ?bool $includeTimetoken;

protected ?bool $includeCustomMessageType;

/**
* @param string $channel
* @return $this
Expand Down Expand Up @@ -97,6 +99,17 @@ public function includeTimetoken($includeTimetoken)
return $this;
}

/**
* @param bool $includeTimetoken
* @return $this
*/
public function includeCustomMessageType($includeCustomMessageType)

Check failure on line 106 in src/PubNub/Endpoints/History.php

View workflow job for this annotation

GitHub Actions / Lint project

Method PubNub\Endpoints\History::includeCustomMessageType() has parameter $includeCustomMessageType with no type specified.

Check failure on line 106 in src/PubNub/Endpoints/History.php

View workflow job for this annotation

GitHub Actions / Lint project

PHPDoc tag @param references unknown parameter: $includeTimetoken
{
$this->includeCustomMessageType = $includeCustomMessageType;

return $this;
}

/**
* @throws PubNubValidationException
*/
Expand Down Expand Up @@ -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;
}

Expand Down
16 changes: 14 additions & 2 deletions src/PubNub/Endpoints/MessagePersistance/FetchMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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)
Expand Down Expand Up @@ -91,6 +93,12 @@ public function includeMessageType($includeMessageType)
return $this;
}

public function includeCustomMessageType($includeCustomMessageType)

Check failure on line 96 in src/PubNub/Endpoints/MessagePersistance/FetchMessages.php

View workflow job for this annotation

GitHub Actions / Lint project

Method PubNub\Endpoints\MessagePersistance\FetchMessages::includeCustomMessageType() has no return type specified.

Check failure on line 96 in src/PubNub/Endpoints/MessagePersistance/FetchMessages.php

View workflow job for this annotation

GitHub Actions / Lint project

Method PubNub\Endpoints\MessagePersistance\FetchMessages::includeCustomMessageType() has parameter $includeCustomMessageType with no type specified.
{
$this->includeCustomMessageType = $includeCustomMessageType;
return $this;
}

public function includeMessageActions($includeMessageActions)
{
$this->includeMessageActions = $includeMessageActions;
Expand All @@ -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)) {

Check failure on line 128 in src/PubNub/Endpoints/MessagePersistance/FetchMessages.php

View workflow job for this annotation

GitHub Actions / Lint project

Negated boolean expression is always true.
if (strpos($customParam, 'include') === 0) {
$params[$requestParam] = $this->$customParam ? 'true' : 'false';
continue;
}
$params[$requestParam] = $this->$customParam;
}
}
Expand Down
22 changes: 21 additions & 1 deletion src/PubNub/Endpoints/PubSub/Signal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*/
Expand Down Expand Up @@ -84,7 +98,13 @@ protected function buildData()

protected function customParams()
{
return [];
$params = [];

if (isset($this->customMessageType)) {
$params['custom_message_type'] = $this->customMessageType;
}

return $params;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -42,12 +43,18 @@ public function setMessageType(string $messageType)
return $this;
}

public function setCustomMessageType(string $customMessageType)

Check failure on line 46 in src/PubNub/Models/Consumer/MessagePersistence/PNFetchMessagesItemResult.php

View workflow job for this annotation

GitHub Actions / Lint project

Method PubNub\Models\Consumer\MessagePersistence\PNFetchMessagesItemResult::setCustomMessageType() has no return type specified.
{
$this->customMessageType = $customMessageType;
return $this;
}

public function getMessage(): mixed
{
return $this->message;
}

public function getTimetoken(): string
public function getTimetoken(): ?string
{
return $this->timetoken;
}
Expand All @@ -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'];
Expand All @@ -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']);
}
Expand Down
Loading

0 comments on commit 4d1a6cb

Please sign in to comment.