Skip to content

Commit

Permalink
fix test and linter
Browse files Browse the repository at this point in the history
  • Loading branch information
seba-aln committed Feb 3, 2025
1 parent a9248d2 commit e3f42ee
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/PubNub/Endpoints/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function validateSubscribeKey()
{
$subscribeKey = $this->pubnub->getConfiguration()->getSubscribeKey();

if ($subscribeKey == null || empty($subscribeKey)) {
if (strlen($subscribeKey) === 0) {
throw new PubNubValidationException("Subscribe Key not configured");
}
}
Expand All @@ -142,7 +142,7 @@ protected function validatePublishKey()
{
$publishKey = $this->pubnub->getConfiguration()->getPublishKey();

if ($publishKey == null || empty($publishKey)) {
if (strlen($publishKey) === 0) {
throw new PubNubValidationException("Publish Key not configured");
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/PubNub/Endpoints/Objects/Member/ManageMembers.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public function includeFields($include)

/**
* @throws PubNubValidationException
* @return void
*/
protected function validateParams()
{
Expand Down Expand Up @@ -214,7 +215,7 @@ protected function buildPath()
}

/**
* @param array $result Decoded json
* @param mixed $result Decoded json
* @return PNMembersResult
*/
protected function createResponse($result): PNMembersResult
Expand All @@ -228,7 +229,7 @@ public function sync(): PNMembersResult
}

/**
* @return array
* @return string[]
*/
protected function customParams()
{
Expand Down
22 changes: 12 additions & 10 deletions src/PubNub/Endpoints/Objects/Membership/ManageMemberships.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PubNub\Enums\PNHttpMethod;
use PubNub\Enums\PNOperationType;
use PubNub\Exceptions\PubNubValidationException;
use PubNub\Exceptions\PubNubBuildRequestException;
use PubNub\Models\Consumer\Objects\Membership\PNMembershipIncludes;
use PubNub\Models\Consumer\Objects\Membership\PNChannelMembership;
use PubNub\Models\Consumer\Objects\Membership\PNMembershipsResult;
Expand Down Expand Up @@ -40,10 +41,10 @@ class ManageMemberships extends ObjectsCollectionEndpoint
protected ?PNMembershipIncludes $includes;

/** @var ?PNChannelMembership[] */
protected array $setMemberships;
protected ?array $setMemberships;

/** @var ?PNChannelMembership[] */
protected array $removeMemberships;
protected ?array $removeMemberships;

/**
* @param PubNub $pubnubInstance
Expand Down Expand Up @@ -76,7 +77,7 @@ public function userId($userId): self
}

/**
* @param array $channels
* @param mixed $channels
* @deprecated Use memberships() method
*
* @return $this
Expand All @@ -88,7 +89,7 @@ public function setChannels($channels): self
}

/**
* @param array $channels
* @param mixed $channels
* @deprecated Use memberships() method
*
* @return $this
Expand All @@ -100,7 +101,7 @@ public function removeChannels($channels): self
}

/**
* @param PNChannelMemberhips[] $members
* @param PNChannelMembership[] $memberships
* @return $this
*/
public function setMemberships(array $memberships): self
Expand All @@ -110,7 +111,7 @@ public function setMemberships(array $memberships): self
}

/**
* @param PNChannelMemberhips[] $members
* @param PNChannelMembership[] $memberships
* @return $this
*/
public function removeMemberships(array $memberships): self
Expand All @@ -120,7 +121,7 @@ public function removeMemberships(array $memberships): self
}

/**
* @param array $custom
* @param mixed $custom
* @deprecated Use members() method
*
* @return $this
Expand All @@ -132,7 +133,7 @@ public function custom($custom): self
}

/**
* @param array $include
* @param string[] $include
* @deprecated Use includes() method
*
* @return $this
Expand Down Expand Up @@ -162,6 +163,7 @@ public function include(PNMembershipIncludes $includes): self

/**
* @throws PubNubValidationException
* @return void
*/
protected function validateParams()
{
Expand Down Expand Up @@ -236,7 +238,7 @@ public function sync(): PNMembershipsResult
}

/**
* @param array $result Decoded json
* @param mixed $result Decoded json
* @return PNMembershipsResult
*/
protected function createResponse($result): PNMembershipsResult
Expand All @@ -245,7 +247,7 @@ protected function createResponse($result): PNMembershipsResult
}

/**
* @return array
* @return string[]
*/
protected function customParams()
{
Expand Down
6 changes: 3 additions & 3 deletions src/PubNub/Endpoints/Objects/Membership/RemoveMemberships.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RemoveMemberships extends ObjectsCollectionEndpoint
/** @var PNMembershipIncludes */
protected ?PNMembershipIncludes $includes;

/** @var ?PNChannelMembership[] */
/** @var PNChannelMembership[] */
protected array $memberships;

/**
Expand All @@ -58,7 +58,7 @@ public function uuid(string $uuid): self
}

/**
* @param string $uuid
* @param string $userId
* @return $this
*/
public function userId(string $userId): self
Expand All @@ -81,7 +81,7 @@ public function channels($channels): self
}

/**
* @param PNChannelMemberhips[] $members
* @param PNChannelMembership[] $memberships
* @return $this
*/
public function memberships(array $memberships): self
Expand Down
4 changes: 2 additions & 2 deletions src/PubNub/Endpoints/Objects/Membership/SetMemberships.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SetMemberships extends ObjectsCollectionEndpoint
/** @var PNMembershipIncludes */
protected ?PNMembershipIncludes $includes;

/** @var ?PNChannelMembership[] */
/** @var PNChannelMembership[] */
protected array $memberships;

/**
Expand Down Expand Up @@ -82,7 +82,7 @@ public function channels($channels): self
}

/**
* @param PNChannelMemberhips[] $members
* @param PNChannelMembership[] $memberships
* @return $this
*/
public function memberships(array $memberships): self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getNext()
}

