Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor/
composer.lock
.DS_Store
.idea/
17 changes: 11 additions & 6 deletions library/Pushy/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class User
/**
* User's device name
*
* @var string
* @var array
*/
protected $deviceName;
protected $deviceName = array();

/**
* Instantiate a user object
Expand All @@ -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);
}
}

/**
Expand Down Expand Up @@ -79,7 +82,7 @@ public function setId($id)
*/
public function getDeviceName()
{
return $this->deviceName;
return implode(',', $this->deviceName);
}

/**
Expand All @@ -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;
}
Expand Down
17 changes: 17 additions & 0 deletions tests/Pushy/Test/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down