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 e97a2c92..d70858b3 100755 --- a/src/PubNub/PNConfiguration.php +++ b/src/PubNub/PNConfiguration.php @@ -217,6 +217,9 @@ public function setOrigin($origin): self */ public function getSubscribeKey(): string { + if (!isset($this->subscribeKey)) { + throw new PubNubValidationException("Subscribe Key not configured"); + } return $this->subscribeKey; } 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/integrational/GetStateTest.php b/tests/integrational/GetStateTest.php index b6173dcb..b28d6421 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,12 @@ public function testMissingChannelAndGroup() public function testIsAuthRequiredSuccess() { - $getState = new GetStateExposed($this->pubnub); + $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,50 +204,53 @@ 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(); } @@ -249,7 +267,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..b37d5e1a 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(); @@ -240,7 +257,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 +273,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 +286,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 +302,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,9 +314,10 @@ 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(); } @@ -307,7 +334,7 @@ public function testSuperCallTest() } } - +// phpcs:ignore PSR1.Classes.ClassDeclaration class HereNowExposed extends HereNow { protected $transport; diff --git a/tests/integrational/HistoryTest.php b/tests/integrational/HistoryTest.php index d7a10fdf..409bce4e 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) @@ -434,6 +441,7 @@ public function testSuperCallTest() } } +// phpcs:ignore PSR1.Classes.ClassDeclaration class HistoryExposed extends History { protected $transport; diff --git a/tests/integrational/ListPushProvisionsTest.php b/tests/integrational/ListPushProvisionsTest.php index 89e51d18..184abc9f 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" => "myUserId" ]) ->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" => "myUserId" ]) ->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" => "myUserId" ]) ->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" => "myUserId" ]) ->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/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