33namespace Bolt \tests \connection ;
44
55use Bolt \Bolt ;
6+ use Bolt \connection \IConnection ;
7+ use Bolt \connection \Socket ;
68use Bolt \connection \StreamSocket ;
79use Bolt \error \ConnectException ;
810use Bolt \error \MessageException ;
911use Bolt \helpers \Auth ;
1012use Bolt \protocol \V4 ;
11- use Exception ;
1213use PHPUnit \Framework \TestCase ;
1314use 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