@@ -38,8 +38,6 @@ public function invalid_signatures_can_not_access_the_api()
3838 public function it_returns_the_channel_information ()
3939 {
4040 $ this ->joinPresenceChannel ('presence-channel ' );
41- $ this ->joinPresenceChannel ('presence-channel ' );
42- $ this ->joinPresenceChannel ('presence-channel ' );
4341
4442 $ connection = new Connection ();
4543
@@ -61,9 +59,7 @@ public function it_returns_the_channel_information()
6159
6260 $ this ->assertSame ([
6361 'channels ' => [
64- 'presence-channel ' => [
65- 'user_count ' => 3 ,
66- ],
62+ 'presence-channel ' => [],
6763 ],
6864 ], json_decode ($ response ->getContent (), true ));
6965 }
@@ -96,6 +92,43 @@ public function it_returns_the_channel_information_for_prefix()
9692 /** @var JsonResponse $response */
9793 $ response = array_pop ($ connection ->sentRawData );
9894
95+ $ this ->assertSame ([
96+ 'channels ' => [
97+ 'presence-global.1 ' => [],
98+ 'presence-global.2 ' => [],
99+ ],
100+ ], json_decode ($ response ->getContent (), true ));
101+ }
102+
103+ /** @test */
104+ public function it_returns_the_channel_information_for_prefix_with_user_count ()
105+ {
106+ $ this ->joinPresenceChannel ('presence-global.1 ' );
107+ $ this ->joinPresenceChannel ('presence-global.1 ' );
108+ $ this ->joinPresenceChannel ('presence-global.2 ' );
109+ $ this ->joinPresenceChannel ('presence-notglobal.2 ' );
110+
111+ $ connection = new Connection ();
112+
113+ $ requestPath = '/apps/1234/channels ' ;
114+ $ routeParams = [
115+ 'appId ' => '1234 ' ,
116+ ];
117+
118+ $ queryString = Pusher::build_auth_query_string ('TestKey ' , 'TestSecret ' , 'GET ' , $ requestPath , [
119+ 'filter_by_prefix ' => 'presence-global ' ,
120+ 'info ' => 'user_count ' ,
121+ ]);
122+
123+ $ request = new Request ('GET ' , "{$ requestPath }? {$ queryString }& " .http_build_query ($ routeParams ));
124+
125+ $ controller = app (FetchChannelsController::class);
126+
127+ $ controller ->onOpen ($ connection , $ request );
128+
129+ /** @var JsonResponse $response */
130+ $ response = array_pop ($ connection ->sentRawData );
131+
99132 $ this ->assertSame ([
100133 'channels ' => [
101134 'presence-global.1 ' => [
@@ -108,6 +141,33 @@ public function it_returns_the_channel_information_for_prefix()
108141 ], json_decode ($ response ->getContent (), true ));
109142 }
110143
144+ /** @test */
145+ public function can_not_get_non_presence_channel_user_count ()
146+ {
147+ $ this ->expectException (HttpException::class);
148+ $ this ->expectExceptionMessage ('Request must be limited to presence channels in order to fetch user_count ' );
149+
150+ $ connection = new Connection ();
151+
152+ $ requestPath = '/apps/1234/channels ' ;
153+ $ routeParams = [
154+ 'appId ' => '1234 ' ,
155+ ];
156+
157+ $ queryString = Pusher::build_auth_query_string ('TestKey ' , 'TestSecret ' , 'GET ' , $ requestPath , [
158+ 'info ' => 'user_count ' ,
159+ ]);
160+
161+ $ request = new Request ('GET ' , "{$ requestPath }? {$ queryString }& " .http_build_query ($ routeParams ));
162+
163+ $ controller = app (FetchChannelsController::class);
164+
165+ $ controller ->onOpen ($ connection , $ request );
166+
167+ /** @var JsonResponse $response */
168+ $ response = array_pop ($ connection ->sentRawData );
169+ }
170+
111171 /** @test */
112172 public function it_returns_empty_object_for_no_channels_found ()
113173 {
0 commit comments