Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3abb49d

Browse files
committed
Reduce number of references by discarding internal previous Exception
1 parent 8d396d6 commit 3abb49d

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

src/SecureConnector.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ public function connect($uri)
6262

6363
throw new \RuntimeException(
6464
'Connection to ' . $uri . ' failed during TLS handshake: ' . $error->getMessage(),
65-
0,
66-
$error
65+
$error->getCode()
6766
);
6867
});
6968
});

src/SecureServer.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ function ($conn) use ($that) {
186186
function ($error) use ($that, $connection) {
187187
$error = new \RuntimeException(
188188
'Connection from ' . $connection->getRemoteAddress() . ' failed during TLS handshake: ' . $error->getMessage(),
189-
$error->getCode(),
190-
$error
189+
$error->getCode()
191190
);
192191

193192
$that->emit('error', array($error));

tests/FunctionalSecureServerTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ public function testEmitsErrorIfConnectionIsClosedBeforeHandshake()
425425
$this->assertStringStartsWith('Connection from tcp://', $error->getMessage());
426426
$this->assertStringEndsWith('failed during TLS handshake: Connection lost during TLS handshake', $error->getMessage());
427427
$this->assertEquals(defined('SOCKET_ECONNRESET') ? SOCKET_ECONNRESET : 0, $error->getCode());
428+
$this->assertNull($error->getPrevious());
428429
}
429430

430431
public function testEmitsErrorIfConnectionIsClosedWithIncompleteHandshake()
@@ -452,6 +453,7 @@ public function testEmitsErrorIfConnectionIsClosedWithIncompleteHandshake()
452453
$this->assertStringStartsWith('Connection from tcp://', $error->getMessage());
453454
$this->assertStringEndsWith('failed during TLS handshake: Connection lost during TLS handshake', $error->getMessage());
454455
$this->assertEquals(defined('SOCKET_ECONNRESET') ? SOCKET_ECONNRESET : 0, $error->getCode());
456+
$this->assertNull($error->getPrevious());
455457
}
456458

457459
public function testEmitsNothingIfConnectionIsIdle()

tests/SecureConnectorTest.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,13 @@ public function testStreamEncryptionWillBeEnabledAfterConnecting()
107107
$promise = $this->connector->connect('example.com:80');
108108
}
109109

110-
/**
111-
* @expectedException RuntimeException
112-
* @expectedExceptionMessage Connection to example.com:80 failed during TLS handshake: TLS error
113-
*/
114110
public function testConnectionWillBeRejectedIfStreamEncryptionFailsAndClosesConnection()
115111
{
116112
$connection = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->getMock();
117113
$connection->expects($this->once())->method('close');
118114

119115
$encryption = $this->getMockBuilder('React\Socket\StreamEncryption')->disableOriginalConstructor()->getMock();
120-
$encryption->expects($this->once())->method('enable')->willReturn(Promise\reject(new \RuntimeException('TLS error')));
116+
$encryption->expects($this->once())->method('enable')->willReturn(Promise\reject(new \RuntimeException('TLS error', 123)));
121117

122118
$ref = new \ReflectionProperty($this->connector, 'streamEncryption');
123119
$ref->setAccessible(true);
@@ -128,7 +124,13 @@ public function testConnectionWillBeRejectedIfStreamEncryptionFailsAndClosesConn
128124

129125
$promise = $this->connector->connect('example.com:80');
130126

131-
$this->throwRejection($promise);
127+
try {
128+
$this->throwRejection($promise);
129+
} catch (\RuntimeException $e) {
130+
$this->assertEquals('Connection to example.com:80 failed during TLS handshake: TLS error', $e->getMessage());
131+
$this->assertEquals(123, $e->getCode());
132+
$this->assertNull($e->getPrevious());
133+
}
132134
}
133135

134136
/**

0 commit comments

Comments
 (0)