Skip to content

Commit 570b5e8

Browse files
committed
Added Behat tests and unittests
1 parent 1302312 commit 570b5e8

27 files changed

+754
-65
lines changed
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
name: AcceptanceTests
3+
4+
on:
5+
push:
6+
workflow_dispatch:
7+
defaults:
8+
run:
9+
shell: bash
10+
jobs:
11+
build:
12+
name: Perform Acceptance BDD tests
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout project
16+
uses: actions/checkout@v3
17+
- name: Checkout mock-server action
18+
uses: actions/checkout@v3
19+
with:
20+
repository: pubnub/client-engineering-deployment-tools
21+
ref: github-actions
22+
token: ${{ secrets.GH_TOKEN }}
23+
path: client-engineering-deployment-tools
24+
- name: Run mock server action
25+
uses: ./client-engineering-deployment-tools/actions/mock-server
26+
with:
27+
token: ${{ secrets.GH_TOKEN }}
28+
- name: Install Composer dev depenencies
29+
run: |
30+
composer install --dev
31+
- name: Run acceptance tests
32+
run: |
33+
mkdir -p tests/features/bootstrap/access/
34+
mkdir -p tests/features/bootstrap/utilities/
35+
mkdir -p tests/features/reports
36+
cp sdk-specifications/features/access/grant-token.feature tests/features/bootstrap/access/grant-an-access-token.feature
37+
cp sdk-specifications/features/utilities/time.feature tests/features/bootstrap/utilities/time.feature
38+
vendor/bin/behat -f junit -o tests/features/reports/
39+
- name: Expose acceptance tests reports
40+
uses: actions/upload-artifact@v2
41+
with:
42+
name: acceptance-test-reports
43+
path: ./tests/features/reports

behat.yml

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
default:
22
autoload:
3-
- "%paths.base%/tests/features/bootstrap/"
3+
- "%paths.base%/tests/features/"
44
suites:
55
access:
6-
paths: [ "%paths.base%/tests/features/bootstrap/access" ]
7-
contexts: [ AccessManagerContext ]
8-
utilities:
9-
paths: [ "%paths.base%/tests/features/bootstrap/utilities" ]
10-
contexts: [ TimeContext ]
6+
paths: [ "%paths.base%/tests/features/contracts/access/grant-token.feature" ]
7+
contexts: [ PubNubTests\Features\Context\AccessManager\GrantTokenContext ]
8+
publish-to-space:
9+
paths: [
10+
# "%paths.base%/tests/features/contracts/publish/publish.feature",
11+
"%paths.base%/tests/features/contracts/publish/publish-to-space.feature"
12+
]
13+
contexts: [PubNubTests\Features\Context\Publish\PublishContext]
14+
signal-to-space:
15+
paths: ["%paths.base%/tests/features/contracts/publish/signal-to-space.feature"]
16+
contexts: [PubNubTests\Features\Context\Publish\SignalContext]
17+
history:
18+
paths: ["%paths.base%/tests/features/contracts/history/history.feature"]
19+
contexts: [PubNubTests\Features\Context\History\HistoryContext]
20+

composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
"require": {
1919
"php": "^7.4|>=8.0",
2020
"rmccue/requests": "^2.0",
21-
"psr/log": "^1.1|^2.0|^3.0"
21+
"psr/log": "1.1.4"
2222
},
2323
"require-dev": {
2424
"monolog/monolog": "^2.8",
2525
"phpunit/phpunit": "^9.5",
2626
"squizlabs/php_codesniffer": "^3.7",
27-
"phpstan/phpstan": "^1.8"
27+
"phpstan/phpstan": "^1.8",
28+
"behat/behat": "^3.10"
2829
},
2930
"autoload": {
3031
"psr-4": {

src/PubNub/Endpoints/PubSub/Publish.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
class Publish extends Endpoint
1414
{
15-
const GET_PATH = "/publish/%s/%s/0/%s/%s/%s";
16-
const POST_PATH = "/publish/%s/%s/0/%s/%s";
15+
protected const GET_PATH = "/publish/%s/%s/0/%s/%s/%s";
16+
protected const POST_PATH = "/publish/%s/%s/0/%s/%s";
1717

1818
/** @var mixed $message to publish */
1919
protected $message;

src/PubNub/Endpoints/PubSub/Signal.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@
99
use PubNub\Exceptions\PubNubValidationException;
1010
use PubNub\Models\Consumer\PubSub\PNSignalResult;
1111
use PubNub\PubNubUtil;
12+
use PubNub\Models\Consumer\PNMessageType;
1213

1314
class Signal extends Endpoint
1415
{
15-
const SIGNAL_PATH = "/signal/%s/%s/0/%s/0/%s";
16+
protected const SIGNAL_PATH = "/signal/%s/%s/0/%s/0/%s";
1617

17-
/** @var mixed $message to send the signal */
18+
/** @var mixed $message to send the signal */
1819
protected $message;
1920

20-
/** @var string $channel to send message on*/
21+
/** @var string $channel to send message on*/
2122
protected $channel;
2223

24+
/** @var string $spaceId */
2325
protected $spaceId = null;
2426

27+
/** @var PNMessageType $messageType */
2528
protected $messageType = null;
2629

2730
/**
@@ -50,18 +53,18 @@ public function channel($channel)
5053
* @param string $spaceId
5154
* @return $this
5255
*/
53-
public function space($spaceId)
56+
public function spaceId($spaceId)
5457
{
5558
$this->spaceId = $spaceId;
5659

5760
return $this;
5861
}
5962

6063
/**
61-
* @param string $messageType
64+
* @param PNMessageType $messageType
6265
* @return $this
6366
*/
64-
public function messageType($messageType)
67+
public function messageType(PNMessageType $messageType)
6568
{
6669
$this->messageType = $messageType;
6770

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace PubNub\Models\Consumer;
4+
5+
final class PNMessageType
6+
{
7+
private $internal = null;
8+
private $custom = null;
9+
10+
public function __construct($custom)
11+
{
12+
$this->custom = $custom;
13+
}
14+
15+
public static function createWithInternal($custom, $internal)
16+
{
17+
$messageType = new self($custom);
18+
$messageType->setInternal($internal);
19+
return $messageType;
20+
}
21+
22+
private function setInternal($internal)
23+
{
24+
$this->internal = $internal;
25+
return $this;
26+
}
27+
28+
public function getInternal()
29+
{
30+
return $this->internal;
31+
}
32+
33+
public function __toString()
34+
{
35+
return $this->custom;
36+
}
37+
38+
public function getCustom()
39+
{
40+
return $this->custom;
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
<?php
2+
3+
namespace PubNubTests\Features\Context\AccessManager;
4+
5+
use Behat\Behat\Context\Context;
6+
use Behat\Behat\Tester\Exception\PendingException;
7+
use PubNub\PNConfiguration;
8+
use PubNubTests\Features\Context\AccessManager\Traits;
9+
use PubNubTests\Features\Context\PubNubContext;
10+
11+
/**
12+
* Defines application features from the specific context.
13+
*/
14+
class GrantTokenContext extends PubNubContext implements Context
15+
{
16+
use Traits\Given;
17+
use Traits\When;
18+
use Traits\Then;
19+
20+
protected $resource = null;
21+
protected $pattern = null;
22+
protected $token;
23+
24+
/**
25+
* @Given I have a keyset with access manager enabled - without secret key
26+
*/
27+
public function iHaveAKeysetWithAccessManagerEnabledWithoutSecretKey()
28+
{
29+
throw new PendingException();
30+
}
31+
32+
/**
33+
* @Given a valid token with permissions to publish with channel :arg1
34+
*/
35+
public function aValidTokenWithPermissionsToPublishWithChannel($arg1)
36+
{
37+
throw new PendingException();
38+
}
39+
40+
/**
41+
* @When I publish a message using that auth token with channel :arg1
42+
*/
43+
public function iPublishAMessageUsingThatAuthTokenWithChannel($arg1)
44+
{
45+
throw new PendingException();
46+
}
47+
48+
/**
49+
* @Then the result is successful
50+
*/
51+
public function theResultIsSuccessful()
52+
{
53+
throw new PendingException();
54+
}
55+
56+
/**
57+
* @Given an expired token with permissions to publish with channel :arg1
58+
*/
59+
public function anExpiredTokenWithPermissionsToPublishWithChannel($arg1)
60+
{
61+
throw new PendingException();
62+
}
63+
64+
/**
65+
* @When I attempt to publish a message using that auth token with channel :arg1
66+
*/
67+
public function iAttemptToPublishAMessageUsingThatAuthTokenWithChannel($arg1)
68+
{
69+
throw new PendingException();
70+
}
71+
72+
/**
73+
* @Then an auth error is returned
74+
*/
75+
public function anAuthErrorIsReturned()
76+
{
77+
throw new PendingException();
78+
}
79+
80+
/**
81+
* @Then the auth error message is :arg1
82+
*/
83+
public function theAuthErrorMessageIs($arg1)
84+
{
85+
throw new PendingException();
86+
}
87+
88+
/**
89+
* @Given The SDK is configured with an AuthKey representing an access Token
90+
*/
91+
public function theSdkIsConfiguredWithAnAuthkeyRepresentingAnAccessToken()
92+
{
93+
throw new PendingException();
94+
}
95+
96+
/**
97+
* @When I publish a messages
98+
*/
99+
public function iPublishAMessages()
100+
{
101+
throw new PendingException();
102+
}
103+
104+
/**
105+
* @Then The request uses the specified access token for authorization
106+
*/
107+
public function theRequestUsesTheSpecifiedAccessTokenForAuthorization()
108+
{
109+
throw new PendingException();
110+
}
111+
112+
/**
113+
* @Given I have associated an access token with the SDK instance
114+
*/
115+
public function iHaveAssociatedAnAccessTokenWithTheSdkInstance()
116+
{
117+
throw new PendingException();
118+
}
119+
120+
/**
121+
* @When I request the current access token via the getToken operation
122+
*/
123+
public function iRequestTheCurrentAccessTokenViaTheGettokenOperation()
124+
{
125+
throw new PendingException();
126+
}
127+
128+
/**
129+
* @Then The token returned matches
130+
*/
131+
public function theTokenReturnedMatches()
132+
{
133+
throw new PendingException();
134+
}
135+
136+
/**
137+
* @Given I have not associated an access token with the SDK instance
138+
*/
139+
public function iHaveNotAssociatedAnAccessTokenWithTheSdkInstance()
140+
{
141+
throw new PendingException();
142+
}
143+
144+
/**
145+
* @Then A non-error response indicating no token is associated will be returned
146+
*/
147+
public function aNonErrorResponseIndicatingNoTokenIsAssociatedWillBeReturned()
148+
{
149+
throw new PendingException();
150+
}
151+
152+
/**
153+
* @Given I have provided an access token to the SDK via the setToken operation
154+
*/
155+
public function iHaveProvidedAnAccessTokenToTheSdkViaTheSettokenOperation()
156+
{
157+
throw new PendingException();
158+
}
159+
160+
/**
161+
* @Given The SDK is configured with an AuthKey representing an acess Token
162+
*/
163+
public function theSdkIsConfiguredWithAnAuthkeyRepresentingAnAcessToken()
164+
{
165+
throw new PendingException();
166+
}
167+
168+
/**
169+
* @Given I provide an access token to the SDK via the setToken operation
170+
*/
171+
public function iProvideAnAccessTokenToTheSdkViaTheSettokenOperation()
172+
{
173+
throw new PendingException();
174+
}
175+
176+
/**
177+
* @Given I indicated to the SDK to not use a token.
178+
*/
179+
public function iIndicatedToTheSdkToNotUseAToken()
180+
{
181+
throw new PendingException();
182+
}
183+
184+
/**
185+
* @Then The request does not include an access token
186+
*/
187+
public function theRequestDoesNotIncludeAnAccessToken()
188+
{
189+
throw new PendingException();
190+
}
191+
}

tests/features/PubNubFeatures/Access/Given.php tests/features/Context/AccessManager/Traits/Given.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespace PubNubFeatures\Access;
3+
namespace PubNubTests\Features\Context\AccessManager\Traits;
44

55
use PubNub\PubNub;
6-
use PubNubFeatures\PNContextHelper;
6+
use PubNubTests\Features\Context\PNContextHelper;
77

88
trait Given
99
{

0 commit comments

Comments
 (0)