33
44use Nats ;
55use Nats \ConnectionOptions ;
6- use Cocur \BackgroundProcess \BackgroundProcess ;
6+ use Nats \StreamWrapper ;
7+ use org \bovigo \vfs \vfsStream ;
8+ use org \bovigo \vfs \vfsStreamFile ;
9+ use Prophecy \Argument ;
710
811/**
912 * Class ConnectionTest.
@@ -31,32 +34,6 @@ class ConnectionTest extends \PHPUnit_Framework_TestCase
3134 */
3235 private static $ isGnatsd = false ;
3336
34- /**
35- * Before Class code setup.
36- *
37- * @return void
38- */
39- public static function setUpBeforeClass ()
40- {
41- if (($ socket = @fsockopen ("localhost " , 4222 , $ err ))!==false ) {
42- self ::$ isGnatsd = true ;
43- } else {
44- self ::$ process = new BackgroundProcess ('/usr/bin/php ./tests/Util/ListeningServerStub.php ' );
45- self ::$ process ->run ();
46- }
47- }
48-
49- /**
50- * After Class code setup.
51- *
52- * @return void
53- */
54- public static function tearDownAfterClass ()
55- {
56- if (!self ::$ isGnatsd ) {
57- self ::$ process ->stop ();
58- }
59- }
6037
6138 /**
6239 * SetUp test suite.
@@ -66,15 +43,20 @@ public static function tearDownAfterClass()
6643 public function setUp ()
6744 {
6845 $ options = new ConnectionOptions ();
69- if (!self ::$ isGnatsd ) {
70- time_nanosleep (1 , 700000000 );
71- $ options ->setPort (4222 );
72- }
46+
47+ $ streamWrapper = $ this ->prophesize ("Nats\StreamWrapper " );
48+ $ streamWrapper ->getStreamSocketClient (Argument::any (), Argument::any (), Argument::any (), Argument::any (), Argument::any ())->will (function ($ args ) {
49+ return fopen ("/tmp/ " .uniqid (), 'w ' );
50+
51+ });
52+
53+ $ streamWrapper ->setStreamTimeout (Argument::any (), Argument::any ())->willReturn (true );
54+
7355 $ this ->c = new Nats \Connection ($ options );
56+ $ this ->c ->setStreamWrapper ($ streamWrapper ->reveal ());
7457 $ this ->c ->connect ();
7558 }
7659
77-
7860 /**
7961 * Test Connection.
8062 *
@@ -122,7 +104,6 @@ public function testPublish()
122104
123105 /**
124106 * Test Reconnect command.
125- *
126107 * @return void
127108 */
128109 public function testReconnect ()
@@ -153,9 +134,10 @@ public function testSubscription()
153134
154135 $ this ->c ->publish ('foo ' , 'bar ' );
155136 $ this ->assertEquals (1 , $ this ->c ->pubsCount ());
156-
137+ /*
157138 $process = new BackgroundProcess('/usr/bin/php ./tests/Util/ClientServerStub.php ');
158139 $process->run();
140+ */
159141 // time_nanosleep(1, 0);
160142 $ this ->c ->wait (1 );
161143 }
0 commit comments