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

Fix tests for Pusher V6 and V7 #895

Merged
merged 1 commit into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions tests/FetchChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use BeyondCode\LaravelWebSockets\API\FetchChannel;
use GuzzleHttp\Psr7\Request;
use Illuminate\Http\JsonResponse;
use Pusher\Pusher;
use Symfony\Component\HttpKernel\Exception\HttpException;

class FetchChannelTest extends TestCase
Expand All @@ -24,7 +23,7 @@ public function test_invalid_signatures_can_not_access_the_api()
'channelName' => 'my-channel',
];

$queryString = Pusher::build_auth_query_string(
$queryString = self::build_auth_query_string(
'TestKey', 'InvalidSecret', 'GET', $requestPath
);

Expand All @@ -48,7 +47,7 @@ public function test_it_returns_the_channel_information()
'channelName' => 'my-channel',
];

$queryString = Pusher::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath);
$queryString = self::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath);

$request = new Request('GET', "{$requestPath}?{$queryString}&".http_build_query($routeParams));

Expand Down Expand Up @@ -79,7 +78,7 @@ public function test_it_returns_presence_channel_information()
'channelName' => 'presence-channel',
];

$queryString = Pusher::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath);
$queryString = self::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath);

$request = new Request('GET', "{$requestPath}?{$queryString}&".http_build_query($routeParams));

Expand Down Expand Up @@ -113,7 +112,7 @@ public function test_it_returns_404_for_invalid_channels()
'channelName' => 'invalid-channel',
];

$queryString = Pusher::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath);
$queryString = self::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath);

$request = new Request('GET', "{$requestPath}?{$queryString}&".http_build_query($routeParams));

Expand Down
13 changes: 6 additions & 7 deletions tests/FetchChannelsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use BeyondCode\LaravelWebSockets\API\FetchChannels;
use GuzzleHttp\Psr7\Request;
use Illuminate\Http\JsonResponse;
use Pusher\Pusher;
use Symfony\Component\HttpKernel\Exception\HttpException;

class FetchChannelsTest extends TestCase
Expand All @@ -23,7 +22,7 @@ public function test_invalid_signatures_can_not_access_the_api()
'appId' => '1234',
];

$queryString = Pusher::build_auth_query_string(
$queryString = self::build_auth_query_string(
'TestKey', 'InvalidSecret', 'GET', $requestPath
);

Expand All @@ -46,7 +45,7 @@ public function test_it_returns_the_channel_information()
'appId' => '1234',
];

$queryString = Pusher::build_auth_query_string(
$queryString = self::build_auth_query_string(
'TestKey', 'TestSecret', 'GET', $requestPath
);

Expand Down Expand Up @@ -81,7 +80,7 @@ public function test_it_returns_the_channel_information_for_prefix()
'appId' => '1234',
];

$queryString = Pusher::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath, [
$queryString = self::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath, [
'filter_by_prefix' => 'presence-global',
]);

Expand Down Expand Up @@ -117,7 +116,7 @@ public function test_it_returns_the_channel_information_for_prefix_with_user_cou
'appId' => '1234',
];

$queryString = Pusher::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath, [
$queryString = self::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath, [
'filter_by_prefix' => 'presence-global',
'info' => 'user_count',
]);
Expand Down Expand Up @@ -156,7 +155,7 @@ public function test_can_not_get_non_presence_channel_user_count()
'appId' => '1234',
];

$queryString = Pusher::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath, [
$queryString = self::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath, [
'info' => 'user_count',
]);

Expand All @@ -180,7 +179,7 @@ public function test_it_returns_empty_object_for_no_channels_found()
'appId' => '1234',
];

$queryString = Pusher::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath);
$queryString = self::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath);

$request = new Request('GET', "{$requestPath}?{$queryString}&".http_build_query($routeParams));

Expand Down
11 changes: 5 additions & 6 deletions tests/FetchUsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use BeyondCode\LaravelWebSockets\API\FetchUsers;
use GuzzleHttp\Psr7\Request;
use Pusher\Pusher;
use Symfony\Component\HttpKernel\Exception\HttpException;

