Skip to content

Commit

Permalink
Merge pull request #7 from GedConk/master
Browse files Browse the repository at this point in the history
Fix the call to $service->trigger() with no socketId
  • Loading branch information
bakura10 committed Jul 23, 2015
2 parents 1f2b1f5 + 329b50c commit a53fa42
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/ZfrPusher/Service/PusherService.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,11 @@ public function getClient()
* @param bool $async If true, the request is performed asynchronously
* @return void
*/
public function trigger($channels, $event, array $data = array(), $socketId = '', $async = false)
public function trigger($channels, $event, array $data = array(), $socketId = null, $async = false)
{
$parameters = array(
'event' => $event,
'data' => $data,
'socket_id' => $socketId
'data' => $data
);

if (is_string($channels)) {
Expand All @@ -97,6 +96,10 @@ public function trigger($channels, $event, array $data = array(), $socketId = ''
$parameters['channels'] = $channels;
}

if(!empty($socketId)){
$parameters['socket_id'] = $socketId;
}

if ($async) {
$this->client->addSubscriber($this->asyncPlugin);
}
Expand All @@ -121,7 +124,7 @@ public function trigger($channels, $event, array $data = array(), $socketId = ''
* @param string $socketId Exclude a specific socket id from the event
* @return void
*/
public function triggerAsync($channels, $event, array $data = array(), $socketId = '')
public function triggerAsync($channels, $event, array $data = array(), $socketId = null)
{
$this->trigger($event, $channels, $data, $socketId, true);
}
Expand Down
43 changes: 39 additions & 4 deletions tests/ZfrPusherTest/Service/PusherServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,43 @@ public function testTriggerAsyncAddAsyncPlugin()
$this->service->triggerAsync('my-channel', 'my-event', array(), '');
}

/**
* @covers PusherService::trigger
*/
public function testTriggerWithSocketIdEmpty()
{
$expectedParameters = array(
'event' => 'my-event',
'channel' => 'my-channel',
'data' => array()
);

$this->client->expects($this->once())
->method('trigger')
->with($expectedParameters);

$this->service->trigger('my-channel', 'my-event', array(), '');
}

/**
* @covers PusherService::trigger
*/
public function testTriggerWithSocketId()
{
$expectedParameters = array(
'event' => 'my-event',
'channel' => 'my-channel',
'data' => array(),
'socket_id' => '123.123'
);

$this->client->expects($this->once())
->method('trigger')
->with($expectedParameters);

$this->service->trigger('my-channel', 'my-event', array(), '123.123');
}

/**
* @covers PusherService::trigger
*/
Expand All @@ -103,8 +140,7 @@ public function testTriggerUseChannelIfString()
$expectedParameters = array(
'event' => 'my-event',
'channel' => 'my-channel',
'data' => array(),
'socket_id' => ''
'data' => array()
);

$this->client->expects($this->once())
Expand All @@ -122,8 +158,7 @@ public function testTriggerUseChannelsIfArray()
$expectedParameters = array(
'event' => 'my-event',
'channels' => array('my-channel-1', 'my-channel-2'),
'data' => array(),
'socket_id' => ''
'data' => array()
);

$this->client->expects($this->once())
Expand Down

0 comments on commit a53fa42

Please sign in to comment.