44use Nats ;
55use Nats \ConnectionOptions ;
66use Nats \StreamWrapper ;
7- use org \bovigo \vfs \vfsStream ;
8- use org \bovigo \vfs \vfsStreamFile ;
97use Prophecy \Argument ;
108
119/**
@@ -43,20 +41,36 @@ class ConnectionTest extends \PHPUnit_Framework_TestCase
4341 public function setUp ()
4442 {
4543 $ options = new ConnectionOptions ();
44+ $ streamWrapper = $ this ->getMockStreamSocketClient ();
4645
46+ $ this ->c = new Nats \Connection ($ options );
47+ $ this ->c ->setStreamWrapper ($ streamWrapper ->reveal ());
48+ $ this ->c ->connect ();
49+ }
50+
51+ /**
52+ * Function for building Socket Mock.
53+ *
54+ * @return StreamWrapper
55+ */
56+ private function getMockStreamSocketClient ()
57+ {
4758 $ streamWrapper = $ this ->prophesize ("Nats\StreamWrapper " );
59+ $ streamWrapper ->setStreamTimeout (Argument::any (), Argument::any ())->willReturn (true );
4860 $ streamWrapper ->getStreamSocketClient (Argument::any (), Argument::any (), Argument::any (), Argument::any (), Argument::any ())->will (function ($ args ) {
49- return fopen ("/tmp/ " .uniqid (), 'w ' );
61+ $ fileName = "/tmp/ " .uniqid ();
62+ $ f = fopen ($ fileName , 'w ' );
63+ fwrite ($ f , "INFO: \n" );
64+ fwrite ($ f , "-ERR \n" );
5065
51- }) ;
66+ return $ f ;
5267
53- $ streamWrapper -> setStreamTimeout (Argument:: any (), Argument:: any ())-> willReturn ( true );
68+ } );
5469
55- $ this ->c = new Nats \Connection ($ options );
56- $ this ->c ->setStreamWrapper ($ streamWrapper ->reveal ());
57- $ this ->c ->connect ();
70+ return $ streamWrapper ;
5871 }
5972
73+
6074 /**
6175 * Test Connection.
6276 *
@@ -73,6 +87,7 @@ public function testConnection()
7387 $ this ->assertFalse ($ this ->c ->isConnected ());
7488 }
7589
90+
7691 /**
7792 * Test Ping command.
7893 *
0 commit comments