class FetchUsersTest extends TestCase
Expand All @@ -23,7 +22,7 @@ public function test_invalid_signatures_can_not_access_the_api()
'channelName' => 'my-channel',
];

$queryString = Pusher::build_auth_query_string(
$queryString = self::build_auth_query_string(
'TestKey', 'InvalidSecret', 'GET', $requestPath
);

Expand All @@ -50,7 +49,7 @@ public function test_it_only_returns_data_for_presence_channels()
'channelName' => 'my-channel',
];

$queryString = Pusher::build_auth_query_string(
$queryString = self::build_auth_query_string(
'TestKey', 'TestSecret', 'GET', $requestPath
);

Expand All @@ -77,7 +76,7 @@ public function test_it_returns_404_for_invalid_channels()
'channelName' => 'invalid-channel',
];

$queryString = Pusher::build_auth_query_string(
$queryString = self::build_auth_query_string(
'TestKey', 'TestSecret', 'GET', $requestPath
);

Expand All @@ -101,7 +100,7 @@ public function test_it_returns_connected_user_information()
'channelName' => 'presence-channel',
];

$queryString = Pusher::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath);
$queryString = self::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath);

$request = new Request('GET', "{$requestPath}?{$queryString}&".http_build_query($routeParams));

Expand Down Expand Up @@ -131,7 +130,7 @@ public function test_multiple_clients_with_same_id_gets_counted_once()
'channelName' => 'presence-channel',
];

$queryString = Pusher::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath);
$queryString = self::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath);

$request = new Request('GET', "{$requestPath}?{$queryString}&".http_build_query($routeParams));

Expand Down
7 changes: 3 additions & 4 deletions tests/PresenceChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use BeyondCode\LaravelWebSockets\Server\Exceptions\InvalidSignature;
use GuzzleHttp\Psr7\Request;
use Illuminate\Http\JsonResponse;
use Pusher\Pusher;
use Ratchet\ConnectionInterface;

class PresenceChannelTest extends TestCase
Expand Down Expand Up @@ -419,7 +418,7 @@ public function test_it_fires_the_event_to_presence_channel()
'appId' => '1234',
];

