Merge pull request #40 from stayallive/fix-empty-channels-response

Fix Pusher lib expecting empty object not array
This commit is contained in:
Marcel Pociot 2018-12-09 11:07:12 +01:00 committed by GitHub
commit efbeb18995
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -25,7 +25,7 @@ class FetchChannelsController extends Controller
return [ return [
'user_count' => count($channel->getUsers()), 'user_count' => count($channel->getUsers()),
]; ];
})->toArray(), })->toArray() ?: new \stdClass,
]; ];
} }
} }

View File

@ -80,4 +80,35 @@ class FetchChannelsTest extends TestCase
], ],
], json_decode($response->getContent(), true)); ], json_decode($response->getContent(), true));
} }
/** @test */
public function it_returns_empty_object_for_no_channels_found()
{
$connection = new Connection();
$auth_key = 'TestKey';
$auth_timestamp = time();
$auth_version = '1.0';
$queryParameters = http_build_query(compact('auth_key', 'auth_timestamp', 'auth_version'));
$signature =
"GET\n/apps/1234/channels\n".
"auth_key={$auth_key}".
"&auth_timestamp={$auth_timestamp}".
"&auth_version={$auth_version}";
$auth_signature = hash_hmac('sha256', $signature, 'TestSecret');
$request = new Request('GET', "/apps/1234/channels?appId=1234&auth_signature={$auth_signature}&{$queryParameters}");
$controller = app(FetchChannelsController::class);
$controller->onOpen($connection, $request);
/** @var JsonResponse $response */
$response = array_pop($connection->sentRawData);
$this->assertSame('{"channels":{}}', $response->getContent());
}
} }