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..3950f4d 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 @@ -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); + } } /** @@ -79,7 +82,7 @@ public function setId($id) */ public function getDeviceName() { - return $this->deviceName; + return implode(',', $this->deviceName); } /** @@ -98,8 +101,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; } 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 *