8000 Merge pull request #529 from clue-labs/drop-browser-alternative · reactphp/http@da8ee09 · GitHub < 8000 meta name="color-scheme" content="light dark" />
[go: up one dir, main page]

Skip to content

Commit da8ee09

Browse files
authored
Merge pull request #529 from clue-labs/drop-browser-alternative
Drop deprecated alternative `Browser` constructor argument order
2 parents 170547b + 6956fe2 commit da8ee09

File tree

3 files changed

+3
-95
lines changed

3 files changed

+3
-95
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,11 +1863,7 @@ $browser = new React\Http\Browser();
18631863
This class takes two optional arguments for more advanced usage:
18641864

18651865
```php
1866-
// constructor signature as of v1.5.0
18671866
$browser = new React\Http\Browser(?ConnectorInterface $connector = null, ?LoopInterface $loop = null);
1868-
1869-
// legacy constructor signature before v1.5.0
1870-
$browser = new React\Http\Browser(?LoopInterface $loop = null, ?ConnectorInterface $connector = null);
18711867
```
18721868

18731869
If you need custom connector settings (DNS resolution, TLS parameters, timeouts,

src/Browser.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ class Browser
3737
* This class takes two optional arguments for more advanced usage:
3838
*
3939
* ```php
40-
* // constructor signature as of v1.5.0
4140
* $browser = new React\Http\Browser(?ConnectorInterface $connector = null, ?LoopInterface $loop = null);
42-
*
43-
* // legacy constructor signature before v1.5.0
44-
* $browser = new React\Http\Browser(?LoopInterface $loop = null, ?ConnectorInterface $connector = null);
4541
* ```
4642
*
4743
* If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
@@ -69,23 +65,11 @@ class Browser
6965
* This value SHOULD NOT be given unless you're sure you want to explicitly use a
7066
* given event loop instance.
7167
*
72-
* @param null|ConnectorInterface|LoopInterface $connector
73-
* @param null|LoopInterface|ConnectorInterface $loop
74-
* @throws \InvalidArgumentException for invalid arguments
68+
* @param ?ConnectorInterface $connector
69+
* @param ?LoopInterface $loop
7570
*/
76-
public function __construct($connector = null, $loop = null)
71+
public function __construct(ConnectorInterface $connector = null, LoopInterface $loop = null)
7772
{
78-
// swap arguments for legacy constructor signature
79-
if (($connector instanceof LoopInterface || $connector === null) && ($loop instanceof ConnectorInterface || $loop === null)) {
80-
$swap = $loop;
81-
$loop = $connector;
82-
$connector = $swap;
83-
}
84-
85-
if (($connector !== null && !$connector instanceof ConnectorInterface) || ($loop !== null && !$loop instanceof LoopInterface)) {
86-
throw new \InvalidArgumentException('Expected "?ConnectorInterface $connector" and "?LoopInterface $loop" arguments');
87-
}
88-
8973
$loop = $loop ?: Loop::get();
9074
$this->transaction = new Transaction(
9175
Sender::createFromLoop($loop, $connector),

tests/BrowserTest.php

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -70,35 +70,6 @@ public function testConstructWithConnectorAssignsGivenConnector()
7070
$this->assertSame($connector, $ret);
7171
}
7272

73-
public function testConstructWithConnectorWithLegacySignatureAssignsGivenConnector()
74-
{
75-
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
76-
77-
$browser = new Browser(null, $connector);
78-
79-
$ref = new \ReflectionProperty($browser, 'transaction');
80-
$ref->setAccessible(true);
81-
$transaction = $ref->getValue($browser);
82-
83-
$ref = new \ReflectionProperty($transaction, 'sender');
84-
$ref->setAccessible(true);
85-
$sender = $ref->getValue($transaction);
86-
87-
$ref = new \ReflectionProperty($sender, 'http');
88-
$ref->setAccessible(true);
89-
$client = $ref->getValue($sender);
90-
91-
$ref = new \ReflectionProperty($client, 'connectionManager');
92-
$ref->setAccessible(true);
93-
$connectionManager = $ref->getValue($client);
94-
95-
$ref = new \ReflectionProperty($connectionManager, 'connector');
96-
$ref->setAccessible(true);
97-
$ret = $ref->getValue($connectionManager);
98-
99-
$this->assertSame($connector, $ret);
100-
}
101-
10273
public function testConstructWithLoopAssignsGivenLoop()
10374
{
10475
$browser = new Browser(null, $this->loop);
@@ -114,49 +85,6 @@ public function testConstructWithLoopAssignsGivenLoop()
11485
$this->assertSame($this->loop, $loop);
11586
}
11687

117-
public function testConstructWithLoopWithLegacySignatureAssignsGivenLoop()
118-
{
119-
$browser = new Browser($this->loop);
120-
121-
$ref = new \ReflectionProperty($browser, 'transaction');
122-
$ref->setAccessible(true);
123-
$transaction = $ref->getValue($browser);
124-
125-
$ref = new \ReflectionProperty($transaction, 'loop');
126-
$ref->setAccessible(true);
127-
$loop = $ref->getValue($transaction);
128-
129-
$this->assertSame($this->loop, $loop);
130-
}
131-
132-
public function testConstructWithInvalidConnectorThrows()
133-
{
134-
$this->setExpectedException('InvalidArgumentException');
135-
new Browser('foo');
136-
}
137-
138-
public function testConstructWithInvalidLoopThrows()
139-
{
140-
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
141-
142-
$this->setExpectedException('InvalidArgumentException');
143-
new Browser($connector, 'foo');
144-
}
145-
146-
public function testConstructWithConnectorTwiceThrows()
147-
{
148-
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
149-
150-
$this->setExpectedException('InvalidArgumentException');
151-
new Browser($connector, $connector);
152-
}
153-
154-
public function testConstructWithLoopTwiceThrows()
155-
{
156-
$this->setExpectedException('InvalidArgumentException');
157-
new Browser($this->loop, $this->loop);
158-
}
159-
16088
public function testGetSendsGetRequest()
16189
{
16290
$that = $this;

0 commit comments

Comments
 (0)
0