/**
* @return array
* @return array | \StdClass
*/
public function getData()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getChannel()
}

/**
* @return array
* @return array | \StdClass
*/
public function getCustom()
{
Expand Down Expand Up @@ -92,6 +92,7 @@ public function getETag()

public function __toString()
{
$data_string = '';
if (!empty($data)) {
$data_string = json_encode($data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ public function testGetMembersForChannel()

$response = $this->pubnub_pam->getMembers()
->channel("ch")
->includeFields([ "totalCount" => true, "customFields" => true, "customChannelFields" => true, "channelFields" => true ])
->includeFields([
"totalCount" => true,
"customFields" => true,
"customChannelFields" => true,
"channelFields" => true,
])
->sync();

$this->assertNotEmpty($response);
Expand Down
9 changes: 5 additions & 4 deletions tests/integrational/objects/member/MembersHappyPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ public function testHappyPath(): void
array_push($staleMembers, new PNChannelMember($member->getUser()->getId()));
}

$this->pubnub->removeMembers()
->channel($this->channel)
->members($staleMembers)
->sync();
if (!empty($staleMembers)) {
$cleanup = $this->pubnub->removeMembers()->channel($this->channel)->members($staleMembers)->sync();
$this->assertInstanceOf(PNSetChannelMetadataResult::class, $cleanup);
$this->assertCount(0, $cleanup->getData());
}

$channelSetup = $this->pubnub->setChannelMetadata()
->channel($this->channel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ public function testSetMembersForChannel()
"a" => "aa",
"b" => "bb",
])
->includeFields([ "totalCount" => true, "customFields" => true, "customChannelFields" => true, "channelFields" => true ])
->includeFields([
"totalCount" => true,
"customFields" => true,
"customChannelFields" => true,
"channelFields" => true,
])
->sync();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ public function testGetMemberships()

$response = $this->pubnub_pam->getMemberships()
->uuid("uuid")
->includeFields([ "totalCount" => true, "customFields" => true, "customUUIDFields" => true, "UUIDFields" => true ])
->includeFields([
"totalCount" => true,
"customFields" => true,
"customUUIDFields" => true,
"UUIDFields" => true,
])
->sync();

$this->assertNotEmpty($response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ public function testHappyPath(): void
foreach ($getStaleMemberships->getData() as $membership) {
array_push($staleMemberships, new PNChannelMembership($membership->getChannel()->getId()));
}
$cleanup = $this->pubnub->removeMemberships()->userId($this->user)->memberships($staleMemberships)->sync();
$this->assertInstanceOf(PNMembershipsResult::class, $cleanup);
$this->assertCount(0, $cleanup->getData());
if (!empty($staleMemberships)) {
$cleanup = $this->pubnub->removeMemberships()->userId($this->user)->memberships($staleMemberships)->sync();
$this->assertInstanceOf(PNMembershipsResult::class, $cleanup);
$this->assertCount(0, $cleanup->getData());
}

$includes = new PNMembershipIncludes();
$includes->channel()->channelId()->channelCustom()->channelType()->channelStatus()->custom()->status()->type();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ public function testSetMembershipsForChannel()
"a" => "aa",
"b" => "bb",
])
->includeFields([ "totalCount" => true, "customFields" => true, "customChannelFields" => true, "channelFields" => true ])
->includeFields([
"totalCount" => true,
"customFields" => true,
"customChannelFields" => true,
"channelFields" => true
])
->sync();


Expand Down

0 comments on commit e3f42ee

Please sign in to comment.