File tree Expand file tree Collapse file tree 5 files changed +36
-8
lines changed Expand file tree Collapse file tree 5 files changed +36
-8
lines changed Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ will not have to wait for an actual underlying connection.
107107
108108#### __ construct()
109109
110- The ` new MysqlClient(string $uri, ConnectorInterface $connector = null, LoopInterface $loop = null) ` constructor can be used to
110+ The ` new MysqlClient(string $uri, ? ConnectorInterface $connector = null, ? LoopInterface $loop = null) ` constructor can be used to
111111create a new ` MysqlClient ` instance.
112112
113113The ` $uri ` parameter must contain the database host, optional
Original file line number Diff line number Diff line change 77 "php" : " >=5.4.0" ,
88 "evenement/evenement" : " ^3.0 || ^2.1 || ^1.1" ,
99 "react/event-loop" : " ^1.2" ,
10- "react/promise" : " ^3 || ^2.7" ,
10+ "react/promise" : " ^3.2 || ^2.7" ,
1111 "react/promise-stream" : " ^1.6" ,
12- "react/promise-timer" : " ^1.9 " ,
13- "react/socket" : " ^1.12 "
12+ "react/promise-timer" : " ^1.11 " ,
13+ "react/socket" : " ^1.16 "
1414 },
1515 "require-dev" : {
1616 "phpunit/phpunit" : " ^9.6 || ^5.7 || ^4.8.36" ,
17- "react/async" : " ^4 || ^3 || ^2"
17+ "react/async" : " ^4.3 || ^3 || ^2"
1818 },
1919 "autoload" : {
2020 "psr-4" : {
Original file line number Diff line number Diff line change @@ -60,8 +60,12 @@ class Factory
6060 * @param ?LoopInterface $loop
6161 * @param ?ConnectorInterface $connector
6262 */
63- public function __construct (LoopInterface $ loop = null , ConnectorInterface $ connector = null )
63+ public function __construct ($ loop = null , $ connector = null )
6464 {
65+ // manual type check to support legacy PHP < 7.1
66+ assert ($ loop === null || $ loop instanceof LoopInterface);
67+ assert ($ connector === null || $ connector instanceof ConnectorInterface);
68+
6569 $ this ->loop = $ loop ?: Loop::get ();
6670 $ this ->connector = $ connector ?: new Connector ([], $ this ->loop );
6771 }
Original file line number Diff line number Diff line change @@ -76,12 +76,24 @@ class MysqlClient extends EventEmitter
7676 */
7777 private $ quitting = false ;
7878
79+ /**
80+ * @param string $uri
81+ * @param ?ConnectorInterface $connector
82+ * @param ?LoopInterface $loop
83+ */
7984 public function __construct (
8085 #[\SensitiveParameter]
8186 $ uri ,
82- ConnectorInterface $ connector = null ,
83- LoopInterface $ loop = null
87+ $ connector = null ,
88+ $ loop = null
8489 ) {
90+ if ($ connector !== null && !$ connector instanceof ConnectorInterface) { // manual type check to support legacy PHP < 7.1
91+ throw new \InvalidArgumentException ('Argument #2 ($connector) expected null|React\Socket\ConnectorInterface ' );
92+ }
93+ if ($ loop !== null && !$ loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
94+ throw new \InvalidArgumentException ('Argument #3 ($loop) expected null|React\EventLoop\LoopInterface ' );
95+ }
96+
8597 $ this ->factory = new Factory ($ loop , $ connector );
8698 $ this ->uri = $ uri ;
8799 }
Original file line number Diff line number Diff line change @@ -56,6 +56,18 @@ public function testConstructWithConnectorAndLoopAssignsGivenConnectorAndLoop()
5656 $ this ->assertSame ($ loop , $ ref ->getValue ($ factory ));
5757 }
5858
59+ public function testContructorThrowsExceptionForInvalidConnector ()
60+ {
61+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Argument #2 ($connector) expected null|React\Socket\ConnectorInterface ' );
62+ new MysqlClient ('localhost ' , 'connector ' );
63+ }
64+
65+ public function testContructorThrowsExceptionForInvalidLoop ()
66+ {
67+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Argument #3 ($loop) expected null|React\EventLoop\LoopInterface ' );
68+ new MysqlClient ('localhost ' , null , 'loop ' );
69+ }
70+
5971 public function testPingWillNotCloseConnectionWhenPendingConnectionFails ()
6072 {
6173 $ deferred = new Deferred ();
You can’t perform that action at this time.
0 commit comments