Skip to content

Commit

Permalink
TestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
denis_sz committed Oct 8, 2024
1 parent 9f11e1c commit 1c907aa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
matrix:
php-version: [ "8.2"]
laravel: [11]

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

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -31,9 +31,9 @@ jobs:
ini-values: error_reporting=E_ALL
tools: composer:v2
coverage: none

- name: Start Centrifugo
run: docker run -d -p 8000:8000 -e CENTRIFUGO_TOKEN_HMAC_SECRET_KEY="secret" -e CENTRIFUGO_PRESENCE=1 -e CENTRIFUGO_JOIN_LEAVE=true -e CENTRIFUGO_FORCE_PUSH_JOIN_LEAVE=true -e CENTRIFUGO_HISTORY_TTL=300s -e CENTRIFUGO_HISTORY_SIZE=100 -e CENTRIFUGO_FORCE_RECOVERY=true -e CENTRIFUGO_USER_SUBSCRIBE_TO_PERSONAL=true -e CENTRIFUGO_ALLOW_PUBLISH_FOR_SUBSCRIBER=true -e CENTRIFUGO_ALLOW_PRESENCE_FOR_SUBSCRIBER=true -e CENTRIFUGO_ALLOW_HISTORY_FOR_SUBSCRIBER=true centrifugo/centrifugo:v5 centrifugo
run: docker run -d -p 8000:8000 -e CENTRIFUGO_TOKEN_HMAC_SECRET_KEY="secret" -e CENTRIFUGO_YOUR-API-KEY-HERE="api-key" -e CENTRIFUGO_PRESENCE=1 -e CENTRIFUGO_JOIN_LEAVE=true -e CENTRIFUGO_FORCE_PUSH_JOIN_LEAVE=true -e CENTRIFUGO_HISTORY_TTL=300s -e CENTRIFUGO_HISTORY_SIZE=100 -e CENTRIFUGO_FORCE_RECOVERY=true -e CENTRIFUGO_USER_SUBSCRIBE_TO_PERSONAL=true -e CENTRIFUGO_ALLOW_PUBLISH_FOR_SUBSCRIBER=true -e CENTRIFUGO_ALLOW_PRESENCE_FOR_SUBSCRIBER=true -e CENTRIFUGO_ALLOW_HISTORY_FOR_SUBSCRIBER=true centrifugo/centrifugo:v5 centrifugo
- name: Check container status
run: docker ps

Expand All @@ -49,6 +49,6 @@ jobs:
run: |
composer require "illuminate/contracts=^${{ matrix.laravel }}" --no-update
composer update --prefer-dist --no-interaction --no-progress
- name: PHPUnit Tests
run: vendor/bin/phpunit
2 changes: 0 additions & 2 deletions src/Centrifugo.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,6 @@ protected function getApiKey(): string
*/
protected function send(string $method, array $params = []) : array
{
$json = json_encode(['method' => $method, 'params' => $params]);

$url = $this->prepareUrl();

$config =[
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ protected function getPackageProviders($app): array

protected function getEnvironmentSetUp($app)
{

$app['config']->set('broadcasting.default', 'centrifugo');
$app['config']->set('broadcasting.connections.centrifugo', [
'driver' => 'centrifugo',
'token_hmac_secret_key' => '', //0cac68ac-5965-46bf-8c44-ed28a03ab8ba
'api_key' => '', //ae3362d2-5862-4261-9b3b-6b231f8863c8
'token_hmac_secret_key' => 'secret',
'api_key' => 'api-key',
'url' => 'http://localhost:8000',
]);
}
Expand Down
18 changes: 12 additions & 6 deletions tests/Unit/CentrifugoTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);

namespace denis660\Centrifugo\Test\Unit;

Expand All @@ -12,30 +13,35 @@
*
* @coversNothing
*/


class CentrifugoTest extends TestCase
{



public function testGenerateToken(): void
{

$timestamp = 1727716803;


$info = [
'first_name' => "Tristian",
'last_name' => "Ruecker",
];
$clientId = "f2527b6a-6705-45b7-a1d9-d0029943dc20";

$clientToken1 = $this->centrifuge->generateConnectionToken($clientId, $timestamp);

$clientToken1 = $this->centrifuge->generateConnectionToken(userId:$clientId);

$this->assertEquals(
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJmMjUyN2I2YS02NzA1LTQ1YjctYTFkOS1kMDAyOTk0M2RjMjAiLCJleHAiOjE3Mjc3MTY4MDN9.om2AdKJLNYbZ7bfeIS9tw0AJqs1RIp5irUGNfPiqHqk',
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJmMjUyN2I2YS02NzA1LTQ1YjctYTFkOS1kMDAyOTk0M2RjMjAifQ.csRuDJhBalF3J3v6JnsNZmOXLx6nbNMi3zcCieJJqng',
$clientToken1
);

$clientToken2 = $this->centrifuge->generatePrivateChannelToken($clientId, 'test', $timestamp, $info);
$clientToken2 = $this->centrifuge->generatePrivateChannelToken(userId:$clientId, channel:'test', info:$info);

$this->assertEquals(
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjaGFubmVsIjoidGVzdCIsImNsaWVudCI6ImYyNTI3YjZhLTY3MDUtNDViNy1hMWQ5LWQwMDI5OTQzZGMyMCIsImluZm8iOnsiZmlyc3RfbmFtZSI6IlRyaXN0aWFuIiwibGFzdF9uYW1lIjoiUnVlY2tlciJ9LCJleHAiOjE3Mjc3MTY4MDN9.UtzQDjU1RDXKizcBlvF5VMR45_crs6AU4tcO-EfPnjM',
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjaGFubmVsIjoidGVzdCIsInN1YiI6ImYyNTI3YjZhLTY3MDUtNDViNy1hMWQ5LWQwMDI5OTQzZGMyMCIsImluZm8iOnsiZmlyc3RfbmFtZSI6IlRyaXN0aWFuIiwibGFzdF9uYW1lIjoiUnVlY2tlciJ9fQ.8wNO3gQdg6Knk9J7mPZquV8aAsDtqI2a4A5tK5Y9IR8',
$clientToken2
);
}
Expand Down

0 comments on commit 1c907aa

Please sign in to comment.