Skip to content

Commit

Permalink
Fix response parser (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
fre5h authored May 25, 2024
1 parent 903d834 commit 9549ca8
Show file tree
Hide file tree
Showing 74 changed files with 568 additions and 221 deletions.
8 changes: 8 additions & 0 deletions Model/ChannelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ public function __construct(string $pattern = null)

parent::__construct(Method::CHANNELS, $params);
}

/**
* {@inheritdoc}
*/
public function processResponse(array $data): array
{
return $data;
}
}
8 changes: 8 additions & 0 deletions Model/HistoryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ public function __construct(protected readonly string $channel, bool $reverse =

parent::__construct(Method::HISTORY, $params);
}

/**
* {@inheritdoc}
*/
public function processResponse(array $data): array
{
return $data['result'];
}
}
8 changes: 8 additions & 0 deletions Model/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ public function __construct()
{
parent::__construct(Method::INFO, []);
}

/**
* {@inheritdoc}
*/
public function processResponse(array $data): array
{
return $data['result'];
}
}
8 changes: 8 additions & 0 deletions Model/PresenceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ public function __construct(protected readonly string $channel)
]
);
}

/**
* {@inheritdoc}
*/
public function processResponse(array $data): array
{
return $data['result']['presence'];
}
}
8 changes: 8 additions & 0 deletions Model/PresenceStatsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ public function __construct(protected readonly string $channel)
]
);
}

/**
* {@inheritdoc}
*/
public function processResponse(array $data): array
{
return $data['result'];
}
}
6 changes: 6 additions & 0 deletions Model/ResultableCommandInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@
*/
interface ResultableCommandInterface extends CommandInterface
{
/**
* @param array $data
*
* @return array
*/
public function processResponse(array $data): array;
}
2 changes: 1 addition & 1 deletion Service/ResponseProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private function decodeAndProcessResponseResult(CommandInterface $command, Respo
$result = $data;
$successfulCommand = false;
} elseif ($command instanceof ResultableCommandInterface) {
$result = $data[$command->getMethod()->value];
$result = $command->processResponse($data);
}

if ($this->profilerEnabled) {
Expand Down
10 changes: 7 additions & 3 deletions Tests/Command/Argument/ArgumentChannelTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Fresh\CentrifugoBundle\Exception\InvalidArgumentException as CentrifugoInvalidArgumentException;
use Fresh\CentrifugoBundle\Service\CentrifugoChecker;
use Fresh\CentrifugoBundle\Service\CentrifugoInterface;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
Expand Down Expand Up @@ -64,7 +65,8 @@ protected function tearDown(): void
);
}

public function testInvalidChannelName(): void
#[Test]
public function invalidChannelName(): void
{
$this->centrifugoChecker
->expects(self::once())
Expand All @@ -89,7 +91,8 @@ public function testInvalidChannelName(): void
);
}

public function testChannelNameIsNotString(): void
#[Test]
public function channelNameIsNotString(): void
{
$this->centrifugoChecker
->expects(self::never())
Expand All @@ -112,7 +115,8 @@ public function testChannelNameIsNotString(): void
);
}

public function testChannelNameIsMissed(): void
#[Test]
public function channelNameIsMissed(): void
{
$this->centrifugoChecker
->expects(self::never())
Expand Down
4 changes: 3 additions & 1 deletion Tests/Command/Argument/ArgumentChannelsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Fresh\CentrifugoBundle\Command\BroadcastCommand;
use Fresh\CentrifugoBundle\Service\CentrifugoChecker;
use Fresh\CentrifugoBundle\Service\CentrifugoInterface;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
Expand Down Expand Up @@ -63,7 +64,8 @@ protected function tearDown(): void
);
}

public function testInvalidChannelName(): void
#[Test]
public function invalidChannelName(): void
{
$this->centrifugoChecker
->expects(self::once())
Expand Down
7 changes: 5 additions & 2 deletions Tests/Command/Argument/ArgumentDataTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Fresh\CentrifugoBundle\Command\BroadcastCommand;
use Fresh\CentrifugoBundle\Service\CentrifugoChecker;
use Fresh\CentrifugoBundle\Service\CentrifugoInterface;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
Expand Down Expand Up @@ -63,7 +64,8 @@ protected function tearDown(): void
);
}

public function testDataIsNotValidJson(): void
#[Test]
public function dataIsNotValidJson(): void
{
$this->centrifugo
->expects(self::never())
Expand All @@ -82,7 +84,8 @@ public function testDataIsNotValidJson(): void
);
}

public function testDataIsNotString(): void
#[Test]
public function dataIsNotString(): void
{
$this->centrifugo
->expects(self::never())
Expand Down
4 changes: 3 additions & 1 deletion Tests/Command/Argument/ArgumentUserTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Fresh\CentrifugoBundle\Command\DisconnectCommand;
use Fresh\CentrifugoBundle\Service\CentrifugoInterface;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
Expand Down Expand Up @@ -57,7 +58,8 @@ protected function tearDown(): void
);
}

public function testInvalidUser(): void
#[Test]
public function invalidUser(): void
{
$this->centrifugo
->expects(self::never())
Expand Down
10 changes: 7 additions & 3 deletions Tests/Command/BroadcastCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Fresh\CentrifugoBundle\Command\BroadcastCommand;
use Fresh\CentrifugoBundle\Service\CentrifugoChecker;
use Fresh\CentrifugoBundle\Service\CentrifugoInterface;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
Expand Down Expand Up @@ -62,7 +63,8 @@ protected function tearDown(): void
);
}

