File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313 strategy :
1414 matrix :
1515 php :
16+ - 8.4
1617 - 8.3
1718 - 8.2
1819 - 8.1
Original file line number Diff line number Diff line change 1414 "php" : " >=5.3" ,
1515 "evenement/evenement" : " ^3.0 || ^2.0 || ^1.0" ,
1616 "react/event-loop" : " ^1.2" ,
17- "react/promise" : " ^3.0 || ^2.9 || ^1.1" ,
18- "react/socket" : " ^1.14 "
17+ "react/promise" : " ^3.2 || ^2.9 || ^1.1" ,
18+ "react/socket" : " ^1.16 "
1919 },
2020 "require-dev" : {
2121 "phpunit/phpunit" : " ^9.6 || ^5.7 || ^4.8.36" ,
22- "react/async" : " ^4.2 || ^3.2 || ^2.2"
22+ "react/async" : " ^4.3 || ^3.2 || ^2.2"
2323 },
2424 "autoload" : {
2525 "psr-4" : {
Original file line number Diff line number Diff line change @@ -33,8 +33,16 @@ class Client extends EventEmitter
3333
3434 private $ actionId = 0 ;
3535
36- public function __construct (ConnectionInterface $ stream , Parser $ parser = null )
36+ /**
37+ * @param ConnectionInterface $stream
38+ * @param ?Parser $parser
39+ */
40+ public function __construct (ConnectionInterface $ stream , $ parser = null )
3741 {
42+ if ($ parser !== null && !$ parser instanceof Parser) { // manual type check to support legacy PHP < 7.1
43+ throw new \InvalidArgumentException ('Argument #2 ($parser) expected null|Clue\React\Ami\Protocol\Parser ' );
44+ }
45+
3846 if ($ parser === null ) {
3947 $ parser = new Parser ();
4048 }
Original file line number Diff line number Diff line change @@ -43,8 +43,19 @@ class Factory
4343{
4444 private $ connector ;
4545
46- public function __construct (LoopInterface $ loop = null , ConnectorInterface $ connector = null )
46+ /**
47+ * @param ?LoopInterface $loop
48+ * @param ?ConnectorInterface $connector
49+ */
50+ public function __construct ($ loop = null , $ connector = null )
4751 {
52+ if ($ loop !== null && !$ loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
53+ throw new \InvalidArgumentException ('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface ' );
54+ }
55+ if ($ connector !== null && !$ connector instanceof ConnectorInterface) { // manual type check to support legacy PHP < 7.1
56+ throw new \InvalidArgumentException ('Argument #2 ($connector) expected null|React\Socket\ConnectorInterface ' );
57+ }
58+
4859 if ($ connector === null ) {
4960 $ connector = new Connector (array (), $ loop );
5061 }
Original file line number Diff line number Diff line change @@ -43,6 +43,12 @@ public function testUnexpectedResponseEmitsErrorAndClosesClient()
4343 $ client ->handleMessage (new Response (array ('ActionID ' => 1 )));
4444 }
4545
46+ public function testCtorThrowsForInvalidParser ()
47+ {
48+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Argument #2 ($parser) expected null|Clue\React\Ami\Protocol\Parser ' );
49+ new Client ($ this ->createStreamMock (), 'parser ' );
50+ }
51+
4652 private function createStreamMock ()
4753 {
4854 if (method_exists ('PHPUnit\Framework\MockObject\MockBuilder ' , 'onlyMethods ' )) {
Original file line number Diff line number Diff line change @@ -31,6 +31,18 @@ public function testDefaultCtorCreatesConnectorAutomatically()
3131 $ this ->assertInstanceOf ('React\Socket\Connector ' , $ connector );
3232 }
3333
34+ public function testCtorThrowsForInvalidLoop ()
35+ {
36+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Argument #1 ($loop) expected null|React\EventLoop\LoopInterface ' );
37+ new Factory ('loop ' );
38+ }
39+
40+ public function testCtorThrowsForInvalidConnector ()
41+ {
42+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Argument #2 ($connector) expected null|React\Socket\ConnectorInterface ' );
43+ new Factory (null , 'connector ' );
44+ }
45+
3446 public function testCreateClientUsesDefaultPortForTcpConnection ()
3547 {
3648 $ promise = new Promise (function () { });
You can’t perform that action at this time.
0 commit comments