From 6956fe2de8f37c1027fb3936d829ab66e3e9da38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 29 Sep 2023 12:25:11 +0200 Subject: [PATCH] Drop deprecated alternative `Browser` constructor argument order --- README.md | 4 --- src/Browser.php | 22 ++----------- tests/BrowserTest.php | 72 ------------------------------------------- 3 files changed, 3 insertions(+), 95 deletions(-) diff --git a/README.md b/README.md index 8867f798..2f7151ac 100644 --- a/README.md +++ b/README.md @@ -1869,11 +1869,7 @@ $browser = new React\Http\Browser(); This class takes two optional arguments for more advanced usage: ```php -// constructor signature as of v1.5.0 $browser = new React\Http\Browser(?ConnectorInterface $connector = null, ?LoopInterface $loop = null); - -// legacy constructor signature before v1.5.0 -$browser = new React\Http\Browser(?LoopInterface $loop = null, ?ConnectorInterface $connector = null); ``` If you need custom connector settings (DNS resolution, TLS parameters, timeouts, diff --git a/src/Browser.php b/src/Browser.php index 01a266ca..a24d24e7 100644 --- a/src/Browser.php +++ b/src/Browser.php @@ -37,11 +37,7 @@ class Browser * This class takes two optional arguments for more advanced usage: * * ```php - * // constructor signature as of v1.5.0 * $browser = new React\Http\Browser(?ConnectorInterface $connector = null, ?LoopInterface $loop = null); - * - * // legacy constructor signature before v1.5.0 - * $browser = new React\Http\Browser(?LoopInterface $loop = null, ?ConnectorInterface $connector = null); * ``` * * If you need custom connector settings (DNS resolution, TLS parameters, timeouts, @@ -69,23 +65,11 @@ class Browser * This value SHOULD NOT be given unless you're sure you want to explicitly use a * given event loop instance. * - * @param null|ConnectorInterface|LoopInterface $connector - * @param null|LoopInterface|ConnectorInterface $loop - * @throws \InvalidArgumentException for invalid arguments + * @param ?ConnectorInterface $connector + * @param ?LoopInterface $loop */ - public function __construct($connector = null, $loop = null) + public function __construct(ConnectorInterface $connector = null, LoopInterface $loop = null) { - // swap arguments for legacy constructor signature - if (($connector instanceof LoopInterface || $connector === null) && ($loop instanceof ConnectorInterface || $loop === null)) { - $swap = $loop; - $loop = $connector; - $connector = $swap; - } - - if (($connector !== null && !$connector instanceof ConnectorInterface) || ($loop !== null && !$loop instanceof LoopInterface)) { - throw new \InvalidArgumentException('Expected "?ConnectorInterface $connector" and "?LoopInterface $loop" arguments'); - } - $loop = $loop ?: Loop::get(); $this->transaction = new Transaction( Sender::createFromLoop($loop, $connector), diff --git a/tests/BrowserTest.php b/tests/BrowserTest.php index fdd338d9..fb1a1beb 100644 --- a/tests/BrowserTest.php +++ b/tests/BrowserTest.php @@ -70,35 +70,6 @@ public function testConstructWithConnectorAssignsGivenConnector() $this->assertSame($connector, $ret); } - public function testConstructWithConnectorWithLegacySignatureAssignsGivenConnector() - { - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); - - $browser = new Browser(null, $connector); - - $ref = new \ReflectionProperty($browser, 'transaction'); - $ref->setAccessible(true); - $transaction = $ref->getValue($browser); - - $ref = new \ReflectionProperty($transaction, 'sender'); - $ref->setAccessible(true); - $sender = $ref->getValue($transaction); - - $ref = new \ReflectionProperty($sender, 'http'); - $ref->setAccessible(true); - $client = $ref->getValue($sender); - - $ref = new \ReflectionProperty($client, 'connectionManager'); - $ref->setAccessible(true); - $connectionManager = $ref->getValue($client); - - $ref = new \ReflectionProperty($connectionManager, 'connector'); - $ref->setAccessible(true); - $ret = $ref->getValue($connectionManager); - - $this->assertSame($connector, $ret); - } - public function testConstructWithLoopAssignsGivenLoop() { $browser = new Browser(null, $this->loop); @@ -114,49 +85,6 @@ public function testConstructWithLoopAssignsGivenLoop() $this->assertSame($this->loop, $loop); } - public function testConstructWithLoopWithLegacySignatureAssignsGivenLoop() - { - $browser = new Browser($this->loop); - - $ref = new \ReflectionProperty($browser, 'transaction'); - $ref->setAccessible(true); - $transaction = $ref->getValue($browser); - - $ref = new \ReflectionProperty($transaction, 'loop'); - $ref->setAccessible(true); - $loop = $ref->getValue($transaction); - - $this->assertSame($this->loop, $loop); - } - - public function testConstructWithInvalidConnectorThrows() - { - $this->setExpectedException('InvalidArgumentException'); - new Browser('foo'); - } - - public function testConstructWithInvalidLoopThrows() - { - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); - - $this->setExpectedException('InvalidArgumentException'); - new Browser($connector, 'foo'); - } - - public function testConstructWithConnectorTwiceThrows() - { - $connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock(); - - $this->setExpectedException('InvalidArgumentException'); - new Browser($connector, $connector); - } - - public function testConstructWithLoopTwiceThrows() - { - $this->setExpectedException('InvalidArgumentException'); - new Browser($this->loop, $this->loop); - } - public function testGetSendsGetRequest() { $that = $this;