8000 Merge pull request #315 from clue-labs/drop-connector-alternative · reactphp/socket@a2b4fe1 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit a2b4fe1

Browse files
authored
Merge pull request #315 from clue-labs/drop-connector-alternative
Drop deprecated alternative `Connector` constructor argument order
2 parents 874deeb + e7e3b55 commit a2b4fe1

File tree

3 files changed

+3
-106
lines changed

3 files changed

+3
-106
lines changed

README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,18 +1150,6 @@ here in order to use the [default loop](https://github.com/reactphp/event-loop#l
11501150
This value SHOULD NOT be given unless you're sure you want to explicitly use a
11511151
given event loop instance.
11521152

1153-
> Changelog v1.9.0: The constructur signature has been updated to take the
1154-
> optional `$context` as the first parameter and the optional `$loop` as a second
1155-
> argument. The previous signature has been deprecated and should not be used anymore.
1156-
>
1157-
> ```php
1158-
> // constructor signature as of v1.9.0
1159-
> $connector = new React\Socket\Connector(array $context = [], ?LoopInterface $loop = null);
1160-
>
1161-
> // legacy constructor signature before v1.9.0
1162-
> $connector = new React\Socket\Connector(?LoopInterface $loop = null, array $context = []);
1163-
> ```
1164-
11651153
### Advanced client usage
11661154

11671155
#### TcpConnector

src/Connector.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ final class Connector implements ConnectorInterface
3636
* This class takes two optional arguments for more advanced usage:
3737
*
3838
* ```php
39-
* // constructor signature as of v1.9.0
4039
* $connector = new React\Socket\Connector(array $context = [], ?LoopInterface $loop = null);
41-
*
42-
* // legacy constructor signature before v1.9.0
43-
* $connector = new React\Socket\Connector(?LoopInterface $loop = null, array $context = []);
4440
* ```
4541
*
4642
* This class takes an optional `LoopInterface|null $loop` parameter that can be used to
@@ -49,23 +45,12 @@ final class Connector implements ConnectorInterface
4945
* This value SHOULD NOT be given unless you're sure you want to explicitly use a
5046
* given event loop instance.
5147
*
52-
* @param array|LoopInterface|null $context
53-
* @param null|LoopInterface|array $loop
48+
* @param array $context
49+
* @param ?LoopInterface $loop
5450
* @throws \InvalidArgumentException for invalid arguments
5551
*/
56-
public function __construct($context = array(), $loop = null)
52+
public function __construct(array $context = array(), LoopInterface $loop = null)
5753
{
58-
// swap arguments for legacy constructor signature
59-
if (($context instanceof LoopInterface || $context === null) && (\func_num_args() <= 1 || \is_array($loop))) {
60-
$swap = $loop === null ? array(): $loop;
61-
$loop = $context;
62-
$context = $swap;
63-
}
64-
65-
if (!\is_array($context) || ($loop !== null && !$loop instanceof LoopInterface)) {
66-
throw new \InvalidArgumentException('Expected "array $context" and "?LoopInterface $loop" arguments');
67-
}
68-
6954
// apply default options if not explicitly given
7055
$context += array(
7156
'tcp' => true,

tests/ConnectorTest.php

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -56,82 +56,6 @@ public function testConstructWithContextAssignsGivenContext()
5656
$this->assertSame($tcp, $connectors['tcp']);
5757
}
5858

59-
public function testConstructWithLegacyContextSignatureAssignsGivenContext()
60-
{
61-
$tcp = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
62-
63-
$connector = new Connector(null, array(
64-
'tcp' => $tcp,
65-
'dns' => false,
66-
'timeout' => false
67-
));
68-
6 8000 9-
$ref = new \ReflectionProperty($connector, 'connectors');
70-
$ref->setAccessible(true);
71-
$connectors = $ref->getValue($connector);
72-
73-
$this->assertSame($tcp, $connectors['tcp']);
74-
}
75-
76-
public function testConstructWithLegacyLoopSignatureAssignsGivenLoop()
77-
{
78-
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
79-
80-
$connector = new Connector($loop);
81-
82-
$ref = new \ReflectionProperty($connector, 'connectors');
83-
$ref->setAccessible(true);
84-
$connectors = $ref->getValue($connector);
85-
86-
$ref = new \ReflectionProperty($connectors['tcp'], 'loop');
87-
$ref->setAccessible(true);
88-
$loop = $ref->getValue($connectors['tcp']);
89-
90-
$this->assertInstanceOf('React\EventLoop\LoopInterface', $loop);
91-
}
92-
93-
public function testConstructWithInvalidContextThrows()
94-
{
95-
$this->setExpectedException('InvalidArgumentException');
96-
new Connector('foo');
97-
}
98-
99-
public function testConstructWithInvalidLoopThrows()
100-
{
101-
$this->setExpectedException('InvalidArgumentException');
102-
new Connector(array(), 'foo');
103-
}
104-
105-
public function testConstructWithContextTwiceThrows()
106-
{
107-
$this->setExpectedException('InvalidArgumentException');
108-
new Connector(array(), array());
109-
}
110-
111-
public function testConstructWithLoopTwiceThrows()
112-
{
113-
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
114-
115-
$this->setExpectedException('InvalidArgumentException');
116-
new Connector($loop, $loop);
117-
}
118-
119-
public function testConstructWithNullContextAndLoopThrows()
120-
{
121-
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
122-
123-
$this->setExpectedException('InvalidArgumentException');
124-
new Connector(null, $loop);
125-
}
126-
127-
public function testConstructWithLoopAndNullContextThrows()
128-
{
129-
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
130-
131-
$this->setExpectedException('InvalidArgumentException');
132-
new Connector($loop, null);
133-
}
134-
13559
public function testConnectorUsesTcpAsDefaultScheme()
13660
{
13761
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();

0 commit comments

Comments
 (0)
0