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

[1.x] Update pusher/pusher-php-server versions #955

Merged
merged 6 commits into from
Mar 3, 2022
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
146 changes: 95 additions & 51 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,99 @@
name: run-tests

on: [push, pull_request]
on:
push:
branches:
- '*'
tags:
- '*'
pull_request:
branches:
- '*'

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.0, 7.4, 7.3, 7.2]
laravel: [6.*, 7.*, 8.*]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 8.*
testbench: 6.*
- laravel: 7.*
testbench: 5.*
- laravel: 6.*
testbench: 4.*
exclude:
- php: 7.2
laravel: 8.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, dom, fileinfo, libxml, mbstring, pdo, sqlite, pdo_sqlite, zip
coverage: pcov

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest

- name: Execute tests
run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml

- uses: codecov/codecov-action@v1
with:
fail_ci_if_error: false
build:
if: "!contains(github.event.head_commit.message, 'skip ci')"

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php:
- '7.3'
- '7.4'
- '8.0'
- '8.1'
laravel:
- 6.*
- 7.*
- 8.*
prefer:
- 'prefer-lowest'
- 'prefer-stable'
include:
- laravel: '6.*'
testbench: '4.*'
phpunit: '^8.5.8|^9.3.3'
- laravel: '7.*'
testbench: '5.*'
phpunit: '^8.5.8|^9.3.3'
- laravel: '8.*'
testbench: '6.*'
phpunit: '^9.3.3'
exclude:
- php: '8.0'
laravel: 6.*
prefer: 'prefer-lowest'
- php: '8.0'
laravel: 7.*
prefer: 'prefer-lowest'
- php: '8.1'
laravel: 6.*
- php: '8.1'
laravel: 7.*
- php: '8.1'
laravel: 8.*
prefer: 'prefer-lowest'

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} --${{ matrix.prefer }}

steps:
- uses: actions/checkout@v1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
coverage: pcov

- name: Setup Redis
uses: supercharge/[email protected]
with:
redis-version: 6

- uses: actions/cache@v1
name: Cache dependencies
with:
path: ~/.composer/cache/files
key: composer-php-${{ matrix.php }}-${{ matrix.laravel }}-${{ matrix.prefer }}-${{ hashFiles('composer.json') }}

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "phpunit/phpunit:${{ matrix.phpunit }}" "orchestra/testbench-browser-kit:${{ matrix.testbench }}" "orchestra/database:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.prefer }} --prefer-dist --no-interaction --no-suggest

- name: Run tests for Local
run: |
REPLICATION_MODE=local vendor/bin/phpunit --coverage-text --coverage-clover=coverage_local.xml

- name: Run tests for Redis
run: |
REPLICATION_MODE=redis vendor/bin/phpunit --coverage-text --coverage-clover=coverage_redis.xml

- uses: codecov/codecov-action@v1
with:
fail_ci_if_error: false
file: '*.xml'
token: ${{ secrets.CODECOV_TOKEN }}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
"ext-json": "*",
"cboden/ratchet": "^0.4.1",
"facade/ignition-contracts": "^1.0",
"guzzlehttp/psr7": "^1.5",
"guzzlehttp/psr7": "^1.7|^2.0",
"illuminate/broadcasting": "^6.0|^7.0|^8.0|^9.0",
"illuminate/console": "^6.0|^7.0|^8.0|^9.0",
"illuminate/http": "^6.0|^7.0|^8.0|^9.0",
"illuminate/routing": "^6.0|^7.0|^8.0|^9.0",
"illuminate/support": "^6.0|^7.0|^8.0|^9.0",
"pusher/pusher-php-server": "^3.0|^4.0|^5.0",
"pusher/pusher-php-server": "^3.0|^4.0|^5.0|^6.0|^7.0",
"react/dns": "^1.1",
"react/http": "^1.1",
"symfony/http-kernel": "^4.0|^5.0|^6.0",
Expand Down
3 changes: 2 additions & 1 deletion src/HttpApi/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use BeyondCode\LaravelWebSockets\QueryParameters;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use Exception;
use GuzzleHttp\Psr7\Message;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\ServerRequest;
use Illuminate\Http\JsonResponse;
Expand Down Expand Up @@ -110,7 +111,7 @@ public function onError(ConnectionInterface $connection, Exception $exception)
'Content-Length' => strlen($responseData),
], $responseData);

$connection->send(\GuzzleHttp\Psr7\str($response));
$connection->send(Message::toString($response));

$connection->close();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Statistics/Logger/HttpStatisticsLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController;
use BeyondCode\LaravelWebSockets\Statistics\Statistic;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use function GuzzleHttp\Psr7\stream_for;
use GuzzleHttp\Psr7\Utils;
use Ratchet\ConnectionInterface;
use React\Http\Browser;

Expand Down Expand Up @@ -81,7 +81,7 @@ public function save()
->post(
action([WebSocketStatisticsEntriesController::class, 'store']),
['Content-Type' => 'application/json'],
stream_for(json_encode($postData))
Utils::streamFor(json_encode($postData))
);

$currentConnectionCount = $this->channelManager->getConnectionCount($appId);
Expand Down
9 changes: 4 additions & 5 deletions tests/HttpApi/FetchChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use GuzzleHttp\Psr7\Request;
use Illuminate\Http\JsonResponse;
use Pusher\Pusher;
use Symfony\Component\HttpKernel\Exception\HttpException;

class FetchChannelTest extends TestCase
Expand All @@ -26,7 +25,7 @@ public function invalid_signatures_can_not_access_the_api()
'channelName' => 'my-channel',
];

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

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

Expand All @@ -49,7 +48,7 @@ public function 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 @@ -81,7 +80,7 @@ public function it_returns_the_channel_information_for_presence_channel()
'channelName' => 'presence-global',
];

$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 @@ -115,7 +114,7 @@ public function 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/HttpApi/FetchChannelsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use GuzzleHttp\Psr7\Request;
use Illuminate\Http\JsonResponse;
use Pusher\Pusher;
use Symfony\Component\HttpKernel\Exception\HttpException;

class FetchChannelsTest extends TestCase
Expand All @@ -25,7 +24,7 @@ public function invalid_signatures_can_not_access_the_api()
'appId' => '1234',
];

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

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

Expand All @@ -46,7 +45,7 @@ public function it_returns_the_channel_information()
'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 Expand Up @@ -79,7 +78,7 @@ public function 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 @@ -115,7 +114,7 @@ public function it_returns_the_channel_information_for_prefix_with_user_count()
'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 @@ -154,7 +153,7 @@ public function 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 @@ -178,7 +177,7 @@ public function 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
9 changes: 4 additions & 5 deletions tests/HttpApi/FetchUsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use GuzzleHttp\Psr7\Request;
use Pusher\Pusher;
use Symfony\Component\HttpKernel\Exception\HttpException;

class FetchUsersTest extends TestCase
Expand All @@ -25,7 +24,7 @@ public function invalid_signatures_can_not_access_the_api()
'channelName' => 'my-channel',
];

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

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

Expand All @@ -50,7 +49,7 @@ public function it_only_returns_data_for_presence_channels()
'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 All @@ -75,7 +74,7 @@ public function 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 All @@ -97,7 +96,7 @@ public function 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
25 changes: 25 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use BeyondCode\LaravelWebSockets\WebSocketsServiceProvider;
use GuzzleHttp\Psr7\Request;
use Mockery;
use Pusher\Pusher;
use Ratchet\ConnectionInterface;
use React\Http\Browser;

Expand Down Expand Up @@ -127,4 +128,28 @@ protected function markTestAsPassed()
{
$this->assertTrue(true);
}

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);
}
}