Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
fix shouldPushToDescriptor in pusher
Browse files Browse the repository at this point in the history
  • Loading branch information
albertcht committed Mar 9, 2019
1 parent 06ad668 commit 4d28803
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/Websocket/Pusher.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,11 @@ protected function getWebsocketConnections(): array
*/
public function shouldPushToDescriptor(int $fd): bool
{
return $this->server->exist($fd)
&& ($this->broadcast && $this->sender !== (int) $fd);
if (! $this->server->exist($fd)) {
return false;
}

return $this->broadcast ? $this->sender !== (int) $fd : true;
}

/**
Expand Down
14 changes: 13 additions & 1 deletion tests/Websocket/PusherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function testShouldPushToDescriptor()
$server = m::mock(Server::class);
$server->shouldReceive('exist')
->with($fd = 1)
->twice()
->times(3)
->andReturn(true);

$pusher = Pusher::make([
Expand All @@ -141,5 +141,17 @@ public function testShouldPushToDescriptor()
], $server);

$this->assertFalse($pusher->shouldPushToDescriptor($fd));

$pusher = Pusher::make([
'opcode' => 1,
'sender' => 1,
'fds' => [],
'broadcast' => false,
'assigned' => false,
'event' => 'event',
'message' => 'message'
], $server);

$this->assertTrue($pusher->shouldPushToDescriptor($fd));
}
}

0 comments on commit 4d28803

Please sign in to comment.