From 666811730c2964b6695b6076a8fc7410c3d279a2 Mon Sep 17 00:00:00 2001 From: Joe Campo Date: Wed, 23 Feb 2022 17:08:40 -0500 Subject: [PATCH 1/6] Update pusher/pusher-php-server versions --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 22b763e82b..710975f999 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "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", From e1d535380e230ff157dd9e7ea6d629ffdb46a42d Mon Sep 17 00:00:00 2001 From: Joe Campo Date: Thu, 24 Feb 2022 11:54:44 -0500 Subject: [PATCH 2/6] Fix tests --- tests/HttpApi/FetchChannelTest.php | 9 ++++----- tests/HttpApi/FetchChannelsTest.php | 13 ++++++------- tests/HttpApi/FetchUsersTest.php | 9 ++++----- tests/TestCase.php | 25 +++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/tests/HttpApi/FetchChannelTest.php b/tests/HttpApi/FetchChannelTest.php index 8324d9e24f..4f0fd7c327 100644 --- a/tests/HttpApi/FetchChannelTest.php +++ b/tests/HttpApi/FetchChannelTest.php @@ -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 @@ -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)); @@ -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)); @@ -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)); @@ -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)); diff --git a/tests/HttpApi/FetchChannelsTest.php b/tests/HttpApi/FetchChannelsTest.php index 0cf5a55e40..d99f09653d 100644 --- a/tests/HttpApi/FetchChannelsTest.php +++ b/tests/HttpApi/FetchChannelsTest.php @@ -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 @@ -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)); @@ -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)); @@ -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', ]); @@ -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', ]); @@ -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', ]); @@ -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)); diff --git a/tests/HttpApi/FetchUsersTest.php b/tests/HttpApi/FetchUsersTest.php index 43bc858b27..e9a42fe3f6 100644 --- a/tests/HttpApi/FetchUsersTest.php +++ b/tests/HttpApi/FetchUsersTest.php @@ -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 @@ -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)); @@ -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)); @@ -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)); @@ -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)); diff --git a/tests/TestCase.php b/tests/TestCase.php index 39ff08bf00..1b4b41f271 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -11,6 +11,7 @@ use BeyondCode\LaravelWebSockets\WebSocketsServiceProvider; use GuzzleHttp\Psr7\Request; use Mockery; +use Pusher\Pusher; use Ratchet\ConnectionInterface; use React\Http\Browser; @@ -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); + } } From b4fb755b957c2894909e466347dd390c666693fa Mon Sep 17 00:00:00 2001 From: Joe Campo Date: Thu, 24 Feb 2022 12:13:32 -0500 Subject: [PATCH 3/6] Add guzzlehttp/psr7 2.0 support --- composer.json | 2 +- src/HttpApi/Controllers/Controller.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 710975f999..274f7178ec 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "ext-json": "*", "cboden/ratchet": "^0.4.1", "facade/ignition-contracts": "^1.0", - "guzzlehttp/psr7": "^1.5", + "guzzlehttp/psr7": "^1.5|^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", diff --git a/src/HttpApi/Controllers/Controller.php b/src/HttpApi/Controllers/Controller.php index 2e3f63848c..13d8332cc6 100644 --- a/src/HttpApi/Controllers/Controller.php +++ b/src/HttpApi/Controllers/Controller.php @@ -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; @@ -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(); } From 5b81c2baee7b605a75870971803315bde1e1bd21 Mon Sep 17 00:00:00 2001 From: Joe Campo Date: Thu, 24 Feb 2022 12:19:04 -0500 Subject: [PATCH 4/6] Update run-tests.yml --- .github/workflows/run-tests.yml | 146 +++++++++++++++++++++----------- 1 file changed, 95 insertions(+), 51 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 704d49aa64..6b37134f6f 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -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/redis-github-action@1.1.0 + 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 }} \ No newline at end of file From 5abdbe3e54d121386debca6c6a9691eb620d5a45 Mon Sep 17 00:00:00 2001 From: Joe Campo Date: Thu, 24 Feb 2022 12:38:08 -0500 Subject: [PATCH 5/6] Fix version of guzzlehttp/psr7 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 274f7178ec..c51e7beecc 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "ext-json": "*", "cboden/ratchet": "^0.4.1", "facade/ignition-contracts": "^1.0", - "guzzlehttp/psr7": "^1.5|^2.0", + "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", From 183d664f228a8c317298891c382baf731844940c Mon Sep 17 00:00:00 2001 From: Joe Campo Date: Fri, 25 Feb 2022 14:34:56 -0500 Subject: [PATCH 6/6] Fix deprecated stream_for method --- src/Statistics/Logger/HttpStatisticsLogger.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Statistics/Logger/HttpStatisticsLogger.php b/src/Statistics/Logger/HttpStatisticsLogger.php index 5bf35dd8da..9145c3712e 100644 --- a/src/Statistics/Logger/HttpStatisticsLogger.php +++ b/src/Statistics/Logger/HttpStatisticsLogger.php @@ -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; @@ -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);