From b87eb38a6ca5294b9ebc8dcdf0ced437785cf391 Mon Sep 17 00:00:00 2001 From: simivar Date: Thu, 11 May 2017 13:11:34 +0200 Subject: [PATCH 1/3] Posibility to set multiple devices for one user --- .gitignore | 1 + library/Pushy/User.php | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 8db156e..2bc033f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ vendor/ composer.lock .DS_Store +.idea/ diff --git a/library/Pushy/User.php b/library/Pushy/User.php index c2aa5ec..259124e 100644 --- a/library/Pushy/User.php +++ b/library/Pushy/User.php @@ -24,9 +24,9 @@ class User /** * User's device name * - * @var string + * @var array */ - protected $deviceName; + protected $deviceName = array(); /** * Instantiate a user object @@ -79,7 +79,7 @@ public function setId($id) */ public function getDeviceName() { - return $this->deviceName; + return implode(',', $this->deviceName); } /** @@ -98,8 +98,10 @@ public function setDeviceName($deviceName) . ' and contain character set [A-Za-z0-9-]' ); } - - $this->deviceName = (string) $deviceName; + + if (!in_array($deviceName, $this->deviceName)) { + $this->deviceName[] = (string) $deviceName; + } return $this; } From 56fc9690db21c255a3d05083c5d82cb8383ef292 Mon Sep 17 00:00:00 2001 From: simivar Date: Thu, 11 May 2017 13:22:28 +0200 Subject: [PATCH 2/3] Add test case --- tests/Pushy/Test/UserTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/Pushy/Test/UserTest.php b/tests/Pushy/Test/UserTest.php index 36c19f6..81af702 100644 --- a/tests/Pushy/Test/UserTest.php +++ b/tests/Pushy/Test/UserTest.php @@ -75,6 +75,23 @@ public function testGetSetDeviceName() $this->assertEquals($deviceName, $this->user->getDeviceName()); } + /** + * Test: Get/Set Multiple Device Name + * + * @covers \Pushy\User::getDeviceName + * @covers \Pushy\User::setDeviceName + */ + public function testGetSetMultipleDeviceName() + { + $deviceName = 'test-device'; + $deviceName2 = 'my-test'; + + $this->user->setDeviceName($deviceName) + ->setDeviceName($deviceName2); + + $this->assertEquals($deviceName . ',' . $deviceName2, $this->user->getDeviceName()); + } + /** * Test: Set device name with an invalid value * From 9d11f1a09848c01e5bfb0785a08227a39e22ca55 Mon Sep 17 00:00:00 2001 From: simivar Date: Thu, 11 May 2017 13:26:52 +0200 Subject: [PATCH 3/3] Fix setDeviceName in __construct() --- library/Pushy/User.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/Pushy/User.php b/library/Pushy/User.php index 259124e..3950f4d 100644 --- a/library/Pushy/User.php +++ b/library/Pushy/User.php @@ -38,7 +38,10 @@ public function __construct($id = null, $deviceName = null) { // Set user Id and device $this->setId($id); - $this->setDeviceName($deviceName); + + if ($deviceName) { + $this->setDeviceName($deviceName); + } } /**