-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds method for detection request type from Request object (#9)
- Loading branch information
1 parent
94f3272
commit 9b48bfa
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RoadRunner\Centrifugo\Tests\Unit\Request; | ||
|
||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
use RoadRunner\Centrifugo\Request\Connect; | ||
use RoadRunner\Centrifugo\Request\Invalid; | ||
use RoadRunner\Centrifugo\Request\Publish; | ||
use RoadRunner\Centrifugo\Request\Refresh; | ||
use RoadRunner\Centrifugo\Request\RequestInterface; | ||
use RoadRunner\Centrifugo\Request\RequestType; | ||
use RoadRunner\Centrifugo\Request\RPC; | ||
use RoadRunner\Centrifugo\Request\SubRefresh; | ||
use RoadRunner\Centrifugo\Request\Subscribe; | ||
|
||
final class RequestTypeTest extends TestCase | ||
{ | ||
#[DataProvider('requestTypeDataProvider')] | ||
public function testRequestType(RequestInterface $request, RequestType $expected): void | ||
{ | ||
$this->assertSame($expected, RequestType::createFrom($request)); | ||
} | ||
|
||
public static function requestTypeDataProvider(): \Traversable | ||
{ | ||
$worker = \Mockery::mock(\Spiral\RoadRunner\WorkerInterface::class); | ||
|
||
yield 'Connect' => [ | ||
new Connect($worker, '', '', '', '', [], '', '', [], []), | ||
RequestType::Connect, | ||
]; | ||
|
||
yield 'Subscribe' => [ | ||
new Subscribe($worker, '', '', '', '', '', '', '', [], [], []), | ||
RequestType::Subscribe, | ||
]; | ||
|
||
yield 'Refresh' => [ | ||
new Refresh($worker, '', '', '', '', '', [], []), | ||
RequestType::Refresh, | ||
]; | ||
|
||
yield 'SubRefresh' => [ | ||
new SubRefresh($worker, '', '', '', '', '', '', [], []), | ||
RequestType::SubRefresh, | ||
]; | ||
|
||
yield 'Publish' => [ | ||
new Publish($worker, '', '', '', '', '', '', [], [], []), | ||
RequestType::Publish, | ||
]; | ||
|
||
yield 'RPC' => [ | ||
new RPC($worker, '', '', '', '', '', '', [], [], []), | ||
RequestType::RPC, | ||
]; | ||
|
||
yield 'Invalid' => [ | ||
new Invalid(new \Exception('Test Exception')), | ||
RequestType::Invalid, | ||
]; | ||
} | ||
} |