Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/PushChannelSubscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,24 @@ public function listChannels (array $params = []) {
$cipher = false, 'GET', $path, $params );
}

/**
* Removes the given channel subscription.
*
* @param string $subscription the id of the device
*/
public function remove ($subscription) {
$params = $subscription->toArray();
$path = '/push/channelSubscriptions';
return $this->ably->delete( $path, [], $params, false );
}

/**
* Removes the channel subscriptions identified by the given parameters.
*
* @param string $subscription the id of the device
*/
public function removeWhere (array $params = []) {
$path = '/push/channelSubscriptions';
return $this->ably->delete( $path, [], $params, false );
}
}
90 changes: 90 additions & 0 deletions tests/PushChannelSubscriptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,94 @@ public function testSaveInvalid($data) {
self::$ably->push->admin->channelSubscriptions->save($data);
}


/**
* RSH1c4
*/
public function testRemove() {
$admin = self::$ably->push->admin;
$channelSubscriptions = $admin->channelSubscriptions;

// Register device
$data = deviceData();
$admin->deviceRegistrations->save($data);
$deviceId = $data['id'];
$clientId = $data['clientId'];

// Remove by device id
$subscription = $channelSubscriptions->save([
'channel' => 'pushenabled:test',
'deviceId' => $deviceId,
]);

$params = ['deviceId' => $deviceId];
$response = $channelSubscriptions->list_($params);
$this->assertEquals(1, count($response->items));
$channelSubscriptions->remove($subscription);
$response = $channelSubscriptions->list_($params);
$this->assertEquals(0, count($response->items));

// Remove by client id
$subscription = $channelSubscriptions->save([
'channel' => 'pushenabled:test',
'clientId' => $clientId,
]);

$params = ['clientId' => $clientId];
$response = $channelSubscriptions->list_($params);
$this->assertEquals(1, count($response->items));
$channelSubscriptions->remove($subscription);
$response = $channelSubscriptions->list_($params);
$this->assertEquals(0, count($response->items));

// Remove again, no error
$channelSubscriptions->remove($subscription);
}


/**
* RSH1c5
*/
public function testRemoveWhere() {
$admin = self::$ably->push->admin;
$channelSubscriptions = $admin->channelSubscriptions;

// Register device
$data = deviceData();
$admin->deviceRegistrations->save($data);
$deviceId = $data['id'];
$clientId = $data['clientId'];

// Remove by device id
$channelSubscriptions->save([
'channel' => 'pushenabled:test',
'deviceId' => $deviceId,
]);

$params = ['deviceId' => $deviceId];
$response = $channelSubscriptions->list_($params);
$this->assertEquals(1, count($response->items));
$channelSubscriptions->removeWhere($params);
sleep(3); // Deletion is async: wait a few seconds
$response = $channelSubscriptions->list_($params);
$this->assertEquals(0, count($response->items));

// Remove by client id
$channelSubscriptions->save([
'channel' => 'pushenabled:test',
'clientId' => $clientId,
]);

$params = ['clientId' => $clientId];
$response = $channelSubscriptions->list_($params);
$this->assertEquals(1, count($response->items));
$channelSubscriptions->removeWhere($params);
sleep(3); // Deletion is async: wait a few seconds
$response = $channelSubscriptions->list_($params);
$this->assertEquals(0, count($response->items));

// Remove again, no error
$channelSubscriptions->removeWhere($params);
}

}