$queryString = Pusher::build_auth_query_string(
$queryString = self::build_auth_query_string(
'TestKey', 'TestSecret', 'POST', $requestPath, [
'name' => 'some-event',
'channels' => ['presence-channel'],
Expand Down Expand Up @@ -460,7 +459,7 @@ public function test_it_fires_event_across_servers_when_there_are_not_users_loca
'appId' => '1234',
];

$queryString = Pusher::build_auth_query_string(
$queryString = self::build_auth_query_string(
'TestKey', 'TestSecret', 'POST', $requestPath, [
'name' => 'some-event',
'channels' => ['presence-channel'],
Expand Down Expand Up @@ -508,7 +507,7 @@ public function test_it_fires_event_across_servers_when_there_are_users_locally_
'appId' => '1234',
];

$queryString = Pusher::build_auth_query_string(
$queryString = self::build_auth_query_string(
'TestKey', 'TestSecret', 'POST', $requestPath, [
'name' => 'some-event',
'channels' => ['presence-channel'],
Expand Down
7 changes: 3 additions & 4 deletions tests/PrivateChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use BeyondCode\LaravelWebSockets\Server\Exceptions\InvalidSignature;
use GuzzleHttp\Psr7\Request;
use Illuminate\Http\JsonResponse;
use Pusher\Pusher;
use Ratchet\ConnectionInterface;

class PrivateChannelTest extends TestCase
Expand Down Expand Up @@ -239,7 +238,7 @@ public function test_it_fires_the_event_to_private_channel()
'appId' => '1234',
];

$queryString = Pusher::build_auth_query_string(
$queryString = self::build_auth_query_string(
'TestKey', 'TestSecret', 'POST', $requestPath, [
'name' => 'some-event',
'channels' => ['private-channel'],
Expand Down Expand Up @@ -280,7 +279,7 @@ public function test_it_fires_event_across_servers_when_there_are_not_users_loca
'appId' => '1234',
];

$queryString = Pusher::build_auth_query_string(
$queryString = self::build_auth_query_string(
'TestKey', 'TestSecret', 'POST', $requestPath, [
'name' => 'some-event',
'channels' => ['private-channel'],
Expand Down Expand Up @@ -328,7 +327,7 @@ public function test_it_fires_event_across_servers_when_there_are_users_locally_
'appId' => '1234',
];

$queryString = Pusher::build_auth_query_string(
$queryString = self::build_auth_query_string(
'TestKey', 'TestSecret', 'POST', $requestPath, [
'name' => 'some-event',
'channels' => ['private-channel'],
Expand Down
7 changes: 3 additions & 4 deletions tests/PublicChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use BeyondCode\LaravelWebSockets\API\TriggerEvent;
use GuzzleHttp\Psr7\Request;
use Illuminate\Http\JsonResponse;
use Pusher\Pusher;
use Ratchet\ConnectionInterface;

class PublicChannelTest extends TestCase
Expand Down Expand Up @@ -220,7 +219,7 @@ public function test_it_fires_the_event_to_public_channel()
'appId' => '1234',
];

$queryString = Pusher::build_auth_query_string(
$queryString = self::build_auth_query_string(
'TestKey', 'TestSecret', 'POST', $requestPath, [
'name' => 'some-event',
'channels' => ['public-channel'],
Expand Down Expand Up @@ -261,7 +260,7 @@ public function test_it_fires_event_across_servers_when_there_are_not_users_loca
'appId' => '1234',
];

$queryString = Pusher::build_auth_query_string(
$queryString = self::build_auth_query_string(
'TestKey', 'TestSecret', 'POST', $requestPath, [
'name' => 'some-event',
'channels' => ['public-channel'],
Expand Down Expand Up @@ -309,7 +308,7 @@ public function test_it_fires_event_across_servers_when_there_are_users_locally_
'appId' => '1234',
];

$queryString = Pusher::build_auth_query_string(
$queryString = self::build_auth_query_string(
'TestKey', 'TestSecret', 'POST', $requestPath, [
'name' => 'some-event',
'channels' => ['public-channel'],
Expand Down
25 changes: 25 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use GuzzleHttp\Psr7\Request;
use Illuminate\Support\Facades\Redis;
use Orchestra\Testbench\BrowserKit\TestCase as Orchestra;
use Pusher\Pusher;
use React\EventLoop\Factory as LoopFactory;

abstract class TestCase extends Orchestra
Expand Down Expand Up @@ -482,4 +483,28 @@ protected function skipOnLocalReplication()
$this->markTestSkipped('Skipped test because the replication mode is Local.');
}
}

protected static function build_auth_query_string(
$auth_key,
$auth_secret,
$request_method,
$request_path,
$query_params = [],
$auth_version = '1.0',
$auth_timestamp = null
) {
$method = method_exists(Pusher::class, 'build_auth_query_params') ? 'build_auth_query_params' : 'build_auth_query_string';

$params = Pusher::$method(
$auth_key, $auth_secret, $request_method, $request_path, $query_params, $auth_version, $auth_timestamp
);

if ($method == 'build_auth_query_string') {
return $params;
}

ksort($params);

return http_build_query($params);
}
}
3 changes: 1 addition & 2 deletions tests/TriggerEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use BeyondCode\LaravelWebSockets\API\TriggerEvent;
use GuzzleHttp\Psr7\Request;
use Pusher\Pusher;
use Symfony\Component\HttpKernel\Exception\HttpException;

class TriggerEventTest extends TestCase
Expand All @@ -22,7 +21,7 @@ public function test_invalid_signatures_can_not_fire_the_event()
'appId' => '1234',
];

$queryString = Pusher::build_auth_query_string(
$queryString = self::build_auth_query_string(
'TestKey', 'InvalidSecret', 'GET', $requestPath
);

Expand Down