diff --git a/src/PubNub/Endpoints/Push/ListPushProvisions.php b/src/PubNub/Endpoints/Push/ListPushProvisions.php index 1a47fc2d..baccc9c2 100644 --- a/src/PubNub/Endpoints/Push/ListPushProvisions.php +++ b/src/PubNub/Endpoints/Push/ListPushProvisions.php @@ -2,7 +2,7 @@ namespace PubNub\Endpoints\Push; -use PubNub\Enums\PNHttpMethod; +use PubNub\Endpoints\Push\PushEndpoint; use PubNub\Enums\PNOperationType; use PubNub\Enums\PNPushType; use PubNub\Models\Consumer\Push\PNPushListProvisionsResult; diff --git a/src/PubNub/PNConfiguration.php b/src/PubNub/PNConfiguration.php index a24b0544..b50ab548 100755 --- a/src/PubNub/PNConfiguration.php +++ b/src/PubNub/PNConfiguration.php @@ -14,49 +14,65 @@ class PNConfiguration private const DEFAULT_CONNECT_TIMEOUT = 10; private const DEFAULT_USE_RANDOM_IV = true; + private bool $disableImmutableCheck = false; + private bool $isLocked = false; + /** @var string Subscribe key provided by PubNub */ - private $subscribeKey; + private string $subscribeKey; - /** @var string Publish key provided by PubNub */ - private $publishKey; + /** @var string Publish key provided by PubNub (only required if publishing) */ + private ?string $publishKey = null; - /** @var string Secret key provided by PubNub */ - private $secretKey; + /** @var string Secret key provided by PubNub (only required for modifying/revealing access permissions) */ + private ?string $secretKey = null; - /** @var string */ - private $authKey; + /** @var string If Access Manager is utilized, client will use this authKey in all restricted requests. */ + private ?string $authKey = null; - /** @var string */ - private $uuid; + /** + * @var string + * You should set a unique UUID to identify the user or the device that connects to PubNub. + * It's a UTF-8 encoded string of up to 92 alphanumeric characters. + * If you don't set the UUID, you won't be able to connect to PubNub. + */ + private string $userId; - /** @var string */ - private $origin; + /** @var string Custom origin if needed. */ + private ?string $origin = null; /** @var bool Set to true to switch the client to HTTPS:// based communications. */ - private $secure = true; + private bool $secure = true; - /** @var PubNubCryptoCore */ - private $crypto; + /** + * @var CryptoModule + * The cryptography module used for encryption and decryption of messages and files. + * Takes the cipherKey and useRandomIV parameters as arguments. + */ + private ?CryptoModule $crypto = null; - /** @var string */ - private $filterExpression; + /** @var string On non subscribe operations, how long to wait for server response.The value is in seconds. */ + private ?string $filterExpression = null; /** @var int */ - protected $nonSubscribeRequestTimeout; + protected int $nonSubscribeRequestTimeout; - /** @var int */ - protected $connectTimeout; + /** @var int How long to wait before giving up connection to client. The value is in seconds. */ + protected int $connectTimeout; - /** @var int */ - protected $subscribeTimeout; + /** @var int How long to keep the subscribe request running before disconnect. The value is in seconds.*/ + protected int $subscribeTimeout; - /** @var Transport */ - protected $transport; + /** @var Transport Custom transport implementation. */ + protected ?Transport $transport = null; - /** @var bool */ - protected $useRandomIV; + /** + * @var bool + * When true the initialization vector (IV) is random for all requests (not just for file upload). + * When false the IV is hard-coded for all requests except for file upload. + */ + protected bool $useRandomIV; - private $usingUserId = null; + private ?bool $usingUserId = null; /** * PNConfiguration constructor. @@ -74,7 +90,7 @@ public function __construct() * * @return PNConfiguration config */ - public static function demoKeys() + public static function demoKeys(): PNConfiguration { $config = new self(); $config->setSubscribeKey("demo"); @@ -84,12 +100,29 @@ public static function demoKeys() return $config; } + + /** + * Returns a unlocked clone of the current configuration. + * This is useful when you want to create a new configuration based on an existing one. + * + * @return PNConfiguration + */ + public function clone(): PNConfiguration + { + $lockState = $this->isLocked; + $this->isLocked = false; + $result = clone $this; + $this->isLocked = $lockState; + return $result; + } + /** * @param string $subscribeKey * @return $this */ - public function setSubscribeKey($subscribeKey) + public function setSubscribeKey(string $subscribeKey): self { + $this->checkLock(); $this->subscribeKey = $subscribeKey; return $this; @@ -99,8 +132,9 @@ public function setSubscribeKey($subscribeKey) * @param string $publishKey * @return $this */ - public function setPublishKey($publishKey) + public function setPublishKey(string $publishKey): self { + $this->checkLock(); $this->publishKey = $publishKey; return $this; @@ -110,8 +144,9 @@ public function setPublishKey($publishKey) * @param string $secretKey * @return $this */ - public function setSecretKey($secretKey) + public function setSecretKey(string $secretKey): self { + $this->checkLock(); $this->secretKey = $secretKey; return $this; @@ -120,12 +155,12 @@ public function setSecretKey($secretKey) /** * @return string */ - public function getCipherKey() + public function getCipherKey(): string { return $this->getCrypto()->getCipherKey(); } - public function isAesEnabled() + public function isAesEnabled(): bool { return !!$this->crypto; } @@ -134,9 +169,10 @@ public function isAesEnabled() * @param string $cipherKey * @return $this */ - public function setCipherKey($cipherKey) + public function setCipherKey(string $cipherKey): self { - if ($this->crypto == null) { + $this->checkLock(); + if (!isset($this->crypto)) { $this->crypto = CryptoModule::legacyCryptor($cipherKey, $this->getUseRandomIV()); } else { $this->getCrypto()->setCipherKey($cipherKey); @@ -148,7 +184,7 @@ public function setCipherKey($cipherKey) /** * @return int */ - public function getNonSubscribeRequestTimeout() + public function getNonSubscribeRequestTimeout(): int { return $this->nonSubscribeRequestTimeout; } @@ -156,7 +192,7 @@ public function getNonSubscribeRequestTimeout() /** * @return int */ - public function getSubscribeTimeout() + public function getSubscribeTimeout(): int { return $this->subscribeTimeout; } @@ -164,7 +200,7 @@ public function getSubscribeTimeout() /** * @return int */ - public function getConnectTimeout() + public function getConnectTimeout(): int { return $this->connectTimeout; } @@ -172,7 +208,7 @@ public function getConnectTimeout() /** * @return string */ - public function getOrigin() + public function getOrigin(): ?string { return $this->origin; } @@ -181,8 +217,9 @@ public function getOrigin() * @param string $origin * @return $this */ - public function setOrigin($origin) + public function setOrigin($origin): self { + $this->checkLock(); $this->origin = $origin; return $this; @@ -191,15 +228,18 @@ public function setOrigin($origin) /** * @return string */ - public function getSubscribeKey() + public function getSubscribeKey(): string { + if (!isset($this->subscribeKey)) { + throw new PubNubValidationException("Subscribe Key not configured"); + } return $this->subscribeKey; } /** * @return string */ - public function getPublishKey() + public function getPublishKey(): string | null { return $this->publishKey; } @@ -207,7 +247,7 @@ public function getPublishKey() /** * @return string */ - public function getSecretKey() + public function getSecretKey(): string | null { return $this->secretKey; } @@ -215,18 +255,19 @@ public function getSecretKey() /** * @return bool */ - public function isSecure() + public function isSecure(): bool { return $this->secure; } /** - * @param $ssl + * @param $secure * @return $this */ - public function setSecure($ssl) + public function setSecure(bool $secure = true): self { - $this->secure = $ssl; + $this->checkLock(); + $this->secure = $secure; return $this; } @@ -234,25 +275,28 @@ public function setSecure($ssl) /** * @return string */ - public function getUuid() + public function getUuid(): string { - return $this->uuid; + if (!isset($this->userId)) { + throw new PubNubConfigurationException('UUID should not be empty'); + } + return $this->userId; } /** * @param string $uuid * @return $this */ - public function setUuid($uuid) + public function setUuid(string $uuid): self { if (!is_null($this->usingUserId) && $this->usingUserId) { throw new PubNubConfigurationException("Cannot use UserId and UUID simultaneously"); } - if (!$this->validateNotEmptyString($uuid)) { + if (!$this->isNotEmptyString($uuid)) { throw new PubNubConfigurationException("UUID should not be empty"); } $this->usingUserId = false; - $this->uuid = $uuid; + $this->userId = $uuid; return $this; } @@ -260,25 +304,29 @@ public function setUuid($uuid) /** * @return string */ - public function getUserId() + public function getUserId(): string { - return $this->uuid; + if (!isset($this->userId)) { + throw new PubNubConfigurationException('UUID should not be empty'); + } + return $this->userId; } /** * @param string $userId * @return $this */ - public function setUserId($userId) + public function setUserId(string $userId): self { + $this->checkLock(); if (!is_null($this->usingUserId) && !$this->usingUserId) { throw new PubNubConfigurationException("Cannot use UserId and UUID simultaneously"); } - if (!$this->validateNotEmptyString($userId)) { + if (!$this->isNotEmptyString($userId)) { throw new PubNubConfigurationException("UserID should not be empty"); } $this->usingUserId = true; - $this->uuid = $userId; + $this->userId = $userId; return $this; } @@ -286,7 +334,7 @@ public function setUserId($userId) /** * @return string|null authKey */ - public function getAuthKey() + public function getAuthKey(): ?string { return $this->authKey; } @@ -295,7 +343,7 @@ public function getAuthKey() * @param string|null $authKey * @return $this */ - public function setAuthKey($authKey) + public function setAuthKey(string $authKey): self { $this->authKey = $authKey; @@ -303,10 +351,10 @@ public function setAuthKey($authKey) } /** - * @return PubNubCryptoCore + * @return CryptoModule * @throws \Exception */ - public function getCrypto() + public function getCrypto(): CryptoModule { if (!$this->crypto) { throw new PubNubValidationException("You should set up either a cipher key or a crypto instance before"); @@ -316,9 +364,9 @@ public function getCrypto() } /** - * @return null|PubNubCryptoCore + * @return null | CryptoModule */ - public function getCryptoSafe() + public function getCryptoSafe(): CryptoModule | null { try { return $this->getCrypto(); @@ -331,8 +379,9 @@ public function getCryptoSafe() * @param PubNubCryptoCore $crypto * @return $this */ - public function setCrypto($crypto) + public function setCrypto(PubNubCryptoCore $crypto): self { + $this->checkLock(); $this->crypto = $crypto; return $this; @@ -341,7 +390,7 @@ public function setCrypto($crypto) /** * @return string */ - public function getFilterExpression() + public function getFilterExpression(): string | null { return $this->filterExpression; } @@ -350,8 +399,9 @@ public function getFilterExpression() * @param string $filterExpression * @return $this */ - public function setFilterExpression($filterExpression) + public function setFilterExpression(string $filterExpression): self { + $this->checkLock(); $this->filterExpression = $filterExpression; return $this; @@ -361,8 +411,9 @@ public function setFilterExpression($filterExpression) * @param int $nonSubscribeRequestTimeout * @return $this */ - public function setNonSubscribeRequestTimeout($nonSubscribeRequestTimeout) + public function setNonSubscribeRequestTimeout(int $nonSubscribeRequestTimeout): self { + $this->checkLock(); $this->nonSubscribeRequestTimeout = $nonSubscribeRequestTimeout; return $this; @@ -372,8 +423,9 @@ public function setNonSubscribeRequestTimeout($nonSubscribeRequestTimeout) * @param int $connectTimeout * @return $this */ - public function setConnectTimeout($connectTimeout) + public function setConnectTimeout(int $connectTimeout): self { + $this->checkLock(); $this->connectTimeout = $connectTimeout; return $this; @@ -383,8 +435,9 @@ public function setConnectTimeout($connectTimeout) * @param int $subscribeTimeout * @return $this */ - public function setSubscribeTimeout($subscribeTimeout) + public function setSubscribeTimeout(int $subscribeTimeout): self { + $this->checkLock(); $this->subscribeTimeout = $subscribeTimeout; return $this; @@ -393,7 +446,7 @@ public function setSubscribeTimeout($subscribeTimeout) /** * @return Transport */ - public function getTransport() + public function getTransport(): Transport | null { return $this->transport; } @@ -404,6 +457,7 @@ public function getTransport() */ public function setTransport($transport) { + $this->checkLock(); $this->transport = $transport; return $this; @@ -412,7 +466,7 @@ public function setTransport($transport) /** * @return bool */ - public function getUseRandomIV() + public function getUseRandomIV(): bool { return $this->useRandomIV; } @@ -421,8 +475,9 @@ public function getUseRandomIV() * @param bool $useRandomIV * @return $this */ - public function setUseRandomIV($useRandomIV) + public function setUseRandomIV($useRandomIV): self { + $this->checkLock(); $this->useRandomIV = $useRandomIV; if ($this->crypto != null) { @@ -432,8 +487,27 @@ public function setUseRandomIV($useRandomIV) return $this; } - private function validateNotEmptyString($value) + private function isNotEmptyString($value): bool { return (is_string($value) && strlen(trim($value)) > 0); } + + public function disableImmutableCheck(): self + { + $this->checkLock(); + $this->disableImmutableCheck = true; + return $this; + } + + public function lock() + { + $this->isLocked = true; + } + + protected function checkLock() + { + if ($this->isLocked && !$this->disableImmutableCheck) { + throw new PubNubConfigurationException("This configuration is locked and cannot be changed anymore."); + } + } } diff --git a/src/PubNub/PubNub.php b/src/PubNub/PubNub.php index 2bdf12b2..1e95eabc 100644 --- a/src/PubNub/PubNub.php +++ b/src/PubNub/PubNub.php @@ -92,6 +92,7 @@ class PubNub implements LoggerAwareInterface public function __construct($initialConfig) { $this->validateConfig($initialConfig); + $initialConfig->lock(); $this->configuration = $initialConfig; $this->basePathManager = new BasePathManager($initialConfig); $this->subscriptionManager = new SubscriptionManager($this); diff --git a/tests/functional/EndpointTest.php b/tests/functional/EndpointTest.php index d99c07a6..4ae186f6 100644 --- a/tests/functional/EndpointTest.php +++ b/tests/functional/EndpointTest.php @@ -4,12 +4,10 @@ use PHPUnit\Framework\TestCase; use PubNub\Endpoints\Endpoint; -use PubNub\Exceptions\PubNubConfigurationException; use PubNub\Exceptions\PubNubValidationException; use PubNub\PNConfiguration; use PubNub\PubNub; - class EndpointTest extends TestCase { protected static $channel = 'pubnub_php_test'; @@ -67,10 +65,9 @@ public function testValidatesPublishKeyEmptyString() } } - +//phpcs:ignore PSR1.Classes.ClassDeclaration class EndpointImplementation extends Endpoint { - public function validateSubscribeKey() { parent::validateSubscribeKey(); @@ -153,4 +150,4 @@ protected function getName() { // TODO: Implement getName() method. } -} \ No newline at end of file +} diff --git a/tests/functional/PublishTest.php b/tests/functional/PublishTest.php index ec5b1fcc..8601bc91 100644 --- a/tests/functional/PublishTest.php +++ b/tests/functional/PublishTest.php @@ -10,7 +10,6 @@ use PubNub\PubNubUtil; use ReflectionMethod; - class PublishTest extends \PubNubTestCase { protected static $channel = 'pubnub_php_test'; @@ -47,8 +46,10 @@ public function testNonSerializable() $this->pubnub->publish()->message(["key" => "\xB1\x31"])->channel('ch')->sync(); $this->fail("No exception was thrown"); } catch (PubNubBuildRequestException $exception) { - $this->assertEquals("Value serialization error: Malformed UTF-8 characters, possibly incorrectly encoded", - $exception->getMessage()); + $this->assertEquals( + "Value serialization error: Malformed UTF-8 characters, possibly incorrectly encoded", + $exception->getMessage() + ); } } @@ -107,7 +108,7 @@ public function testPublishGet() $this->assertGeneratesCorrectPathUsingGet('hey', 'ch', 3); $this->assertGeneratesCorrectPathUsingGet(42.345, 34.534, 5); $this->assertGeneratesCorrectPathUsingGet(true, false, 7); - $this->assertGeneratesCorrectPathUsingGet(['hey'], 'ch',9); + $this->assertGeneratesCorrectPathUsingGet(['hey'], 'ch', 9); } public function testPublishPost() @@ -285,20 +286,22 @@ public function testPublishWithCipher() $channel = 'ch'; $message = ['hi', 'hi2', 'hi3']; - $this->pubnub->getConfiguration()->setUseRandomIV(false); - $this->pubnub->getConfiguration()->setCipherKey("testCipher"); + $config = $this->config->clone(); + $config->setUseRandomIV(false); + $config->setCipherKey("testCipher"); + $pubnub = new PubNub($config); $r = new ReflectionMethod('\PubNub\Endpoints\PubSub\Publish', 'buildPath'); $r->setAccessible(true); - $publish = $this->pubnub->publish(); + $publish = $pubnub->publish(); $publish->channel($channel); $publish->message($message); $this->assertEquals( sprintf( "/publish/%s/%s/0/%s/0/%s", - $this->pubnub->getConfiguration()->getPublishKey(), - $this->pubnub->getConfiguration()->getSubscribeKey(), + $pubnub->getConfiguration()->getPublishKey(), + $pubnub->getConfiguration()->getSubscribeKey(), $channel, // NOTICE: php doesn't add spaces to stringified object, // so encoded string not equal ones in python or javascript diff --git a/tests/functional/UuidTest.php b/tests/functional/UuidTest.php index bd40b07e..8deeec35 100644 --- a/tests/functional/UuidTest.php +++ b/tests/functional/UuidTest.php @@ -12,8 +12,7 @@ class UuidTest extends PubNubTestCase { public function testValidateOnSet() { - $this->expectException(PubNubConfigurationException::class); - $this->expectExceptionMessage("UUID should not be empty"); + $this->expectException(\TypeError::class); $config = new PNConfiguration(); $config->setPublishKey('fake') ->setSubscribeKey('fake') diff --git a/tests/integrational/AddChannelChannelGroupEndpointTest.php b/tests/integrational/AddChannelChannelGroupEndpointTest.php index 96c531d9..b100f4e2 100644 --- a/tests/integrational/AddChannelChannelGroupEndpointTest.php +++ b/tests/integrational/AddChannelChannelGroupEndpointTest.php @@ -9,7 +9,6 @@ use PubNubTestCase; use Tests\Helpers\StubTransport; - class AddChannelChannelGroupEndpointTest extends PubNubTestCase { public function testSuccess() @@ -22,7 +21,7 @@ public function testSuccess() "uuid" => "myUUID", "add" => "c%7Ch1,ch2s" ]) - ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {} , \"service\": \"ChannelGroups\"}"); + ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {},\"service\":\"ChannelGroups\"}"); $this->pubnub->getConfiguration()->setUuid("myUUID"); @@ -44,7 +43,7 @@ public function testGroupMissing() "uuid" => "myUUID", "add" => "c%7Ch1,ch2s" ]) - ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {} , \"service\": \"ChannelGroups\"}"); + ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {},\"service\":\"ChannelGroups\"}"); $this->pubnub->getConfiguration()->setUuid("myUUID"); @@ -64,7 +63,7 @@ public function testGroupIsEmpty() "uuid" => "myUUID", "add" => "c%7Ch1,ch2s" ]) - ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {} , \"service\": \"ChannelGroups\"}"); + ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {},\"service\":\"ChannelGroups\"}"); $this->pubnub->getConfiguration()->setUuid("myUUID"); @@ -83,7 +82,7 @@ public function testChannelMissing() "pnsdk" => $this->encodedSdkName, "uuid" => "myUUID" ]) - ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {} , \"service\": \"ChannelGroups\"}"); + ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {},\"service\":\"ChannelGroups\"}"); $this->pubnub->getConfiguration()->setUuid("myUUID"); @@ -92,6 +91,7 @@ public function testChannelMissing() public function testIsAuthRequiredSuccess() { + $this->expectNotToPerformAssertions(); $addChannelChannelGroup = new AddChannelChannelGroupExposed($this->pubnub); $addChannelChannelGroup->stubFor("/v1/channel-registration/sub-key/demo/channel-group/groupA") @@ -101,7 +101,7 @@ public function testIsAuthRequiredSuccess() "auth" => "myKey", "add" => "ch1,ch2" ]) - ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {} , \"service\": \"ChannelGroups\"}"); + ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {},\"service\":\"ChannelGroups\"}"); $this->pubnub->getConfiguration()->setUuid("myUUID")->setAuthKey("myKey"); @@ -123,7 +123,7 @@ public function testErrorBodyForbidden() "add" => "ch1,ch2" ]) ->setResponseStatus("HTTP/1.0 403 Forbidden") - ->setResponseBody("{\"status\": 403, \"message\": \"OK\", \"payload\": {} , \"service\": \"ChannelGroups\"}"); + ->setResponseBody("{\"status\": 403, \"message\": \"OK\", \"payload\": {},\"service\":\"ChannelGroups\"}"); $this->pubnub->getConfiguration()->setUuid("myUUID")->setAuthKey("myKey"); @@ -148,7 +148,7 @@ public function testSuperCallTest() } } - +// phpcs:ignore PSR1.Classes.ClassDeclaration class AddChannelChannelGroupExposed extends AddChannelToChannelGroup { protected $transport; diff --git a/tests/integrational/GetStateTest.php b/tests/integrational/GetStateTest.php index b6173dcb..e0fb3cb1 100644 --- a/tests/integrational/GetStateTest.php +++ b/tests/integrational/GetStateTest.php @@ -8,10 +8,8 @@ use PubNub\PubNub; use PubNub\PubNubUtil; use PubNubTestCase; -use Tests\Helpers\Stub; use Tests\Helpers\StubTransport; - class GetStateTest extends PubNubTestCase { public function testOneChannel() @@ -23,7 +21,8 @@ public function testOneChannel() "uuid" => "sampleUUID", "pnsdk" => $this->encodedSdkName ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\"}, \"service\": \"Presence\"}"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", " + . " \"payload\": { \"age\" : 20, \"status\" : \"online\"}, \"service\": \"Presence\"}"); $this->pubnub->getConfiguration()->setUuid("sampleUUID"); @@ -42,7 +41,8 @@ public function testOneChannelWithoutUUID() "pnsdk" => $this->encodedSdkName, "uuid" => "myUUID" ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\"}, \"service\": \"Presence\"}"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", " + . "\"payload\": { \"age\" : 20, \"status\" : \"online\"}, \"service\": \"Presence\"}"); $this->pubnub->getConfiguration()->setUuid("myUUID"); @@ -62,7 +62,8 @@ public function testFailedPayload() ->withQuery([ "uuid" => "sampleUUID", ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\"}, \"service\": \"Presence\"}"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", " + . "\"payload\": { \"age\" : 20, \"status\" : \"online\"}, \"service\": \"Presence\"}"); $this->pubnub->getConfiguration()->setUuid("sampleUUID"); @@ -78,7 +79,9 @@ public function testMultipleChannel() "uuid" => "sampleUUID", "pnsdk" => $this->encodedSdkName ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"channels\": { \"ch1\": { \"age\" : 20, \"status\" : \"online\"}, \"ch2\": { \"age\": 100, \"status\": \"offline\" } } }, \"service\": \"Presence\"}"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", " + . "\"payload\": { \"channels\": { \"ch1\": { \"age\" : 20, \"status\" : \"online\"}, " + . "\"ch2\": { \"age\": 100, \"status\": \"offline\" } } }, \"service\": \"Presence\"}"); $this->pubnub->getConfiguration()->setUuid("sampleUUID"); @@ -101,7 +104,9 @@ public function testOneChannelGroup() "pnsdk" => $this->encodedSdkName, "channel-group" => "cg1" ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"channels\": { \"chcg1\": { \"age\" : 20, \"status\" : \"online\"}, \"chcg2\": { \"age\": 100, \"status\": \"offline\" } } }, \"service\": \"Presence\"}"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", " + . "\"payload\": { \"channels\": { \"chcg1\": { \"age\" : 20, \"status\" : \"online\"}, " + . "\"chcg2\": { \"age\": 100, \"status\": \"offline\" } } }, \"service\": \"Presence\"}"); $this->pubnub->getConfiguration()->setUuid("sampleUUID"); @@ -124,7 +129,9 @@ public function testManyChannelGroup() "pnsdk" => $this->encodedSdkName, "channel-group" => PubNubUtil::urlEncode("cg1,cg2") ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"channels\": { \"chcg1\": { \"age\" : 20, \"status\" : \"online\"}, \"chcg2\": { \"age\": 100, \"status\": \"offline\" } } }, \"service\": \"Presence\"}"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", " + . "\"payload\": { \"channels\": { \"chcg1\": { \"age\" : 20, \"status\" : \"online\"}, " + . "\"chcg2\": { \"age\": 100, \"status\": \"offline\" } } }, \"service\": \"Presence\"}"); $this->pubnub->getConfiguration()->setUuid("sampleUUID"); @@ -147,7 +154,9 @@ public function testCombination() "pnsdk" => $this->encodedSdkName, "channel-group" => PubNubUtil::urlEncode("cg1,cg2") ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"channels\": { \"chcg1\": { \"age\" : 20, \"status\" : \"online\"}, \"chcg2\": { \"age\": 100, \"status\": \"offline\" } } }, \"service\": \"Presence\"}"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", " + . "\"payload\": { \"channels\": { \"chcg1\": { \"age\" : 20, \"status\" : \"online\"}, " + . "\"chcg2\": { \"age\": 100, \"status\": \"offline\" } } }, \"service\": \"Presence\"}"); $this->pubnub->getConfiguration()->setUuid("sampleUUID"); @@ -172,7 +181,8 @@ public function testMissingChannelAndGroup() "uuid" => "sampleUUID", "pnsdk" => $this->encodedSdkName ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\"}, \"service\": \"Presence\"}"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", " + . "\"payload\": { \"age\" : 20, \"status\" : \"online\"}, \"service\": \"Presence\"}"); $this->pubnub->getConfiguration()->setUuid("sampleUUID"); @@ -181,7 +191,13 @@ public function testMissingChannelAndGroup() public function testIsAuthRequiredSuccess() { - $getState = new GetStateExposed($this->pubnub); + $this->expectNotToPerformAssertions(); + $config = $this->config->clone(); + $config->setAuthKey("myKey"); + $config->setUuid("sampleUUID"); + + $pubnub = new PubNub($config); + $getState = new GetStateExposed($pubnub); $getState->stubFor("/v2/presence/sub-key/demo/channel/testChannel/uuid/sampleUUID") ->withQuery([ @@ -189,56 +205,60 @@ public function testIsAuthRequiredSuccess() "pnsdk" => $this->encodedSdkName, "auth" => "myKey" ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\"}, \"service\": \"Presence\"}"); - - $this->pubnub->getConfiguration()->setAuthKey("myKey"); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", " + . "\"payload\": { \"age\" : 20, \"status\" : \"online\"}, \"service\": \"Presence\"}"); $getState->channels("testChannel")->sync(); } public function testNullSubKey() { - $this->expectException(PubNubException::class); - $this->expectExceptionMessage("Subscribe Key not configured"); + $this->expectException(\TypeError::class); - $getState = new GetStateExposed($this->pubnub); + $config = $this->config->clone(); + $config ->setSubscribeKey(null); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); + $getState = new GetStateExposed($pubnub); $getState->stubFor("/v2/presence/sub-key/demo/channel/testChannel/uuid/sampleUUID") ->withQuery([ "uuid" => "sampleUUID", "pnsdk" => $this->encodedSdkName ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\"}, \"service\": \"Presence\"}"); - - $this->pubnub->getConfiguration()->setSubscribeKey(null); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", " + . "\"payload\": { \"age\" : 20, \"status\" : \"online\"}, \"service\": \"Presence\"}"); $getState->channels("testChannel")->sync(); } public function testEmptySubKeySync() { + + $this->expectException(PubNubException::class); $this->expectExceptionMessage("Subscribe Key not configured"); - $getState = new GetStateExposed($this->pubnub); + $config = $this->config->clone(); + $config ->setSubscribeKey(""); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); + $getState = new GetStateExposed($pubnub); $getState->stubFor("/v2/presence/sub-key/demo/channel/testChannel/uuid/sampleUUID") ->withQuery([ "uuid" => "sampleUUID", "pnsdk" => $this->encodedSdkName ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\"}, \"service\": \"Presence\"}"); - - $this->pubnub->getConfiguration()->setSubscribeKey(""); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", " + . "\"payload\": { \"age\" : 20, \"status\" : \"online\"}, \"service\": \"Presence\"}"); $getState->channels("testChannel")->sync(); } public function testSuperCall() { + $this->expectNotToPerformAssertions(); // Not valid // ,~/ $characters = "-._:?#[]@!$&'()*+;=`|"; @@ -249,7 +269,7 @@ public function testSuperCall() } } - +//phpcs:ignore PSR1.Classes.ClassDeclaration class GetStateExposed extends GetState { protected $transport; diff --git a/tests/integrational/HereNowTest.php b/tests/integrational/HereNowTest.php index 198ba904..30a96793 100644 --- a/tests/integrational/HereNowTest.php +++ b/tests/integrational/HereNowTest.php @@ -5,11 +5,9 @@ use Countable; use PubNub\Endpoints\Presence\HereNow; use PubNub\Exceptions\PubNubValidationException; -use RawTransport; use Tests\Helpers\Stub; use Tests\Helpers\StubTransport; - class HereNowTest extends \PubNubTestCase { /** @@ -25,7 +23,9 @@ public function testMultipleChannelState() 'pnsdk' => $this->encodedSdkName, 'uuid' => Stub::ANY ]) - ->setResponseBody("{\"status\":200,\"message\":\"OK\",\"payload\":{\"total_occupancy\":3,\"total_channels\":2,\"channels\":{\"ch1\":{\"occupancy\":1,\"uuids\":[{\"uuid\":\"user1\"}]},\"ch2\":{\"occupancy\":2,\"uuids\":[{\"uuid\":\"user1\"},{\"uuid\":\"user3\"}]}}},\"service\":\"Presence\"}"); + ->setResponseBody("{\"status\":200,\"message\":\"OK\",\"payload\":{\"total_occupancy\":3,\"total_channels\"" + . ":2,\"channels\":{\"ch1\":{\"occupancy\":1,\"uuids\":[{\"uuid\":\"user1\"}]},\"ch2\":{\"occupancy\":2" + . ",\"uuids\":[{\"uuid\":\"user1\"},{\"uuid\":\"user3\"}]}}},\"service\":\"Presence\"}"); $response = $hereNow->channels(["ch1", "ch2"])->includeState(true)->sync(); @@ -60,7 +60,9 @@ public function testMultipleChannel() 'pnsdk' => $this->encodedSdkName, 'uuid' => Stub::ANY ]) - ->setResponseBody("{\"status\":200,\"message\":\"OK\",\"payload\":{\"total_occupancy\":3,\"total_channels\":2,\"channels\":{\"ch1\":{\"occupancy\":1,\"uuids\":[{\"uuid\":\"user1\"}]},\"ch2\":{\"occupancy\":2,\"uuids\":[{\"uuid\":\"user1\"},{\"uuid\":\"user3\"}]}}},\"service\":\"Presence\"}"); + ->setResponseBody("{\"status\":200,\"message\":\"OK\",\"payload\":{\"total_occupancy\":3,\"total_channels\"" + . ":2,\"channels\":{\"ch1\":{\"occupancy\":1,\"uuids\":[{\"uuid\":\"user1\"}]},\"ch2\":{\"occupancy\":2" + . ",\"uuids\":[{\"uuid\":\"user1\"},{\"uuid\":\"user3\"}]}}},\"service\":\"Presence\"}"); $response = $hereNow->channels(["ch1", "ch2"])->includeState(true)->sync(); @@ -94,7 +96,9 @@ public function testMultipleChannelWithoutState() 'pnsdk' => $this->encodedSdkName, 'uuid' => Stub::ANY ]) - ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {\"channels\": {\"game1\": {\"uuids\": [\"a3ffd012-a3b9-478c-8705-64089f24d71e\"], \"occupancy\": 1}}, \"total_channels\": 1, \"total_occupancy\": 1}, \"service\": \"Presence\"}"); + ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {\"channels\": {\"game1\": {\"uuids" + . "\": [\"a3ffd012-a3b9-478c-8705-64089f24d71e\"], \"occupancy\": 1}}, \"total_channels\": 1, \"total_o" + . "ccupancy\": 1}, \"service\": \"Presence\"}"); $response = $hereNow->channels(["game1", "game2"])->includeState(false)->sync(); @@ -104,7 +108,10 @@ public function testMultipleChannelWithoutState() $this->assertEquals($response->getChannels()[0]->getChannelName(), "game1"); $this->assertEquals($response->getChannels()[0]->getOccupancy(), 1); $this->assertEquals(count($response->getChannels()[0]->getOccupants()), 1); - $this->assertEquals($response->getChannels()[0]->getOccupants()[0]->getUuid(), "a3ffd012-a3b9-478c-8705-64089f24d71e"); + $this->assertEquals( + $response->getChannels()[0]->getOccupants()[0]->getUuid(), + "a3ffd012-a3b9-478c-8705-64089f24d71e" + ); $this->assertEquals($response->getChannels()[0]->getOccupants()[0]->getState(), null); } @@ -121,7 +128,8 @@ public function testMultipleChannelWithoutStateUUIDs() 'uuid' => Stub::ANY, 'pnsdk' => $this->encodedSdkName ]) - ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {\"channels\": {\"game1\": {\"occupancy\": 1}}, \"total_channels\": 1, \"total_occupancy\": 1}, \"service\": \"Presence\"}"); + ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {\"channels\": {\"game1\": {\"occupa" + . "ncy\": 1}}, \"total_channels\": 1, \"total_occupancy\": 1}, \"service\": \"Presence\"}"); $response = $hereNow->channels(["game1", "game2"])->includeUuids(false)->includeState(false)->sync(); @@ -130,7 +138,7 @@ public function testMultipleChannelWithoutStateUUIDs() $this->assertEquals($response->getChannels()[0]->getChannelName(), "game1"); $this->assertEquals($response->getChannels()[0]->getOccupancy(), 1); - $this->assertEquals(is_array($response->getChannels()[0]->getOccupants()) , false); + $this->assertEquals(is_array($response->getChannels()[0]->getOccupants()), false); } /** @@ -166,7 +174,8 @@ public function testSingularChannelWithoutState() 'uuid' => Stub::ANY, 'pnsdk' => $this->encodedSdkName ]) - ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"service\": \"Presence\", \"uuids\": [\"a3ffd012-a3b9-478c-8705-64089f24d71e\"], \"occupancy\": 1}"); + ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"service\": \"Presence\", \"uuids\": [\"a3ffd012" + . "-a3b9-478c-8705-64089f24d71e\"], \"occupancy\": 1}"); $response = $hereNow->channels("game1")->includeState(false)->sync(); @@ -175,7 +184,10 @@ public function testSingularChannelWithoutState() $this->assertEquals(count($response->getChannels()), 1); $this->assertEquals($response->getChannels()[0]->getOccupancy(), 1); $this->assertEquals(count($response->getChannels()[0]->getOccupants()), 1); - $this->assertEquals($response->getChannels()[0]->getOccupants()[0]->getUuid(), "a3ffd012-a3b9-478c-8705-64089f24d71e"); + $this->assertEquals( + $response->getChannels()[0]->getOccupants()[0]->getUuid(), + "a3ffd012-a3b9-478c-8705-64089f24d71e" + ); $this->assertEquals($response->getChannels()[0]->getOccupants()[0]->getState(), null); } @@ -192,7 +204,8 @@ public function testSingularChannel() 'uuid' => Stub::ANY, 'pnsdk' => $this->encodedSdkName ]) - ->setResponseBody("{\"status\":200,\"message\":\"OK\",\"service\":\"Presence\",\"uuids\":[{\"uuid\":\"a3ffd012-a3b9-478c-8705-64089f24d71e\",\"state\":{\"age\":10}}],\"occupancy\":1}"); + ->setResponseBody("{\"status\":200,\"message\":\"OK\",\"service\":\"Presence\",\"uuids\":[{\"uuid\":\"a3ffd" + . "012-a3b9-478c-8705-64089f24d71e\",\"state\":{\"age\":10}}],\"occupancy\":1}"); $response = $hereNow->channels("game1")->includeState(true)->sync(); @@ -201,7 +214,10 @@ public function testSingularChannel() $this->assertEquals(count($response->getChannels()), 1); $this->assertEquals($response->getChannels()[0]->getOccupancy(), 1); $this->assertEquals(count($response->getChannels()[0]->getOccupants()), 1); - $this->assertEquals($response->getChannels()[0]->getOccupants()[0]->getUuid(), "a3ffd012-a3b9-478c-8705-64089f24d71e"); + $this->assertEquals( + $response->getChannels()[0]->getOccupants()[0]->getUuid(), + "a3ffd012-a3b9-478c-8705-64089f24d71e" + ); $this->assertEquals($response->getChannels()[0]->getOccupants()[0]->getState(), ["age" => 10]); } @@ -219,7 +235,8 @@ public function testSingularChannelAndGroup() 'uuid' => Stub::ANY, 'pnsdk' => $this->encodedSdkName ]) - ->setResponseBody("{\"status\":200,\"message\":\"OK\",\"payload\":{\"channels\":{}, \"total_channels\":0, \"total_occupancy\":0},\"service\":\"Presence\"}"); + ->setResponseBody("{\"status\":200,\"message\":\"OK\",\"payload\":{\"channels\":{}, \"total_channels\":0, " + . "\"total_occupancy\":0},\"service\":\"Presence\"}"); $response = $hereNow->channelGroups("grp1")->channels("game1")->includeState(true)->sync(); @@ -232,6 +249,7 @@ public function testSingularChannelAndGroup() */ public function testIsAuthRequiredSuccess() { + $this->expectNotToPerformAssertions(); $hereNow = new HereNowExposed($this->pubnub); $hereNow->stubFor("/v2/presence/sub-key/demo/channel/ch1,ch2") ->withQuery([ @@ -240,7 +258,10 @@ public function testIsAuthRequiredSuccess() 'uuid' => Stub::ANY, 'auth' => 'myKey' ]) - ->setResponseBody("{\"status\":200,\"message\":\"OK\",\"payload\":{\"total_occupancy\":3,\"total_channels\":2,\"channels\":{\"ch1\":{\"occupancy\":1,\"uuids\":[{\"uuid\":\"user1\",\"state\":{\"age\":10}}]},\"ch2\":{\"occupancy\":2,\"uuids\":[{\"uuid\":\"user1\",\"state\":{\"age\":10}},{\"uuid\":\"user3\",\"state\":{\"age\":30}}]}}},\"service\":\"Presence\"}"); + ->setResponseBody("{\"status\":200,\"message\":\"OK\",\"payload\":{\"total_occupancy\":3,\"total_channels" + . "\":2,\"channels\":{\"ch1\":{\"occupancy\":1,\"uuids\":[{\"uuid\":\"user1\",\"state\":{\"age\":10}}]}" + . ",\"ch2\":{\"occupancy\":2,\"uuids\":[{\"uuid\":\"user1\",\"state\":{\"age\":10}},{\"uuid\":\"user3" + . "\",\"state\":{\"age\":30}}]}}},\"service\":\"Presence\"}"); $this->pubnub->getConfiguration()->setAuthKey("myKey"); @@ -253,10 +274,12 @@ public function testIsAuthRequiredSuccess() */ public function testNullSubKey() { - $this->expectException(PubNubValidationException::class); - $this->expectExceptionMessage("Subscribe Key not configured"); + $this->expectException(\TypeError::class); + $config = $this->config->clone(); + $config->setSubscribeKey(null); - $hereNow = new HereNowExposed($this->pubnub); + $pubnub = new \PubNub\PubNub($config); + $hereNow = new HereNowExposed($pubnub); $hereNow->stubFor("/v2/presence/sub-key/demo/channel/ch1,ch2") ->withQuery([ 'channel-group' => 'grp1', @@ -264,9 +287,10 @@ public function testNullSubKey() 'uuid' => Stub::ANY, 'pnsdk' => $this->encodedSdkName ]) - ->setResponseBody("{\"status\":200,\"message\":\"OK\",\"payload\":{\"total_occupancy\":3,\"total_channels\":2,\"channels\":{\"ch1\":{\"occupancy\":1,\"uuids\":[{\"uuid\":\"user1\",\"state\":{\"age\":10}}]},\"ch2\":{\"occupancy\":2,\"uuids\":[{\"uuid\":\"user1\",\"state\":{\"age\":10}},{\"uuid\":\"user3\",\"state\":{\"age\":30}}]}}},\"service\":\"Presence\"}"); - - $this->pubnub->getConfiguration()->setSubscribeKey(null); + ->setResponseBody("{\"status\":200,\"message\":\"OK\",\"payload\":{\"total_occupancy\":3,\"total_channels" + . "\":2,\"channels\":{\"ch1\":{\"occupancy\":1,\"uuids\":[{\"uuid\":\"user1\",\"state\":{\"age\":10}}]}" + . ",\"ch2\":{\"occupancy\":2,\"uuids\":[{\"uuid\":\"user1\",\"state\":{\"age\":10}},{\"uuid\":\"user3" + . "\",\"state\":{\"age\":30}}]}}},\"service\":\"Presence\"}"); $hereNow->channels(["ch1", "ch2"])->includeState(true)->sync(); } @@ -279,8 +303,11 @@ public function testEmptySubKey() { $this->expectException(PubNubValidationException::class); $this->expectExceptionMessage("Subscribe Key not configured"); + $config = $this->config->clone(); + $config->setSubscribeKey(""); - $hereNow = new HereNowExposed($this->pubnub); + $pubnub = new \PubNub\PubNub($config); + $hereNow = new HereNowExposed($pubnub); $hereNow->stubFor("/v2/presence/sub-key/demo/channel/ch1,ch2") ->withQuery([ 'state' => '1', @@ -288,15 +315,17 @@ public function testEmptySubKey() 'uuid' => Stub::ANY, 'auth' => 'myKey' ]) - ->setResponseBody("{\"status\":200,\"message\":\"OK\",\"payload\":{\"total_occupancy\":3,\"total_channels\":2,\"channels\":{\"ch1\":{\"occupancy\":1,\"uuids\":[{\"uuid\":\"user1\",\"state\":{\"age\":10}}]},\"ch2\":{\"occupancy\":2,\"uuids\":[{\"uuid\":\"user1\",\"state\":{\"age\":10}},{\"uuid\":\"user3\",\"state\":{\"age\":30}}]}}},\"service\":\"Presence\"}"); - - $this->pubnub->getConfiguration()->setSubscribeKey(""); + ->setResponseBody("{\"status\":200,\"message\":\"OK\",\"payload\":{\"total_occupancy\":3,\"total_channels" + . "\":2,\"channels\":{\"ch1\":{\"occupancy\":1,\"uuids\":[{\"uuid\":\"user1\",\"state\":{\"age\":10}}]}" + . ",\"ch2\":{\"occupancy\":2,\"uuids\":[{\"uuid\":\"user1\",\"state\":{\"age\":10}},{\"uuid\":\"user3\"" + . ",\"state\":{\"age\":30}}]}}},\"service\":\"Presence\"}"); $hereNow->channels(["ch1", "ch2"])->includeState(true)->sync(); } public function testSuperCallTest() { + $this->expectNotToPerformAssertions(); // Not valid // ,~/ $characters = "-._:?#[]@!$&'()*+;=`|"; @@ -307,7 +336,7 @@ public function testSuperCallTest() } } - +// phpcs:ignore PSR1.Classes.ClassDeclaration class HereNowExposed extends HereNow { protected $transport; diff --git a/tests/integrational/HistoryDeleteTest.php b/tests/integrational/HistoryDeleteTest.php index df9c52f0..7f1b3d23 100644 --- a/tests/integrational/HistoryDeleteTest.php +++ b/tests/integrational/HistoryDeleteTest.php @@ -9,7 +9,6 @@ use Tests\Helpers\Stub; use Tests\Helpers\StubTransport; - class TestPubNubHistoryDelete extends \PubNubTestCase { public function testMissingChannelException() @@ -51,12 +50,14 @@ public function testChannelIsEmptyException() public function testSuperCallTest() { + $this->expectNotToPerformAssertions(); $this->pubnub_pam->deleteMessages() ->channel(static::SPECIAL_CHARACTERS) ->sync(); } } +// phpcs:ignore PSR1.Classes.ClassDeclaration class HistoryDeleteExposed extends HistoryDelete { protected $transport; diff --git a/tests/integrational/HistoryTest.php b/tests/integrational/HistoryTest.php index d7a10fdf..65cdec57 100644 --- a/tests/integrational/HistoryTest.php +++ b/tests/integrational/HistoryTest.php @@ -11,12 +11,8 @@ use Tests\Helpers\Stub; use Tests\Helpers\StubTransport; - -class TestPubNubHistory extends \PubNubTestCase +class HistoryTest extends \PubNubTestCase { - const COUNT = 5; - const TOTAL = 7; - /** * @group history * @group history-integrational @@ -131,10 +127,11 @@ public function testAuthSuccess() */ public function testEncryptedSuccess() { - $history = new HistoryExposed($this->pubnub); - - $this->pubnub->getConfiguration()->setUseRandomIV(false); - $this->pubnub->getConfiguration()->setCipherKey("cipherKey"); + $config = $this->config->clone(); + $config->setUseRandomIV(false); + $config->setCipherKey("cipherKey"); + $pubnub = new PubNub($config); + $history = new HistoryExposed($pubnub); $history->stubFor("/v2/history/sub-key/demo/channel/niceChannel") ->withQuery([ @@ -143,7 +140,11 @@ public function testEncryptedSuccess() "pnsdk" => $this->encodedSdkName, "uuid" => Stub::ANY ]) - ->setResponseBody("[[{\"message\":\"zFJeF9BVABL80GUiQEBjLg==\",\"timetoken\":\"14649369736959785\"},{\"message\":\"HIq4MTi9nk/KEYlHOKpMCaH78ZXppGynDHrgY9nAd3s=\",\"timetoken\":\"14649369766426772\"}],14649369736959785,14649369766426772]"); + ->setResponseBody("[[{\"message\":\"zFJeF9BVABL80GUiQEBjLg==\"," + . "\"timetoken\":\"14649369736959785\"}," + . "{\"message\":\"HIq4MTi9nk/KEYlHOKpMCaH78ZXppGynDHrgY9nAd3s=\"," + . "\"timetoken\":\"14649369766426772\"}]," + . " 14649369736959785,14649369766426772]"); $response = $history->channel("niceChannel")->includeTimetoken(true)->sync(); @@ -161,10 +162,11 @@ public function testEncryptedSuccess() public function testEncryptedWithPNOtherSuccess() { - $history = new HistoryExposed($this->pubnub); - - $this->pubnub->getConfiguration()->setUseRandomIV(false); - $this->pubnub->getConfiguration()->setCipherKey("hello"); + $config = $this->config->clone(); + $config->setUseRandomIV(false); + $config->setCipherKey("hello"); + $pubnub = new PubNub($config); + $history = new HistoryExposed($pubnub); $history->stubFor("/v2/history/sub-key/demo/channel/niceChannel") ->withQuery([ @@ -401,9 +403,12 @@ public function xtestSuperCallWithChannelOnly() { $ch = "history-php-ch-.*|@#"; - $this->pubnub_pam->getConfiguration()->setUuid("history-php-uuid-.*|@#"); + $config = $this->config_pam->clone(); + $config->setUuid("history-php-uuid-.*|@#"); + + $pubnub_pam = new PubNub($config); - $result = $this->pubnub_pam->history()->channel($ch)->sync(); + $result = $pubnub_pam->history()->channel($ch)->sync(); $this->assertInstanceOf(PNHistoryResult::class, $result); } @@ -411,10 +416,12 @@ public function xtestSuperCallWithChannelOnly() public function testSuperCallWithAllParams() { $ch = "history-php-ch"; + $config = $this->config_pam->clone(); + $config->setUuid("history-php-uuid"); - $this->pubnub_pam->getConfiguration()->setUuid("history-php-uuid"); + $pubnub_pam = new PubNub($config); - $result = $this->pubnub_pam->history() + $result = $pubnub_pam->history() ->channel($ch) ->count(2) ->includeTimetoken(true) @@ -428,12 +435,14 @@ public function testSuperCallWithAllParams() public function testSuperCallTest() { + $this->expectNotToPerformAssertions(); $this->pubnub_pam->history() ->channel(static::SPECIAL_CHARACTERS) ->sync(); } } +// phpcs:ignore PSR1.Classes.ClassDeclaration class HistoryExposed extends History { protected $transport; diff --git a/tests/integrational/ListChannelsInChannelGroupTest.php b/tests/integrational/ListChannelsInChannelGroupTest.php index 975034b4..5e8bbdcb 100644 --- a/tests/integrational/ListChannelsInChannelGroupTest.php +++ b/tests/integrational/ListChannelsInChannelGroupTest.php @@ -4,13 +4,11 @@ use PubNub\Endpoints\ChannelGroups\ListChannelsInChannelGroup; use PubNub\Exceptions\PubNubResponseParsingException; -use PubNub\Exceptions\PubNubServerException; use PubNub\Exceptions\PubNubValidationException; use PubNub\PubNub; use PubNubTestCase; use Tests\Helpers\StubTransport; - class ListChannelsInChannelGroupTest extends PubNubTestCase { public function testSuccess() @@ -22,7 +20,8 @@ public function testSuccess() "pnsdk" => $this->encodedSdkName, "uuid" => "myUUID" ]) - ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {\"channels\": [\"a\",\"b\"]}, \"service\": \"ChannelGroups\"}"); + ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {\"channels\": [\"a\",\"b\"]}, " + . "\"service\": \"ChannelGroups\"}"); $this->pubnub->getConfiguration()->setUuid("myUUID"); @@ -43,7 +42,8 @@ public function testGroupMissing() "pnsdk" => $this->encodedSdkName, "uuid" => "myUUID" ]) - ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {\"channels\": [\"a\",\"b\"]}, \"service\": \"ChannelGroups\"}"); + ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {\"channels\": [\"a\",\"b\"]}, " + . "\"service\": \"ChannelGroups\"}"); $this->pubnub->getConfiguration()->setUuid("myUUID"); @@ -62,7 +62,8 @@ public function testEmptyGroup() "pnsdk" => $this->encodedSdkName, "uuid" => "myUUID" ]) - ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {\"channels\": [\"a\",\"b\"]}, \"service\": \"ChannelGroups\"}"); + ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {\"channels\": [\"a\",\"b\"]}, " + . "\"service\": \"ChannelGroups\"}"); $this->pubnub->getConfiguration()->setUuid("myUUID"); @@ -108,6 +109,7 @@ public function testNullBody() public function testIsAuthRequiredSuccess() { + $this->expectNotToPerformAssertions(); $listChannelsInChannelGroup = new ListChannelsInChannelGroupExposed($this->pubnub); $listChannelsInChannelGroup->stubFor("/v1/channel-registration/sub-key/demo/channel-group/groupA") @@ -116,7 +118,8 @@ public function testIsAuthRequiredSuccess() "uuid" => "myUUID", "auth" => "myKey" ]) - ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {\"channels\": [\"a\",\"b\"]}, \"service\": \"ChannelGroups\"}"); + ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {\"channels\": [\"a\",\"b\"]}, " + . "\"service\": \"ChannelGroups\"}"); $this->pubnub->getConfiguration()->setUuid("myUUID")->setAuthKey("myKey"); @@ -124,7 +127,7 @@ public function testIsAuthRequiredSuccess() } } - +// phpcs:ignore PSR1.Classes.ClassDeclaration class ListChannelsInChannelGroupExposed extends ListChannelsInChannelGroup { protected $transport; @@ -147,4 +150,4 @@ public function requestOptions() 'transport' => $this->transport ]; } -} \ No newline at end of file +} diff --git a/tests/integrational/ListPushProvisionsTest.php b/tests/integrational/ListPushProvisionsTest.php index 89e51d18..49164cab 100644 --- a/tests/integrational/ListPushProvisionsTest.php +++ b/tests/integrational/ListPushProvisionsTest.php @@ -12,15 +12,13 @@ class ListPushProvisionsTest extends \PubNubTestCase { public function testAppleSuccess() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $list = new ListPushProvisionsExposed($this->pubnub); $list->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ "type" => "apns", "pnsdk" => $this->encodedSdkName, - "uuid" => "sampleUUID" + "uuid" => getenv("UUID_MOCK") ]) ->setResponseBody("[\"ch1\", \"ch2\", \"ch3\"]"); @@ -33,15 +31,13 @@ public function testAppleSuccess() public function testFCMSuccess() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $list = new ListPushProvisionsExposed($this->pubnub); $list->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ "type" => "gcm", "pnsdk" => $this->encodedSdkName, - "uuid" => "sampleUUID" + "uuid" => getenv("UUID_MOCK") ]) ->setResponseBody("[\"ch1\", \"ch2\", \"ch3\"]"); @@ -54,15 +50,13 @@ public function testFCMSuccess() public function testMicrosoftSuccess() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $list = new ListPushProvisionsExposed($this->pubnub); $list->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ "type" => "mpns", "pnsdk" => $this->encodedSdkName, - "uuid" => "sampleUUID" + "uuid" => getenv("UUID_MOCK") ]) ->setResponseBody("[\"ch1\", \"ch2\", \"ch3\"]"); @@ -75,17 +69,17 @@ public function testMicrosoftSuccess() public function testIsAuthRequiredSuccess() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $this->pubnub->getConfiguration()->setAuthKey("myKey"); - - $list = new ListPushProvisionsExposed($this->pubnub); + $config = $this->config->clone(); + $config->setAuthKey("myKey"); + $pubnub = new PubNub($config); + $list = new ListPushProvisionsExposed($pubnub); $list->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ "auth" => "myKey", "type" => "mpns", "pnsdk" => $this->encodedSdkName, - "uuid" => "sampleUUID" + "uuid" => getenv("UUID_MOCK") ]) ->setResponseBody("[\"ch1\", \"ch2\", \"ch3\"]"); @@ -98,13 +92,11 @@ public function testIsAuthRequiredSuccess() public function testNullSubscribeKey() { - $this->expectException(PubNubValidationException::class); - $this->expectExceptionMessage("Subscribe Key not configured"); - - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $this->pubnub->getConfiguration()->setSubscribeKey(null); - - $list = new ListPushProvisionsExposed($this->pubnub); + $this->expectException(\TypeError::class); + $config = $this->config->clone(); + $config->setSubscribeKey(null); + $pubnub = new PubNub($config); + $list = new ListPushProvisionsExposed($pubnub); $list->deviceId("coolDevice") ->pushType(PNPushType::MPNS) @@ -116,10 +108,10 @@ public function testEmptySubscribeKey() $this->expectException(PubNubValidationException::class); $this->expectExceptionMessage("Subscribe Key not configured"); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $this->pubnub->getConfiguration()->setSubscribeKey(""); - - $list = new ListPushProvisionsExposed($this->pubnub); + $config = $this->config->clone(); + $config->setSubscribeKey(''); + $pubnub = new PubNub($config); + $list = new ListPushProvisionsExposed($pubnub); $list->deviceId("coolDevice") ->pushType(PNPushType::MPNS) @@ -131,8 +123,6 @@ public function testNullPushType() $this->expectException(PubNubValidationException::class); $this->expectExceptionMessage("Push Type is missing"); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $list = new ListPushProvisionsExposed($this->pubnub); $list->deviceId("coolDevice") @@ -142,10 +132,7 @@ public function testNullPushType() public function testNullDeviceId() { $this->expectException(PubNubValidationException::class); - $this->expectExceptionMessage("Subscribe Key not configured"); - - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $this->pubnub->getConfiguration()->setSubscribeKey(""); + $this->expectExceptionMessage("Device ID is missing for push operation"); $list = new ListPushProvisionsExposed($this->pubnub); @@ -158,8 +145,6 @@ public function testEmptyDeviceIdRemoveAll() $this->expectException(PubNubValidationException::class); $this->expectExceptionMessage("Device ID is missing for push operation"); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $list = new ListPushProvisionsExposed($this->pubnub); $list->deviceId("") diff --git a/tests/integrational/ModifyPushChannelsForDeviceTest.php b/tests/integrational/ModifyPushChannelsForDeviceTest.php index 3a3a6f39..46e4f48f 100644 --- a/tests/integrational/ModifyPushChannelsForDeviceTest.php +++ b/tests/integrational/ModifyPushChannelsForDeviceTest.php @@ -14,9 +14,11 @@ class ModifyPushChannelsForDeviceTest extends \PubNubTestCase { public function testListChannelGroupAPNS() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); - $listRemove = new RemoveChannelsFromPushTestExposed($this->pubnub); + $listRemove = new RemoveChannelsFromPushTestExposed($pubnub); $listRemove->stubFor("/v1/push/sub-key/demo/devices/coolDevice/remove") ->withQuery([ @@ -35,9 +37,11 @@ public function testListChannelGroupAPNS() public function testFCMSuccessRemoveAll() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); - $listRemove = new RemoveChannelsFromPushTestExposed($this->pubnub); + $listRemove = new RemoveChannelsFromPushTestExposed($pubnub); $listRemove->stubFor("/v1/push/sub-key/demo/devices/coolDevice/remove") ->withQuery([ @@ -56,9 +60,11 @@ public function testFCMSuccessRemoveAll() public function testMicrosoftSuccessRemoveAll() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); - $listRemove = new RemoveChannelsFromPushTestExposed($this->pubnub); + $listRemove = new RemoveChannelsFromPushTestExposed($pubnub); $listRemove->stubFor("/v1/push/sub-key/demo/devices/coolDevice/remove") ->withQuery([ @@ -77,10 +83,12 @@ public function testMicrosoftSuccessRemoveAll() public function testIsAuthRequiredSuccessRemoveAll() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $this->pubnub->getConfiguration()->setAuthKey("myKey"); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $config->setAuthKey('myKey'); + $pubnub = new PubNub($config); - $listRemove = new RemoveChannelsFromPushTestExposed($this->pubnub); + $listRemove = new RemoveChannelsFromPushTestExposed($pubnub); $listRemove->stubFor("/v1/push/sub-key/demo/devices/coolDevice/remove") ->withQuery([ @@ -100,13 +108,13 @@ public function testIsAuthRequiredSuccessRemoveAll() public function testNullSubscribeKeyRemoveAll() { - $this->expectException(PubNubValidationException::class); - $this->expectExceptionMessage("Subscribe Key not configured"); - - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $this->pubnub->getConfiguration()->setSubscribeKey(null); + $this->expectException(\TypeError::class); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $config->setSubscribeKey(null); + $pubnub = new PubNub($config); - $listRemove = new RemoveChannelsFromPushTestExposed($this->pubnub); + $listRemove = new RemoveChannelsFromPushTestExposed($pubnub); $listRemove->pushType(PNPushType::MPNS) ->deviceId("coolDevice") @@ -118,10 +126,12 @@ public function testEmptySubscribeKeyRemoveAll() $this->expectException(PubNubValidationException::class); $this->expectExceptionMessage("Subscribe Key not configured"); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $this->pubnub->getConfiguration()->setSubscribeKey(""); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $config->setSubscribeKey(""); + $pubnub = new PubNub($config); - $listRemove = new RemoveChannelsFromPushTestExposed($this->pubnub); + $listRemove = new RemoveChannelsFromPushTestExposed($pubnub); $listRemove->pushType(PNPushType::MPNS) ->deviceId("coolDevice") @@ -133,9 +143,11 @@ public function testNullPushTypeRemoveAll() $this->expectException(PubNubValidationException::class); $this->expectExceptionMessage("Push Type is missing"); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); - $listRemove = new RemoveChannelsFromPushTestExposed($this->pubnub); + $listRemove = new RemoveChannelsFromPushTestExposed($pubnub); $listRemove->deviceId("coolDevice") ->sync(); @@ -146,9 +158,11 @@ public function testNullDeviceIdRemoveAll() $this->expectException(PubNubValidationException::class); $this->expectExceptionMessage("Device ID is missing for push operation"); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); - $listRemove = new RemoveChannelsFromPushTestExposed($this->pubnub); + $listRemove = new RemoveChannelsFromPushTestExposed($pubnub); $listRemove->pushType(PNPushType::MPNS) ->sync(); @@ -159,9 +173,11 @@ public function testEmptyDeviceIdRemoveAll() $this->expectException(PubNubValidationException::class); $this->expectExceptionMessage("Device ID is missing for push operation"); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); - $listRemove = new RemoveChannelsFromPushTestExposed($this->pubnub); + $listRemove = new RemoveChannelsFromPushTestExposed($pubnub); $listRemove->pushType(PNPushType::MPNS) ->deviceId("") @@ -170,9 +186,11 @@ public function testEmptyDeviceIdRemoveAll() public function testAddAppleSuccess() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); - $listAdd = new AddChannelsToPushExposed($this->pubnub); + $listAdd = new AddChannelsToPushExposed($pubnub); $listAdd->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ @@ -193,9 +211,11 @@ public function testAddAppleSuccess() public function testAddFCMSuccessSync() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); - $listAdd = new AddChannelsToPushExposed($this->pubnub); + $listAdd = new AddChannelsToPushExposed($pubnub); $listAdd->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ @@ -216,9 +236,11 @@ public function testAddFCMSuccessSync() public function testAddMicrosoftSuccessSync() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); - $listAdd = new AddChannelsToPushExposed($this->pubnub); + $listAdd = new AddChannelsToPushExposed($pubnub); $listAdd->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ @@ -239,10 +261,12 @@ public function testAddMicrosoftSuccessSync() public function testIsAuthRequiredSuccessAdd() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $this->pubnub->getConfiguration()->setAuthKey("myKey"); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $config->setAuthKey("myKey"); + $pubnub = new PubNub($config); - $listAdd = new AddChannelsToPushExposed($this->pubnub); + $listAdd = new AddChannelsToPushExposed($pubnub); $listAdd->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ @@ -264,13 +288,14 @@ public function testIsAuthRequiredSuccessAdd() public function testNullSubscribeKeyAdd() { - $this->expectException(PubNubValidationException::class); - $this->expectExceptionMessage("Subscribe Key not configured"); + $this->expectException(\TypeError::class); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $this->pubnub->getConfiguration()->setSubscribeKey(null); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $config->setSubscribeKey(null); + $pubnub = new PubNub($config); - $listAdd = new AddChannelsToPushExposed($this->pubnub); + $listAdd = new AddChannelsToPushExposed($pubnub); $listAdd->pushType(PNPushType::MPNS) ->channels(["ch1", "ch2", "ch3"]) @@ -282,11 +307,11 @@ public function testEmptySubscribeKeyAdd() { $this->expectException(PubNubValidationException::class); $this->expectExceptionMessage("Subscribe Key not configured"); - - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $this->pubnub->getConfiguration()->setSubscribeKey(""); - - $listAdd = new AddChannelsToPushExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $config->setSubscribeKey(''); + $pubnub = new PubNub($config); + $listAdd = new AddChannelsToPushExposed($pubnub); $listAdd->pushType(PNPushType::MPNS) ->channels(["ch1", "ch2", "ch3"]) @@ -299,9 +324,10 @@ public function testNullPushTypeAdd() $this->expectException(PubNubValidationException::class); $this->expectExceptionMessage("Push Type is missing"); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - - $listAdd = new AddChannelsToPushExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); + $listAdd = new AddChannelsToPushExposed($pubnub); $listAdd->channels(["ch1", "ch2", "ch3"]) ->deviceId("coolDevice") @@ -313,9 +339,10 @@ public function testNullDeviceIdAdd() $this->expectException(PubNubValidationException::class); $this->expectExceptionMessage("Device ID is missing for push operation"); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - - $listAdd = new AddChannelsToPushExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); + $listAdd = new AddChannelsToPushExposed($pubnub); $listAdd->pushType(PNPushType::MPNS) ->channels(["ch1", "ch2", "ch3"]) @@ -327,9 +354,10 @@ public function testEmptyDeviceIdAdd() $this->expectException(PubNubValidationException::class); $this->expectExceptionMessage("Device ID is missing for push operation"); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - - $listAdd = new AddChannelsToPushExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); + $listAdd = new AddChannelsToPushExposed($pubnub); $listAdd->pushType(PNPushType::MPNS) ->channels(["ch1", "ch2", "ch3"]) @@ -342,9 +370,10 @@ public function testMissingChannelsAdd() $this->expectException(PubNubValidationException::class); $this->expectExceptionMessage("Channel missing"); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - - $listAdd = new AddChannelsToPushExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); + $listAdd = new AddChannelsToPushExposed($pubnub); $listAdd->pushType(PNPushType::MPNS) ->deviceId("Example") @@ -353,9 +382,10 @@ public function testMissingChannelsAdd() public function testAppleSuccessRemove() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - - $remove = new RemovePushNotificationsFromChannelsExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); + $remove = new RemovePushNotificationsFromChannelsExposed($pubnub); $remove->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ @@ -376,9 +406,10 @@ public function testAppleSuccessRemove() public function testFCMSuccessRemove() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - - $remove = new RemovePushNotificationsFromChannelsExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); + $remove = new RemovePushNotificationsFromChannelsExposed($pubnub); $remove->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ @@ -399,9 +430,10 @@ public function testFCMSuccessRemove() public function testMicrosoftSuccessRemove() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - - $remove = new RemovePushNotificationsFromChannelsExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); + $remove = new RemovePushNotificationsFromChannelsExposed($pubnub); $remove->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ @@ -422,10 +454,11 @@ public function testMicrosoftSuccessRemove() public function testIsAuthRequiredSuccessRemove() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $this->pubnub->getConfiguration()->setAuthKey("myKey"); - - $remove = new RemovePushNotificationsFromChannelsExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $config->setAuthKey("myKey"); + $pubnub = new PubNub($config); + $remove = new RemovePushNotificationsFromChannelsExposed($pubnub); $remove->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ @@ -447,13 +480,13 @@ public function testIsAuthRequiredSuccessRemove() public function testNullSubscribeKeyRemove() { - $this->expectException(PubNubValidationException::class); - $this->expectExceptionMessage("Subscribe Key not configured"); + $this->expectException(\TypeError::class); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $this->pubnub->getConfiguration()->setSubscribeKey(null); - - $remove = new RemovePushNotificationsFromChannelsExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $config->setSubscribeKey(null); + $pubnub = new PubNub($config); + $remove = new RemovePushNotificationsFromChannelsExposed($pubnub); $remove->pushType(PNPushType::MPNS) ->channels(["ch1", "ch2", "ch3"]) @@ -466,10 +499,12 @@ public function testEmptySubscribeKeyRemove() $this->expectException(PubNubValidationException::class); $this->expectExceptionMessage("Subscribe Key not configured"); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $this->pubnub->getConfiguration()->setSubscribeKey(null); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $config->setSubscribeKey(''); + $pubnub = new PubNub($config); + $remove = new RemovePushNotificationsFromChannelsExposed($pubnub); - $remove = new RemovePushNotificationsFromChannelsExposed($this->pubnub); $remove->pushType(PNPushType::MPNS) ->channels(["ch1", "ch2", "ch3"]) @@ -510,9 +545,10 @@ public function testEmptyDeviceId() $this->expectException(PubNubValidationException::class); $this->expectExceptionMessage("Device ID is missing for push operation"); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - - $remove = new RemovePushNotificationsFromChannelsExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); + $remove = new RemovePushNotificationsFromChannelsExposed($pubnub); $remove->pushType(PNPushType::MPNS) ->channels(["ch1", "ch2", "ch3"]) @@ -525,9 +561,10 @@ public function testMissingChannels() $this->expectException(PubNubValidationException::class); $this->expectExceptionMessage("Channel missing"); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - - $remove = new RemovePushNotificationsFromChannelsExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); + $remove = new RemovePushNotificationsFromChannelsExposed($pubnub); $remove->pushType(PNPushType::MPNS) ->deviceId("") diff --git a/tests/integrational/PublishTest.php b/tests/integrational/PublishTest.php index fadcece4..33abb1ca 100644 --- a/tests/integrational/PublishTest.php +++ b/tests/integrational/PublishTest.php @@ -10,7 +10,6 @@ use PubNub\PNConfiguration; use PubNub\PubNub; - class PublishTest extends \PubNubTestCase { /** @@ -61,7 +60,7 @@ public function testPublishMixedViaGet() $this->assertSuccessPublishGet($this->pubnub->publish(), 3.14); $this->assertSuccessPublishGet($this->pubnub->publish(), false); $this->assertSuccessPublishGet($this->pubnub->publish(), ['hey', 'hey2', 'hey3']); - $this->assertSuccessPublishGet($this->pubnub->publish(), ['hey' => 31, 'hey2' => true, 'hey3' =>['ok']]); + $this->assertSuccessPublishGet($this->pubnub->publish(), ['hey' => 31, 'hey2' => true, 'hey3' => ['ok']]); } public function testPublishMixedViaPost() @@ -71,7 +70,7 @@ public function testPublishMixedViaPost() $this->assertSuccessPublishPost($this->pubnub->publish(), 3.14); $this->assertSuccessPublishPost($this->pubnub->publish(), false); $this->assertSuccessPublishPost($this->pubnub->publish(), ['hey', 'hey2', 'hey3']); - $this->assertSuccessPublishPost($this->pubnub->publish(), ['hey' => 31, 'hey2' => true, 'hey3' =>['ok']]); + $this->assertSuccessPublishPost($this->pubnub->publish(), ['hey' => 31, 'hey2' => true, 'hey3' => ['ok']]); } public function testPublishMixedViaGetEncrypted() @@ -81,7 +80,7 @@ public function testPublishMixedViaGetEncrypted() $this->assertSuccessPublishGet($this->pubnub_enc->publish(), 3.14); $this->assertSuccessPublishGet($this->pubnub_enc->publish(), false); $this->assertSuccessPublishGet($this->pubnub_enc->publish(), ['hey', 'hey2', 'hey3']); - $this->assertSuccessPublishGet($this->pubnub_enc->publish(), ['hey' => 31, 'hey2' => true, 'hey3' =>['ok']]); + $this->assertSuccessPublishGet($this->pubnub_enc->publish(), ['hey' => 31, 'hey2' => true, 'hey3' => ['ok']]); } public function testPublishMixedViaPostEncrypted() @@ -91,7 +90,7 @@ public function testPublishMixedViaPostEncrypted() $this->assertSuccessPublishPost($this->pubnub_enc->publish(), 3.14); $this->assertSuccessPublishPost($this->pubnub_enc->publish(), false); $this->assertSuccessPublishPost($this->pubnub_enc->publish(), ['hey', 'hey2', 'hey3']); - $this->assertSuccessPublishPost($this->pubnub_enc->publish(), ['hey' => 31, 'hey2' => true, 'hey3' =>['ok']]); + $this->assertSuccessPublishPost($this->pubnub_enc->publish(), ['hey' => 31, 'hey2' => true, 'hey3' => ['ok']]); } public function testPublishDoNotSerialize() @@ -112,7 +111,12 @@ public function testPublishDoNotSerializeInvalidType() public function testPublishDoNotSerializePost() { - $response = $this->pubnub->publish()->usePost(true)->doNotSerialize()->channel("ch1")->message("{\"message\": 2}")->sync(); + $response = $this->pubnub->publish() + ->usePost(true) + ->doNotSerialize() + ->channel("ch1") + ->message("{\"message\": 2}") + ->sync(); $this->assertGreaterThan(0, $response->getTimetoken()); } @@ -179,6 +183,7 @@ public function testServerSideErrorEnvelope() public function testSuperCall() { + $this->expectNotToPerformAssertions(); $this->pubnub_pam->getConfiguration()->setUuid(static::SPECIAL_CHARACTERS); $this->pubnub_pam->getConfiguration()->setAuthKey(static::SPECIAL_CHANNEL); diff --git a/tests/integrational/RemoveChannelFromChannelGroupEndpointTest.php b/tests/integrational/RemoveChannelFromChannelGroupEndpointTest.php index 793b2cb1..92987507 100644 --- a/tests/integrational/RemoveChannelFromChannelGroupEndpointTest.php +++ b/tests/integrational/RemoveChannelFromChannelGroupEndpointTest.php @@ -3,13 +3,11 @@ namespace Tests\Integrational; use PubNub\Endpoints\ChannelGroups\RemoveChannelFromChannelGroup; -use PubNub\Exceptions\PubNubServerException; use PubNub\Exceptions\PubNubValidationException; use PubNub\PubNub; use PubNubTestCase; use Tests\Helpers\StubTransport; - class RemoveChannelFromChannelGroupEndpointTest extends PubNubTestCase { public function testSuccess() @@ -22,7 +20,7 @@ public function testSuccess() "uuid" => "myUUID", "remove" => "ch1,ch2" ]) - ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {}, \"service\": \"ChannelGroups\"}"); + ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {},\"service\": \"ChannelGroups\"}"); $this->pubnub->getConfiguration()->setUuid("myUUID"); @@ -43,7 +41,7 @@ public function testGroupMissing() "pnsdk" => $this->encodedSdkName, "uuid" => "myUUID" ]) - ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {}, \"service\": \"ChannelGroups\"}"); + ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {},\"service\": \"ChannelGroups\"}"); $this->pubnub->getConfiguration()->setUuid("myUUID"); @@ -62,7 +60,7 @@ public function testEmptyGroup() "pnsdk" => $this->encodedSdkName, "uuid" => "myUUID" ]) - ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {}, \"service\": \"ChannelGroups\"}"); + ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {},\"service\": \"ChannelGroups\"}"); $this->pubnub->getConfiguration()->setUuid("myUUID"); @@ -71,6 +69,7 @@ public function testEmptyGroup() public function testIsAuthRequiredSuccess() { + $this->expectNotToPerformAssertions(); $removeChannelFromChannelGroup = new RemoveChannelFromChannelGroupExposed($this->pubnub); $removeChannelFromChannelGroup->stubFor("/v1/channel-registration/sub-key/demo/channel-group/groupA") @@ -80,7 +79,7 @@ public function testIsAuthRequiredSuccess() "auth" => "myKey", "remove" => "ch1,ch2" ]) - ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {}, \"service\": \"ChannelGroups\"}"); + ->setResponseBody("{\"status\": 200, \"message\": \"OK\", \"payload\": {},\"service\": \"ChannelGroups\"}"); $this->pubnub->getConfiguration()->setUuid("myUUID")->setAuthKey("myKey"); @@ -88,7 +87,7 @@ public function testIsAuthRequiredSuccess() } } - +// phpcs:ignore PSR1.Classes.ClassDeclaration class RemoveChannelFromChannelGroupExposed extends RemoveChannelFromChannelGroup { protected $transport; @@ -111,4 +110,4 @@ public function requestOptions() 'transport' => $this->transport ]; } -} \ No newline at end of file +} diff --git a/tests/integrational/SetStateTest.php b/tests/integrational/SetStateTest.php index 93242f0f..6978817b 100644 --- a/tests/integrational/SetStateTest.php +++ b/tests/integrational/SetStateTest.php @@ -9,12 +9,14 @@ use PubNub\PubNubUtil; use Tests\Helpers\StubTransport; - class SetStateTest extends \PubNubTestCase { public function testApplyStateForChannel() { - $setState = new SetStateExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("myUUID"); + $pubnub = new PubNub($config); + $setState = new SetStateExposed($pubnub); $myState = [ "age" => 20 @@ -26,9 +28,8 @@ public function testApplyStateForChannel() "pnsdk" => $this->encodedSdkName, "uuid" => "myUUID" ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\" }, \"service\": \"Presence\"}"); - - $this->pubnub->getConfiguration()->setUuid("myUUID"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, " + . "\"status\" : \"online\" }, \"service\": \"Presence\"}"); $response = $setState->channels("testChannel")->state($myState)->sync(); @@ -38,7 +39,10 @@ public function testApplyStateForChannel() public function testApplyStateForSomebodyElseChannel() { - $setState = new SetStateExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("someoneElseUUID"); + $pubnub = new PubNub($config); + $setState = new SetStateExposed($pubnub); $myState = [ "age" => 20 @@ -50,9 +54,8 @@ public function testApplyStateForSomebodyElseChannel() "state" => "%7B%22age%22%3A20%7D", "pnsdk" => $this->encodedSdkName ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\" }, \"service\": \"Presence\"}"); - - $this->pubnub->getConfiguration()->setUuid("someoneElseUUID"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : " + . "\"online\" }, \"service\": \"Presence\"}"); $response = $setState->channels("testChannel")->state($myState)->sync(); @@ -62,7 +65,10 @@ public function testApplyStateForSomebodyElseChannel() public function testApplyStateForChannelsSync() { - $setState = new SetStateExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("myUUID"); + $pubnub = new PubNub($config); + $setState = new SetStateExposed($pubnub); $myState = [ "age" => 20 @@ -74,9 +80,8 @@ public function testApplyStateForChannelsSync() "state" => "%7B%22age%22%3A20%7D", "pnsdk" => $this->encodedSdkName ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\" }, \"service\": \"Presence\"}"); - - $this->pubnub->getConfiguration()->setUuid("myUUID"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : " + . "\"online\" }, \"service\": \"Presence\"}"); $response = $setState->channels(["testChannel", "testChannel2"])->state($myState)->sync(); @@ -86,7 +91,10 @@ public function testApplyStateForChannelsSync() public function testApplyStateForChannelGroup() { - $setState = new SetStateExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("myUUID"); + $pubnub = new PubNub($config); + $setState = new SetStateExposed($pubnub); $myState = [ "age" => 20 @@ -99,9 +107,9 @@ public function testApplyStateForChannelGroup() "pnsdk" => $this->encodedSdkName, "channel-group" => "cg1" ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\" }, \"service\": \"Presence\"}"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : " + . "\"online\" }, \"service\": \"Presence\"}"); - $this->pubnub->getConfiguration()->setUuid("myUUID"); $response = $setState->channelGroups("cg1")->state($myState)->sync(); @@ -111,7 +119,10 @@ public function testApplyStateForChannelGroup() public function testApplyStateForChannelGroups() { - $setState = new SetStateExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("myUUID"); + $pubnub = new PubNub($config); + $setState = new SetStateExposed($pubnub); $myState = [ "age" => 20 @@ -124,9 +135,9 @@ public function testApplyStateForChannelGroups() "pnsdk" => $this->encodedSdkName, "channel-group" => PubNubUtil::urlEncode("cg1,cg2") ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\" }, \"service\": \"Presence\"}"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : " + . "\"online\" }, \"service\": \"Presence\"}"); - $this->pubnub->getConfiguration()->setUuid("myUUID"); $response = $setState->channelGroups(["cg1", "cg2"])->state($myState)->sync(); @@ -136,7 +147,10 @@ public function testApplyStateForChannelGroups() public function testApplyStateForMix() { - $setState = new SetStateExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("myUUID"); + $pubnub = new PubNub($config); + $setState = new SetStateExposed($pubnub); $myState = [ "age" => 20 @@ -149,9 +163,9 @@ public function testApplyStateForMix() "pnsdk" => $this->encodedSdkName, "channel-group" => PubNubUtil::urlEncode("cg1,cg2") ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\" }, \"service\": \"Presence\"}"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : " + . "\"online\" }, \"service\": \"Presence\"}"); - $this->pubnub->getConfiguration()->setUuid("myUUID"); $response = $setState->channels("ch1")->channelGroups(["cg1", "cg2"])->state($myState)->sync(); @@ -163,7 +177,10 @@ public function testApplyNon200() { $this->expectException(PubNubException::class); - $setState = new SetStateExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("myUUID"); + $pubnub = new PubNub($config); + $setState = new SetStateExposed($pubnub); $myState = [ "age" => 20 @@ -176,16 +193,21 @@ public function testApplyNon200() "pnsdk" => $this->encodedSdkName, "channel-group" => PubNubUtil::urlEncode("cg1,cg2") ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\" }, \"service\": \"Presence\"}"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : " + . "\"online\" }, \"service\": \"Presence\"}"); - $this->pubnub->getConfiguration()->setUuid("myUUID"); $setState->channels("ch1")->channelGroups(["cg1cg2"])->state($myState)->sync(); } public function testMissingState() { - $setState = new SetStateExposed($this->pubnub); + $this->expectNotToPerformAssertions(); + + $config = $this->config->clone(); + $config->setUuid("myUUID"); + $pubnub = new PubNub($config); + $setState = new SetStateExposed($pubnub); $setState->stubFor("/v2/presence/sub-key/demo/channel/ch1/uuid/myUUID/data") ->withQuery([ @@ -193,16 +215,21 @@ public function testMissingState() "pnsdk" => $this->encodedSdkName, "state" => "%5B%5D" ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\" }, \"service\": \"Presence\"}"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : " + . "\"online\" }, \"service\": \"Presence\"}"); - $this->pubnub->getConfiguration()->setUuid("myUUID"); $setState->channels("ch1")->sync(); } public function testIsAuthRequiredSuccess() { - $setState = new SetStateExposed($this->pubnub); + $this->expectNotToPerformAssertions(); + $config = $this->config->clone(); + $config->setUuid("myUUID"); + $config->setAuthKey("myKey"); + $pubnub = new PubNub($config); + $setState = new SetStateExposed($pubnub); $myState = [ "age" => 20 @@ -215,20 +242,21 @@ public function testIsAuthRequiredSuccess() "pnsdk" => $this->encodedSdkName, "auth" => "myKey" ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\" }, \"service\": \"Presence\"}"); - - $this->pubnub->getConfiguration()->setUuid("myUUID"); - $this->pubnub->getConfiguration()->setAuthKey("myKey"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : " + . "\"online\" }, \"service\": \"Presence\"}"); $setState->channels("ch1")->state($myState)->sync(); } public function testNullSubKey() { - $this->expectException(PubNubException::class); - $this->expectExceptionMessage("Subscribe Key not configured"); + $this->expectException(\TypeError::class); - $setState = new SetStateExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("myUUID"); + $config->setSubscribeKey(null); + $pubnub = new PubNub($config); + $setState = new SetStateExposed($pubnub); $myState = [ "age" => 20 @@ -240,10 +268,8 @@ public function testNullSubKey() "state" => "%7B%22age%22%3A20%7D", "pnsdk" => $this->encodedSdkName ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\" }, \"service\": \"Presence\"}"); - - $this->pubnub->getConfiguration()->setUuid("myUUID"); - $this->pubnub->getConfiguration()->setSubscribeKey(null); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : " + . "\"online\" }, \"service\": \"Presence\"}"); $setState->channels("ch1")->state($myState)->sync(); } @@ -253,7 +279,11 @@ public function testEmptySubKey() $this->expectException(PubNubException::class); $this->expectExceptionMessage("Subscribe Key not configured"); - $setState = new SetStateExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("myUUID"); + $config->setSubscribeKey(""); + $pubnub = new PubNub($config); + $setState = new SetStateExposed($pubnub); $myState = [ "age" => 20 @@ -265,10 +295,8 @@ public function testEmptySubKey() "state" => "%7B%22age%22%3A20%7D", "pnsdk" => $this->encodedSdkName ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\" }, \"service\": \"Presence\"}"); - - $this->pubnub->getConfiguration()->setUuid("myUUID"); - $this->pubnub->getConfiguration()->setSubscribeKey(""); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : " + . "\"online\" }, \"service\": \"Presence\"}"); $setState->channels("ch1")->state($myState)->sync(); } @@ -278,7 +306,10 @@ public function testChannelAndGroupMissing() $this->expectException(PubNubException::class); $this->expectExceptionMessage("Channel or group missing"); - $setState = new SetStateExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("myUUID"); + $pubnub = new PubNub($config); + $setState = new SetStateExposed($pubnub); $myState = [ "age" => 20 @@ -290,9 +321,9 @@ public function testChannelAndGroupMissing() "state" => "%7B%22age%22%3A20%7D", "pnsdk" => $this->encodedSdkName ]) - ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : \"online\" }, \"service\": \"Presence\"}"); + ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"payload\": { \"age\" : 20, \"status\" : " + . "\"online\" }, \"service\": \"Presence\"}"); - $this->pubnub->getConfiguration()->setUuid("myUUID"); $setState->state($myState)->sync(); } @@ -301,7 +332,10 @@ public function testNullPayload() { $this->expectException(PubNubException::class); - $setState = new SetStateExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("myUUID"); + $pubnub = new PubNub($config); + $setState = new SetStateExposed($pubnub); $myState = [ "age" => 20 @@ -315,13 +349,12 @@ public function testNullPayload() ]) ->setResponseBody("{ \"status\": 200, \"message\": \"OK\", \"service\": \"Presence\"}"); - $this->pubnub->getConfiguration()->setUuid("myUUID"); $setState->channels("testChannel")->state($myState)->sync(); } } - +// phpcs:ignore PSR1.Classes.ClassDeclaration class SetStateExposed extends SetState { protected $transport; diff --git a/tests/integrational/SslTest.php b/tests/integrational/SslTest.php index 60aa15c8..42c72b69 100644 --- a/tests/integrational/SslTest.php +++ b/tests/integrational/SslTest.php @@ -2,6 +2,8 @@ namespace Tests\Integrational; +use PubNub\PubNub; + class SslTest extends \PubNubTestCase { /** @@ -11,8 +13,11 @@ class SslTest extends \PubNubTestCase public function testSslIsSetByDefault() { $transport = new CheckSslTransport(); - $this->pubnub->getConfiguration()->setTransport($transport); - $time = $this->pubnub->time()->sync(); + $config = $this->config->clone(); + $config->setTransport($transport); + $pubnub = new PubNub($config); + + $pubnub->time()->sync(); $this->assertTrue($transport->isRequestedSecureOrigin()); } @@ -24,14 +29,17 @@ public function testSslIsSetByDefault() public function testSslCanBeDisabled() { $transport = new CheckSslTransport(); - $this->pubnub->getConfiguration()->setTransport($transport); - $this->pubnub->getConfiguration()->setSecure(false); - $this->pubnub->time()->sync(); + $config = $this->config->clone(); + $config->setTransport($transport); + $config->setSecure(false); + $pubnub = new PubNub($config); + $pubnub->time()->sync(); $this->assertFalse($transport->isRequestedSecureOrigin()); } } +//phpcs:ignore PSR1.Classes.ClassDeclaration class CheckSslTransport implements \WpOrg\Requests\Transport { protected $requestedThroughHttps; @@ -51,6 +59,7 @@ public function request($url, $headers = array(), $data = array(), $options = ar . "[16614599133417872]"; } + // phpcs:ignore PSR1.Methods.CamelCapsMethodName public function request_multiple($requests, $options) { } diff --git a/tests/integrational/SubscribePresenceTest.php b/tests/integrational/SubscribePresenceTest.php index c4931706..0e8ba106 100644 --- a/tests/integrational/SubscribePresenceTest.php +++ b/tests/integrational/SubscribePresenceTest.php @@ -10,7 +10,6 @@ use PubNubTestCase; use Tests\Helpers\StubTransport; - /** * Class SubscribePresenceTest * @@ -19,7 +18,8 @@ */ class SubscribePresenceTest extends PubNubTestCase { - public function testMessageOnPresenceCallback() { + public function testMessageOnPresenceCallback() + { $transport = new StubTransport(); $transport->stubFor("/v2/presence/sub-key/demo/channel/blah/leave") @@ -46,12 +46,17 @@ public function testMessageOnPresenceCallback() { "tr" => "12" ]) ->setResponseStatus("HTTP/1.0 200 OK") - ->setResponseBody('{"t":{"t":"14818963588185526","r":12},"m":[{"a":"2","f":0,"p":{"t":"14818963587725382","r":2},"k":"demo","c":"blah-pnpres","d":{"action": "join", "timestamp": 1481896358, "uuid": "test-subscribe-listener", "occupancy": 1},"b":"blah-pnpres"}]}'); + ->setResponseBody('{"t":{"t":"14818963588185526","r":12},"m":[{"a":"2","f":0,' + . '"p":{"t":"14818963587725382","r":2},"k":"demo","c":"blah-pnpres",' + . '"d":{"action": "join", "timestamp": 1481896358, "uuid": "test-subscribe-listener", "occupancy": 1},' + . '"b":"blah-pnpres"}]}'); $callback = new MySubscribeCallbackToTestPresence(); - $pubnub = PubNub::demo(); - $pubnub->getConfiguration()->setTransport($transport)->setUuid("myUUID"); + $config = $this->config->clone(); + $config->setTransport($transport); + $config->setUuid("myUUID"); + $pubnub = new PubNub($config); $pubnub->addListener($callback); $pubnub->subscribe()->channel("blah")->withPresence()->execute(); @@ -61,7 +66,7 @@ public function testMessageOnPresenceCallback() { } } - +//phpcs:ignore PSR1.Classes.ClassDeclaration class MySubscribeCallbackToTestPresence extends SubscribeCallback { protected $connectedInvoked = false; @@ -72,11 +77,11 @@ public function areBothConnectedAndDisconnectedInvoked() return $this->connectedInvoked && $this->disconnectedInvoked; } - function status($pubnub, $status) + public function status($pubnub, $status) { if ($status->getCategory() === PNStatusCategory::PNConnectedCategory) { $this->connectedInvoked = true; - } else if ($status->getCategory() === PNStatusCategory::PNDisconnectedCategory) { + } elseif ($status->getCategory() === PNStatusCategory::PNDisconnectedCategory) { $this->disconnectedInvoked = true; } else { if ($status->getException() !== null) { @@ -92,11 +97,11 @@ 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) { throw new PubNubUnsubscribeException(); } diff --git a/tests/integrational/SubscribeSignalTest.php b/tests/integrational/SubscribeSignalTest.php index 8ee96e1c..3b10c2bb 100644 --- a/tests/integrational/SubscribeSignalTest.php +++ b/tests/integrational/SubscribeSignalTest.php @@ -29,12 +29,18 @@ public function testSignal() "uuid" => "myUUID" ]) ->setResponseStatus("HTTP/1.0 200 OK") - ->setResponseBody('{"t":{"t":"14921661962885137","r":12},"m":[{"a":"5","f":0,"i":"eda482a8-9de3-4891-b328-b2c1d14f210c","p":{"t":"14921661962867845","r":12},"k":"demo","e":1,"c":"test","u":{},"d":{"text":"hey"},"b":"test"}]}'); + ->setResponseBody('{"t":{"t":"14921661962885137","r":12},' + . '"m":[{"a":"5","f":0,"i":"eda482a8-9de3-4891-b328-b2c1d14f210c",' + . '"p":{"t":"14921661962867845","r":12},"k":"demo","e":1,"c":"test","u":{},' + . '"d":{"text":"hey"},"b":"test"}]}'); $callback = new MySubscribeCallbackToTestSignal(); - $pubnub = PubNub::demo(); - $pubnub->getConfiguration()->setTransport($transport)->setUuid("myUUID"); + $config = $this->config->clone(); + $config->setTransport($transport); + $config->setUuid("myUUID"); + + $pubnub = new PubNub($config); $pubnub->addListener($callback); $pubnub->subscribe()->channel("test")->execute(); @@ -43,24 +49,24 @@ public function testSignal() } } - +//phpcs:ignore PSR1.Classes.ClassDeclaration class MySubscribeCallbackToTestSignal extends SubscribeCallback { public $signalInvoked = false; - function status($pubnub, $status) + public function status($pubnub, $status) { } - function message($pubnub, $message) + public function message($pubnub, $message) { } - function presence($pubnub, $presence) + public function presence($pubnub, $presence) { } - function signal($pubnub, $signal) + public function signal($pubnub, $signal) { $this->signalInvoked = true; } diff --git a/tests/integrational/SubscribeWildCardTest.php b/tests/integrational/SubscribeWildCardTest.php index 737f1e23..62e18004 100644 --- a/tests/integrational/SubscribeWildCardTest.php +++ b/tests/integrational/SubscribeWildCardTest.php @@ -6,10 +6,9 @@ use PubNub\Enums\PNStatusCategory; use PubNub\Exceptions\PubNubUnsubscribeException; use PubNub\Models\Consumer\PubSub\PNMessageResult; -use PubNub\Models\ResponseHelpers\PNStatus; -use PubNub\Models\Server\SubscribeMessage; use PubNub\PubNub; use PubNubTestCase; +use PHPUnit\Framework\AssertionFailedError; use Tests\Helpers\StubTransport; class SubscribeWildCardTest extends PubNubTestCase @@ -42,12 +41,17 @@ public function testWildCard() "uuid" => "myUUID" ]) ->setResponseStatus("HTTP/1.0 200 OK") - ->setResponseBody('{"t":{"t":"14921661962885137","r":12},"m":[{"a":"5","f":0,"i":"eda482a8-9de3-4891-b328-b2c1d14f210c","p":{"t":"14921661962867845","r":12},"k":"demo","c":"channels.one","u":{},"d":{"text":"hey"},"b":"channels.*"}]}'); + ->setResponseBody('{"t":{"t":"14921661962885137","r":12},' + . '"m":[{"a":"5","f":0,"i":"eda482a8-9de3-4891-b328-b2c1d14f210c",' + . '"p":{"t":"14921661962867845","r":12},"k":"demo","c":"channels.one","u":{},' + . '"d":{"text":"hey"},"b":"channels.*"}]}'); $callback = new MySubscribeCallbackToTestWildCard(); - $pubnub = PubNub::demo(); - $pubnub->getConfiguration()->setTransport($transport)->setUuid("myUUID"); + $config = $this->config->clone(); + $config->setTransport($transport); + $config->setUuid("myUUID"); + $pubnub = new PubNub($config); $pubnub->addListener($callback); $pubnub->subscribe()->channel("channels.*")->execute(); @@ -57,7 +61,7 @@ public function testWildCard() } } - +//phpcs:ignore PSR1.Classes.ClassDeclaration class MySubscribeCallbackToTestWildCard extends SubscribeCallback { protected $connectedInvoked = false; @@ -68,12 +72,11 @@ public function areBothConnectedAndDisconnectedInvoked() return $this->connectedInvoked && $this->disconnectedInvoked; } - function status($pubnub, $status) + public function status($pubnub, $status) { if ($status->getCategory() === PNStatusCategory::PNConnectedCategory) { $this->connectedInvoked = true; - - } else if ($status->getCategory() === PNStatusCategory::PNDisconnectedCategory) { + } elseif ($status->getCategory() === PNStatusCategory::PNDisconnectedCategory) { $this->disconnectedInvoked = true; } else { if ($status->getException() !== null) { @@ -89,24 +92,27 @@ function status($pubnub, $status) * @param PNMessageResult $message * @throws PubNubUnsubscribeException */ - function message($pubnub, $message) + public function message($pubnub, $message) { if ($message->getChannel() !== 'channels.one') { - throw new \PHPUnit_Framework_AssertionFailedError("Actual channel " . $message->getChannel() . " doesn't match expected channels.one" ); + throw new AssertionFailedError("Actual channel " . $message->getChannel() + . " doesn't match expected channels.one"); } if ($message->getSubscription() !== 'channels.*') { - throw new \PHPUnit_Framework_AssertionFailedError("Actual subscription " . $message->getChannel() . " doesn't match expected channels.one" ); + throw new AssertionFailedError("Actual subscription " . $message->getChannel() + . " doesn't match expected channels.one"); } if ($message->getPublisher() !== 'eda482a8-9de3-4891-b328-b2c1d14f210c') { - throw new \PHPUnit_Framework_AssertionFailedError("Actual uuid " . $message->getPublisher() . " doesn't match expected eda482a8-9de3-4891-b328-b2c1d14f210c"); + throw new AssertionFailedError("Actual uuid " . $message->getPublisher() + . " doesn't match expected eda482a8-9de3-4891-b328-b2c1d14f210c"); } throw new PubNubUnsubscribeException(); } - function presence($pubnub, $presence) + public function presence($pubnub, $presence) { } } diff --git a/tests/integrational/push/ListPushProvisionsEndpointTest.php b/tests/integrational/push/ListPushProvisionsEndpointTest.php index 8a750da9..d22bc811 100644 --- a/tests/integrational/push/ListPushProvisionsEndpointTest.php +++ b/tests/integrational/push/ListPushProvisionsEndpointTest.php @@ -12,9 +12,10 @@ class ListPushProvisionsEndpointTest extends PubNubTestCase { public function testListChannelGroupAPNS() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - - $list = new ListPushProvisionsEndpointExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); + $list = new ListPushProvisionsEndpointExposed($pubnub); $list->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ @@ -33,9 +34,10 @@ public function testListChannelGroupAPNS() public function testListChannelGroupAPNS2() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - - $list = new ListPushProvisionsEndpointExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); + $list = new ListPushProvisionsEndpointExposed($pubnub); $list->stubFor("/v2/push/sub-key/demo/devices-apns2/coolDevice") ->withQuery([ @@ -59,7 +61,10 @@ public function testListChannelGroupFCM() { $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - $list = new ListPushProvisionsEndpointExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); + $list = new ListPushProvisionsEndpointExposed($pubnub); $list->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ @@ -78,9 +83,10 @@ public function testListChannelGroupFCM() public function testListChannelGroupMPNS() { - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - - $list = new ListPushProvisionsEndpointExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); + $list = new ListPushProvisionsEndpointExposed($pubnub); $list->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ @@ -106,9 +112,10 @@ public function testWarningWhenUsingDeprecatedGCMType() $this->expectException(\Exception::class); $this->expectExceptionMessage('GCM is deprecated. Please use FCM instead.'); - $this->pubnub->getConfiguration()->setUuid("sampleUUID"); - - $list = new ListPushProvisionsEndpointExposed($this->pubnub); + $config = $this->config->clone(); + $config->setUuid("sampleUUID"); + $pubnub = new PubNub($config); + $list = new ListPushProvisionsEndpointExposed($pubnub); $list->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ @@ -160,4 +167,3 @@ public function requestOptions() ]; } } -// phpcs:ignore PSR1.Classes.ClassDeclaration