Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop deprecated alternative Browser constructor argument order #529

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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