11<?php
2-
32namespace Nats \tests \Unit ;
43
54use Nats ;
@@ -27,20 +26,24 @@ class ConnectionTest extends \PHPUnit_Framework_TestCase
2726 private static $ isGnatsd = false ;
2827
2928 /**
30- * Before Class code setup.
29+ * Before Class code setup
30+ *
31+ * @return void
3132 */
3233 public static function setUpBeforeClass ()
3334 {
34- if (($ socket = @fsockopen (' localhost ' , 4222 , $ err )) !== false ) {
35- self ::$ isGnatsd = true ;
35+ if (($ socket = @fsockopen (" localhost " , 4222 , $ err ))!==false ) {
36+ self ::$ isGnatsd = true ;
3637 } else {
3738 self ::$ process = new BackgroundProcess ('/usr/bin/php ./tests/Util/ListeningServerStub.php ' );
3839 self ::$ process ->run ();
3940 }
4041 }
4142
4243 /**
43- * After Class code setup.
44+ * After Class code setup
45+ *
46+ * @return void
4447 */
4548 public static function tearDownAfterClass ()
4649 {
@@ -50,21 +53,26 @@ public static function tearDownAfterClass()
5053 }
5154
5255 /**
53- * setUp test suite.
56+ * setUp test suite
57+ *
58+ * @return void
5459 */
5560 public function setUp ()
5661 {
5762 $ options = new ConnectionOptions ();
5863 if (!self ::$ isGnatsd ) {
59- time_nanosleep (0 , 300000000 );
64+ time_nanosleep (1 , 700000000 );
6065 $ options ->port = 4222 ;
6166 }
6267 $ this ->c = new Nats \Connection ($ options );
6368 $ this ->c ->connect ();
6469 }
6570
71+
6672 /**
6773 * Test Connection.
74+ *
75+ * @return void
6876 */
6977 public function testConnection ()
7078 {
@@ -77,22 +85,10 @@ public function testConnection()
7785 $ this ->assertFalse ($ this ->c ->isConnected ());
7886 }
7987
80- /**
81- * Test Connection with bad configuration.
82- *
83- * @expectedException PHPUnit_Framework_Error
84- */
85- public function testConnectionBadStream ()
86- {
87- $ options = new ConnectionOptions ();
88- $ options ->host = null ;
89- $ options ->port = null ;
90- $ this ->c = new Nats \Connection ($ options );
91- $ this ->c ->connect ();
92- }
93-
9488 /**
9589 * Test Ping command.
90+ *
91+ * @return void
9692 */
9793 public function testPing ()
9894 {
@@ -103,9 +99,10 @@ public function testPing()
10399 $ this ->c ->close ();
104100 }
105101
106-
107102 /**
108103 * Test Publish command.
104+ *
105+ * @return void
109106 */
110107 public function testPublish ()
111108 {
@@ -117,9 +114,10 @@ public function testPublish()
117114 $ this ->c ->close ();
118115 }
119116
120-
121117 /**
122118 * Test Reconnect command.
119+ *
120+ * @return void
123121 */
124122 public function testReconnect ()
125123 {
@@ -132,50 +130,27 @@ public function testReconnect()
132130
133131 /**
134132 * Test Subscription command.
133+ *
134+ * @return void
135135 */
136136 public function testSubscription ()
137137 {
138-
139138 $ callback = function ($ message ) {
140139 $ this ->assertNotNull ($ message );
141140 $ this ->assertEquals ($ message , 'bar ' );
142141 };
143- $ sid = $ this ->c ->subscribe ('foo ' , $ callback );
144142
143+ $ this ->c ->subscribe ('foo ' , $ callback );
145144 $ this ->assertGreaterThan (0 , $ this ->c ->subscriptionsCount ());
146-
147145 $ subscriptions = $ this ->c ->getSubscriptions ();
148146 $ this ->assertInternalType ('array ' , $ subscriptions );
149147
150148 $ this ->c ->publish ('foo ' , 'bar ' );
151149 $ this ->assertEquals (1 , $ this ->c ->pubsCount ());
152150
153- $ process = new BackgroundProcess ('/usr/bin/php ./tests/Util/ClientServerStub.php ' . $ sid );
151+ $ process = new BackgroundProcess ('/usr/bin/php ./tests/Util/ClientServerStub.php ' );
154152 $ process ->run ();
155-
153+ // time_nanosleep(1, 0);
156154 $ this ->c ->wait (1 );
157155 }
158-
159- /**
160- * Test Unsubscription command.
161- */
162- public function testUnSubscription ()
163- {
164- $ callback = function ($ message ) {
165- $ this ->assertNotNull ($ message );
166- $ this ->assertEquals ($ message , 'bar ' );
167- };
168-
169- $ sid = $ this ->c ->subscribe ('foo ' , $ callback );
170-
171- $ this ->assertGreaterThan (0 , $ this ->c ->subscriptionsCount ());
172- $ subscriptions = $ this ->c ->getSubscriptions ();
173- $ this ->assertInternalType ('array ' , $ subscriptions );
174-
175- $ this ->c ->publish ('foo ' , 'bar ' );
176- $ this ->assertEquals (1 , $ this ->c ->pubsCount ());
177-
178- $ this ->c ->unsubscribe ($ sid );
179- $ this ->assertEquals (0 , $ this ->c ->subscriptionsCount ());
180- }
181156}
0 commit comments