From e7e3b557b5ae0381abe19987bd4aa36c211846c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 27 Sep 2023 08:22:25 +0200 Subject: [PATCH] Drop deprecated alternative `Connector` constructor argument order --- README.md | 12 ------- src/Connector.php | 21 ++---------- tests/ConnectorTest.php | 76 ----------------------------------------- 3 files changed, 3 insertions(+), 106 deletions(-) diff --git a/README.md b/README.md index 8915e9d..42e2132 100644 --- a/README.md +++ b/README.md @@ -1156,18 +1156,6 @@ here in order to use the [default loop](https://github.com/reactphp/event-loop#l This value SHOULD NOT be given unless you're sure you want to explicitly use a given event loop instance. -> Changelog v1.9.0: The constructur signature has been updated to take the -> optional `$context` as the first parameter and the optional `$loop` as a second -> argument. The previous signature has been deprecated and should not be used anymore. -> -> ```php -> // constructor signature as of v1.9.0 -> $connector = new React\Socket\Connector(array $context = [], ?LoopInterface $loop = null); -> -> // legacy constructor signature before v1.9.0 -> $connector = new React\Socket\Connector(?LoopInterface $loop = null, array $context = []); -> ``` - ### Advanced client usage #### TcpConnector diff --git a/src/Connector.php b/src/Connector.php index 15faa46..e2203fc 100644 --- a/src/Connector.php +++ b/src/Connector.php @@ -36,11 +36,7 @@ final class Connector implements ConnectorInterface * This class takes two optional arguments for more advanced usage: * * ```php - * // constructor signature as of v1.9.0 * $connector = new React\Socket\Connector(array $context = [], ?LoopInterface $loop = null); - * - * // legacy constructor signature before v1.9.0 - * $connector = new React\Socket\Connector(?LoopInterface $loop = null, array $context = []); * ``` * * This class takes an optional `LoopInterface|null $loop` parameter that can be used to @@ -49,23 +45,12 @@ final class Connector implements ConnectorInterface * This value SHOULD NOT be given unless you're sure you want to explicitly use a * given event loop instance. * - * @param array|LoopInterface|null $context - * @param null|LoopInterface|array $loop + * @param array $context + * @param ?LoopInterface $loop * @throws \InvalidArgumentException for invalid arguments */ - public function __construct($context = array(), $loop = null) + public function __construct(array $context = array(), LoopInterface $loop = null) { - // swap arguments for legacy constructor signature - if (($context instanceof LoopInterface || $context === null) && (\func_num_args() <= 1 || \is_array($loop))) { - $swap = $loop === null ? array(): $loop; - $loop = $context; - $context = $swap; - } - - if (!\is_array($context) || ($loop !== null && !$loop instanceof LoopInterface)) { - throw new \InvalidArgumentException('Expected "array $context" and "?LoopInterface $loop" arguments'); - } - // apply default options if not explicitly given $context += array( 'tcp' => true, diff --git a/tests/ConnectorTest.php b/tests/ConnectorTest.php index 02982db..a56d69a 100644 --- a/tests/ConnectorTest.php +++ b/tests/ConnectorTest.php @@ -56,82 +56,6 @@ public function testConstructWithContextAssignsGivenContext() $this->assertSame($tcp, $connectors['tcp']); } - public function testConstructWithLegacyContextSignatureAssignsGivenContext() - { - $tcp = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); - - $connector = new Connector(null, array( - 'tcp' => $tcp, - 'dns' => false, - 'timeout' => false - )); - - $ref = new \ReflectionProperty($connector, 'connectors'); - $ref->setAccessible(true); - $connectors = $ref->getValue($connector); - - $this->assertSame($tcp, $connectors['tcp']); - } - - public function testConstructWithLegacyLoopSignatureAssignsGivenLoop() - { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); - - $connector = new Connector($loop); - - $ref = new \ReflectionProperty($connector, 'connectors'); - $ref->setAccessible(true); - $connectors = $ref->getValue($connector); - - $ref = new \ReflectionProperty($connectors['tcp'], 'loop'); - $ref->setAccessible(true); - $loop = $ref->getValue($connectors['tcp']); - - $this->assertInstanceOf('React\EventLoop\LoopInterface', $loop); - } - - public function testConstructWithInvalidContextThrows() - { - $this->setExpectedException('InvalidArgumentException'); - new Connector('foo'); - } - - public function testConstructWithInvalidLoopThrows() - { - $this->setExpectedException('InvalidArgumentException'); - new Connector(array(), 'foo'); - } - - public function testConstructWithContextTwiceThrows() - { - $this->setExpectedException('InvalidArgumentException'); - new Connector(array(), array()); - } - - public function testConstructWithLoopTwiceThrows() - { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); - - $this->setExpectedException('InvalidArgumentException'); - new Connector($loop, $loop); - } - - public function testConstructWithNullContextAndLoopThrows() - { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); - - $this->setExpectedException('InvalidArgumentException'); - new Connector(null, $loop); - } - - public function testConstructWithLoopAndNullContextThrows() - { - $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); - - $this->setExpectedException('InvalidArgumentException'); - new Connector($loop, null); - } - public function testConnectorUsesTcpAsDefaultScheme() { $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();