Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit efbeb18

Browse files
authored
Merge pull request #40 from stayallive/fix-empty-channels-response
Fix Pusher lib expecting empty object not array
2 parents ecf0fe4 + 0a0c124 commit efbeb18

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/HttpApi/Controllers/FetchChannelsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __invoke(Request $request)
2525
return [
2626
'user_count' => count($channel->getUsers()),
2727
];
28-
})->toArray(),
28+
})->toArray() ?: new \stdClass,
2929
];
3030
}
3131
}

tests/HttpApi/FetchChannelsTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,35 @@ public function it_returns_the_channel_information()
8080
],
8181
], json_decode($response->getContent(), true));
8282
}
83+
84+
/** @test */
85+
public function it_returns_empty_object_for_no_channels_found()
86+
{
87+
$connection = new Connection();
88+
89+
$auth_key = 'TestKey';
90+
$auth_timestamp = time();
91+
$auth_version = '1.0';
92+
93+
$queryParameters = http_build_query(compact('auth_key', 'auth_timestamp', 'auth_version'));
94+
95+
$signature =
96+
"GET\n/apps/1234/channels\n".
97+
"auth_key={$auth_key}".
98+
"&auth_timestamp={$auth_timestamp}".
99+
"&auth_version={$auth_version}";
100+
101+
$auth_signature = hash_hmac('sha256', $signature, 'TestSecret');
102+
103+
$request = new Request('GET', "/apps/1234/channels?appId=1234&auth_signature={$auth_signature}&{$queryParameters}");
104+
105+
$controller = app(FetchChannelsController::class);
106+
107+
$controller->onOpen($connection, $request);
108+
109+
/** @var JsonResponse $response */
110+
$response = array_pop($connection->sentRawData);
111+
112+
$this->assertSame('{"channels":{}}', $response->getContent());
113+
}
83114
}

0 commit comments

Comments
 (0)