Skip to content

Commit b71dba7

Browse files
committed
created tests for both sockets
1 parent e11f6ef commit b71dba7

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

src/connection/Socket.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@ public function setTimeout(float $timeout): void
128128
$this->configureTimeout();
129129
}
130130

131-
/**
132-
* @return void
133-
*/
134131
private function configureTimeout(): void
135132
{
136133
$timeoutSeconds = floor($this->timeout);

tests/connection/StreamSocketTest.php renamed to tests/connection/AConnectionTest.php

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,34 @@
33
namespace Bolt\tests\connection;
44

55
use Bolt\Bolt;
6+
use Bolt\connection\IConnection;
7+
use Bolt\connection\Socket;
68
use Bolt\connection\StreamSocket;
79
use Bolt\error\ConnectException;
810
use Bolt\error\MessageException;
911
use Bolt\helpers\Auth;
1012
use Bolt\protocol\V4;
11-
use Exception;
1213
use PHPUnit\Framework\TestCase;
1314
use function microtime;
1415

15-
final class StreamSocketTest extends TestCase
16+
final class AConnectionTest extends TestCase
1617
{
18+
public function provideConnections(): array
19+
{
20+
return [
21+
[StreamSocket::class],
22+
[Socket::class],
23+
];
24+
}
25+
1726
/**
18-
* @throws Exception
27+
* @dataProvider provideConnections
1928
*/
20-
public function testMillisecondTimeout(): void
29+
public function testMillisecondTimeout(string $alias): void
2130
{
22-
$socket = new StreamSocket($GLOBALS['NEO_HOST'] ?? '127.0.0.1', (int) ($GLOBALS['NEO_PORT'] ?? 7687), 1.5);
23-
$bolt = new Bolt($socket);
24-
$protocol = $bolt->build();
31+
$socket = $this->getConnection($alias);
32+
$protocol = (new Bolt($socket))->build();
33+
$socket->setTimeout(1.5);
2534
$protocol->init(Auth::basic($GLOBALS['NEO_USER'], $GLOBALS['NEO_PASS']));
2635

2736
$time = microtime(true);
@@ -39,13 +48,12 @@ public function testMillisecondTimeout(): void
3948
}
4049

4150
/**
42-
* @throws Exception
51+
* @dataProvider provideConnections
4352
*/
44-
public function testSecondsTimeout(): void
53+
public function testSecondsTimeout(string $alias): void
4554
{
46-
$socket = new StreamSocket($GLOBALS['NEO_HOST'] ?? '127.0.0.1', (int) ($GLOBALS['NEO_PORT'] ?? 7687), 1);
47-
$bolt = new Bolt($socket);
48-
$protocol = $bolt->build();
55+
$socket = $this->getConnection($alias);
56+
$protocol = (new Bolt($socket))->build();
4957
$protocol->init(Auth::basic($GLOBALS['NEO_USER'], $GLOBALS['NEO_PASS']));
5058

5159
$time = microtime(true);
@@ -61,8 +69,12 @@ public function testSecondsTimeout(): void
6169
}
6270
}
6371

64-
public function testTimeoutRecoverAndReset(): void
72+
/**
73+
* @dataProvider provideConnections
74+
*/
75+
public function testTimeoutRecoverAndReset(string $alias): void
6576
{
77+
$socket = $this->getConnection($alias);
6678
$streamSocket = new StreamSocket($GLOBALS['NEO_HOST'] ?? '127.0.0.1', (int) ($GLOBALS['NEO_PORT'] ?? 7687), 1);
6779
/** @var V4 $protocol */
6880
$protocol = (new Bolt($streamSocket))->build();
@@ -104,4 +116,9 @@ public function testTimeoutRecoverAndReset(): void
104116
$this->assertEqualsWithDelta(1.0, $newTime - $time, 0.2);
105117
}
106118
}
119+
120+
private function getConnection(string $class): IConnection
121+
{
122+
return new $class($GLOBALS['NEO_HOST'] ?? '127.0.0.1', (int) ($GLOBALS['NEO_PORT'] ?? 7687), 1);
123+
}
107124
}

0 commit comments

Comments
 (0)