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
14 changes: 14 additions & 0 deletions src/PushDeviceRegistrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,18 @@ public function save ( $device ) {
return new DeviceDetails ( $body );
}

/**
* Returns a DeviceDetails object if the device id is found or results in
* a not found error if the device cannot be found.
*
* @param string $deviceId the id of the device
*/
public function get ($deviceId) {
$path = '/push/deviceRegistrations/' . $deviceId;
$body = $this->ably->get( $path );
$body = json_decode(json_encode($body), true); // Convert stdClass to array
return new DeviceDetails ( $body );
}


}
70 changes: 41 additions & 29 deletions tests/PushDeviceRegistrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ function random_string ( $n ) {
return bin2hex(openssl_random_pseudo_bytes($n / 2));
}

function data () {
return [
'id' => random_string(26),
'clientId' => random_string(12),
'platform' => 'ios',
'formFactor' => 'phone',
'push' => [
'recipient' => [
'transportType' => 'apns',
'deviceToken' => '740f4707bebcf74f9b7c25d48e3358945f6aa01da5ddb387462c7eaf61bb78ad'
]
],
'deviceSecret' => random_string(12),
];
}


class PushDeviceRegistrationsTest extends \PHPUnit_Framework_TestCase {
protected static $testApp;
protected static $defaultOptions;
Expand All @@ -28,23 +45,31 @@ public static function tearDownAfterClass() {
self::$testApp->release();
}

/**
* RSH1b1
*/
public function testGet() {
// Save
$data = data();
self::$ably->push->admin->deviceRegistrations->save($data);

// Found
$deviceDetails = self::$ably->push->admin->deviceRegistrations->get($data['id']);
$this->assertEquals($data['id'], $deviceDetails->id);
$this->assertEquals($data['platform'], $deviceDetails->platform);
$this->assertEquals($data['formFactor'], $deviceDetails->formFactor);
$this->assertEquals($data['deviceSecret'], $deviceDetails->deviceSecret);

// Not Found
$this->expectException(AblyException::class);
self::$ably->push->admin->deviceRegistrations->get("not-found");
}

/**
* RSH1b3
*/
public function testAdminDeviceRegistrationsSave() {
$data = [
'id' => random_string(26),
'clientId' => random_string(12),
'platform' => 'ios',
'formFactor' => 'phone',
'push' => [
'recipient' => [
'transportType' => 'apns',
'deviceToken' => '740f4707bebcf74f9b7c25d48e3358945f6aa01da5ddb387462c7eaf61bb78ad'
]
],
'deviceSecret' => random_string(12),
];
public function testSave() {
$data = data();

// Create
$deviceDetails = self::$ably->push->admin->deviceRegistrations->save($data);
Expand All @@ -62,20 +87,7 @@ public function testAdminDeviceRegistrationsSave() {
}

public function badValues() {
$data = [
'id' => random_string(26),
'clientId' => random_string(12),
'platform' => 'ios',
'formFactor' => 'phone',
'push' => [
'recipient' => [
'transportType' => 'apns',
'deviceToken' => '740f4707bebcf74f9b7c25d48e3358945f6aa01da5ddb387462c7eaf61bb78ad'
]
],
'deviceSecret' => random_string(12),
];

$data = data();
return [
[
array_merge($data, [
Expand All @@ -91,7 +103,7 @@ public function badValues() {
* @dataProvider badValues
* @expectedException Ably\Exceptions\AblyRequestException
*/
public function testAdminDeviceRegistrationsSaveInvalid($data) {
public function testSaveInvalid($data) {
self::$ably->push->admin->deviceRegistrations->save($data);
}

Expand Down