Skip to content

Commit

Permalink
[1.x] Adds exists() method to ChannelManager (#149)
Browse files Browse the repository at this point in the history
* Add exists() method to ChannelManager

* formatting

* formatting

* Update ChannelManager.php

* Update ArrayChannelManager.php

---------

Co-authored-by: Joe Dixon <[email protected]>
Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
3 people authored Apr 15, 2024
1 parent d07a576 commit 371aefd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Protocols/Pusher/Contracts/ChannelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public function for(Application $application): ChannelManager;
*/
public function all(): array;

/**
* Determine whether the given channel exists.
*/
public function exists(string $channel): bool;

/**
* Find the given channel.
*/
Expand Down
8 changes: 8 additions & 0 deletions src/Protocols/Pusher/Managers/ArrayChannelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public function all(): array
return $this->channels();
}

/**
* Determine whether the given channel exists.
*/
public function exists(string $channel): bool
{
return isset($this->applications[$this->application->id()][$channel]);
}

/**
* Find the given channel
*/
Expand Down
7 changes: 7 additions & 0 deletions tests/Unit/Protocols/Pusher/Managers/ChannelManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
expect($this->channelManager->all())->toHaveCount(4);
});

it('can determine whether a channel exists', function () {
$this->channelManager->findOrCreate('test-channel-1');

expect($this->channelManager->exists('test-channel-1'))->toBeTrue();
expect($this->channelManager->exists('test-channel-2'))->toBeFalse();
});

it('can get all connections subscribed to a channel', function () {
$connections = collect(factory(5))
->each(fn ($connection) => $this->channel->subscribe($connection->connection()));
Expand Down

0 comments on commit 371aefd

Please sign in to comment.