33
44use Nats ;
55use Nats \ConnectionOptions ;
6- use Nats \StreamWrapper ;
76use Prophecy \Argument ;
87
98/**
@@ -18,20 +17,6 @@ class ConnectionTest extends \PHPUnit_Framework_TestCase
1817 */
1918 private $ c ;
2019
21- /**
22- * Process.
23- *
24- * @var resource A separated process.
25- */
26- private static $ process ;
27-
28- /**
29- * Gnatsd switch.
30- *
31- * @var bool Am I using a real or a fake server?
32- */
33- private static $ isGnatsd = false ;
34-
3520
3621 /**
3722 * SetUp test suite.
@@ -41,35 +26,10 @@ class ConnectionTest extends \PHPUnit_Framework_TestCase
4126 public function setUp ()
4227 {
4328 $ options = new ConnectionOptions ();
44- $ streamWrapper = $ this ->getMockStreamSocketClient ();
45-
4629 $ this ->c = new Nats \Connection ($ options );
47- $ this ->c ->setStreamWrapper ($ streamWrapper ->reveal ());
4830 $ this ->c ->connect ();
4931 }
5032
51- /**
52- * Function for building Socket Mock.
53- *
54- * @return StreamWrapper
55- */
56- private function getMockStreamSocketClient ()
57- {
58- $ streamWrapper = $ this ->prophesize ("Nats\StreamWrapper " );
59- $ streamWrapper ->setStreamTimeout (Argument::any (), Argument::any ())->willReturn (true );
60- $ streamWrapper ->getStreamSocketClient (Argument::any (), Argument::any (), Argument::any (), Argument::any (), Argument::any ())->will (function ($ args ) {
61- $ fileName = "/tmp/ " .uniqid ();
62- $ f = fopen ($ fileName , 'w ' );
63- fwrite ($ f , "INFO: \n" );
64- fwrite ($ f , "-ERR \n" );
65-
66- return $ f ;
67-
68- });
69-
70- return $ streamWrapper ;
71- }
72-
7333
7434 /**
7535 * Test Connection.
@@ -130,60 +90,6 @@ public function testReconnect()
13090 $ this ->c ->close ();
13191 }
13292
133- /**
134- * Test Subscription command.
135- *
136- * @return void
137- */
138- public function testSubscription ()
139- {
140- $ callback = function ($ message ) {
141- $ this ->assertNotNull ($ message );
142- $ this ->assertEquals ($ message , 'bar ' );
143- };
144-
145- $ this ->c ->subscribe ('foo ' , $ callback );
146- $ this ->assertGreaterThan (0 , $ this ->c ->subscriptionsCount ());
147- $ subscriptions = $ this ->c ->getSubscriptions ();
148- $ this ->assertInternalType ('array ' , $ subscriptions );
149-
150- $ this ->c ->publish ('foo ' , 'bar ' );
151- $ this ->assertEquals (1 , $ this ->c ->pubsCount ());
152- /*
153- $process = new BackgroundProcess('/usr/bin/php ./test/Util/ClientServerStub.php ');
154- $process->run();
155- */
156- // time_nanosleep(1, 0);
157- $ this ->c ->wait (1 );
158- }
159-
160- /**
161- * Test Queue Subscription command.
162- *
163- * @return void
164- */
165- public function testQueueSubscription ()
166- {
167- $ callback = function ($ message ) {
168- $ this ->assertNotNull ($ message );
169- $ this ->assertEquals ($ message , 'bar ' );
170- };
171-
172- $ this ->c ->queueSubscribe ('foo ' , 'bar ' , $ callback );
173- $ this ->assertGreaterThan (0 , $ this ->c ->subscriptionsCount ());
174- $ subscriptions = $ this ->c ->getSubscriptions ();
175- $ this ->assertInternalType ('array ' , $ subscriptions );
176-
177- $ this ->c ->publish ('foo ' , 'bar ' );
178- $ this ->assertEquals (1 , $ this ->c ->pubsCount ());
179- /*
180- $process = new BackgroundProcess('/usr/bin/php ./test/Util/ClientServerStub.php ');
181- $process->run();
182- */
183- // time_nanosleep(1, 0);
184- $ this ->c ->wait (1 );
185- }
186-
18793 /**
18894 * Test Request command.
18995 *
@@ -226,15 +132,4 @@ function ($res) {
226132
227133 $ this ->assertTrue (true );
228134 }
229-
230- /**
231- * Test setStreamTimeout command.
232- *
233- * @return void
234- */
235- public function testSetStreamTimeout ()
236- {
237- $ this ->assertTrue ($ this ->c ->setStreamTimeout (2 ));
238- $ this ->assertFalse ($ this ->c ->setStreamTimeout ("hello " ));
239- }
240135}
0 commit comments