Skip to content

Commit

Permalink
Merge pull request #529 from clue-labs/drop-browser-alternative
Browse files Browse the repository at this point in the history
Drop deprecated alternative `Browser` constructor argument order
  • Loading branch information
WyriHaximus authored May 24, 2024
2 parents 170547b + 6956fe2 commit da8ee09
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 95 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1863,11 +1863,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,
Expand Down
22 changes: 3 additions & 19 deletions src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
72 changes: 0 additions & 72 deletions tests/BrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit da8ee09

Please sign in to comment.