public function testSuccessfulExecutionWithRequiredParameters(): void
#[Test]
public function successfulExecutionWithRequiredParameters(): void
{
$this->centrifugo
->expects(self::once())
Expand All @@ -83,7 +85,8 @@ public function testSuccessfulExecutionWithRequiredParameters(): void
self::assertStringContainsString('DONE', $output);
}

public function testSuccessfulExecutionWithAllParameters(): void
#[Test]
public function successfulExecutionWithAllParameters(): void
{
$this->centrifugo
->expects(self::once())
Expand All @@ -107,7 +110,8 @@ public function testSuccessfulExecutionWithAllParameters(): void
self::assertStringContainsString('DONE', $output);
}

public function testException(): void
#[Test]
public function exception(): void
{
$this->centrifugo
->expects(self::once())
Expand Down
16 changes: 11 additions & 5 deletions Tests/Command/ChannelsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Fresh\CentrifugoBundle\Command\ChannelsCommand;
use Fresh\CentrifugoBundle\Service\CentrifugoInterface;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
Expand Down Expand Up @@ -56,7 +57,8 @@ protected function tearDown(): void
);
}

public function testSuccessfulExecutionWithoutPattern(): void
#[Test]
public function successfulExecutionWithoutPattern(): void
{
$this->centrifugo
->expects(self::once())
Expand All @@ -73,7 +75,8 @@ public function testSuccessfulExecutionWithoutPattern(): void
self::assertStringContainsString('Total Channels: 2', $output);
}

public function testSuccessfulExecutionWithPattern(): void
#[Test]
public function successfulExecutionWithPattern(): void
{
$this->centrifugo
->expects(self::once())
Expand All @@ -94,7 +97,8 @@ public function testSuccessfulExecutionWithPattern(): void
self::assertStringContainsString('Total Channels: 1', $output);
}

public function testNoData(): void
#[Test]
public function noData(): void
{
$this->centrifugo
->expects(self::once())
Expand All @@ -109,7 +113,8 @@ public function testNoData(): void
self::assertStringContainsString('NO DATA', $output);
}

public function testException(): void
#[Test]
public function exception(): void
{
$this->centrifugo
->expects(self::once())
Expand All @@ -124,7 +129,8 @@ public function testException(): void
self::assertStringContainsString('test', $output);
}

public function testAutocomplete(): void
#[Test]
public function autocomplete(): void
{
$this->centrifugo
->expects(self::once())
Expand Down
16 changes: 11 additions & 5 deletions Tests/Command/DisconnectCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Fresh\CentrifugoBundle\Command\DisconnectCommand;
use Fresh\CentrifugoBundle\Model\Disconnect;
use Fresh\CentrifugoBundle\Service\CentrifugoInterface;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
Expand Down Expand Up @@ -58,7 +59,8 @@ protected function tearDown(): void
);
}

public function testSuccessfulExecutionWithRequiredParameters(): void
#[Test]
public function successfulExecutionWithRequiredParameters(): void
{
$this->centrifugo
->expects(self::once())
Expand All @@ -78,7 +80,8 @@ public function testSuccessfulExecutionWithRequiredParameters(): void
self::assertStringContainsString('DONE', $output);
}

public function testSuccessfulExecutionWithAllParameters(): void
#[Test]
public function successfulExecutionWithAllParameters(): void
{
$this->centrifugo
->expects(self::once())
Expand All @@ -103,7 +106,8 @@ public function testSuccessfulExecutionWithAllParameters(): void
self::assertStringContainsString('DONE', $output);
}

public function testExceptionForMissingDisconnectCode(): void
#[Test]
public function exceptionForMissingDisconnectCode(): void
{
$this->centrifugo
->expects(self::never())
Expand All @@ -129,7 +133,8 @@ public function testExceptionForMissingDisconnectCode(): void
self::assertStringContainsString('DONE', $output);
}

public function testExceptionForMissingDisconnectReason(): void
#[Test]
public function exceptionForMissingDisconnectReason(): void
{
$this->centrifugo
->expects(self::never())
Expand All @@ -155,7 +160,8 @@ public function testExceptionForMissingDisconnectReason(): void
self::assertStringContainsString('DONE', $output);
}

public function testException(): void
#[Test]
public function exception(): void
{
$this->centrifugo
->expects(self::once())
Expand Down
10 changes: 7 additions & 3 deletions Tests/Command/HistoryCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Fresh\CentrifugoBundle\Model\StreamPosition;
use Fresh\CentrifugoBundle\Service\CentrifugoChecker;
use Fresh\CentrifugoBundle\Service\CentrifugoInterface;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
Expand Down Expand Up @@ -63,7 +64,8 @@ protected function tearDown(): void
);
}

public function testSuccessfulExecutionWithRequiredParameters(): void
#[Test]
public function successfulExecutionWithRequiredParameters(): void
{
$this->centrifugo
->expects(self::once())
Expand Down Expand Up @@ -106,7 +108,8 @@ public function testSuccessfulExecutionWithRequiredParameters(): void
self::assertStringContainsString('Epoch: test', $output);
}

public function testSuccessfulExecutionWithAllParameters(): void
#[Test]
public function successfulExecutionWithAllParameters(): void
{
$this->centrifugo
->expects(self::once())
Expand Down Expand Up @@ -153,7 +156,8 @@ public function testSuccessfulExecutionWithAllParameters(): void
self::assertStringContainsString('Epoch: test', $output);
}

public function testException(): void
#[Test]
public function exception(): void
{
$this->centrifugo
->expects(self::once())
Expand Down
Loading

0 comments on commit 9549ca8

Please sign in to comment.