1
1
<?php
2
+
2
3
/**
3
- * TestConnection Class
4
+ * TestConnection Class.
4
5
*
5
6
* PHP version 5
6
7
*
7
8
* @category Class
8
- * @package Nats\Tests\Unit
9
+ *
9
10
* @author Raül Përez <[email protected] >
10
11
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
12
+ *
11
13
* @link https://github.com/repejota/phpnats
12
14
*/
13
- namespace Nats \Tests \Unit ;
15
+
16
+ namespace Nats \tests \Unit ;
14
17
15
18
use Nats ;
19
+ use Cocur \BackgroundProcess \BackgroundProcess ;
20
+
21
+
16
22
17
23
/**
18
- * Class TestConnection
24
+ * Class TestConnection.
19
25
*
20
26
* @category Class
21
- * @package Nats\Tests\Unit
27
+ *
22
28
* @author Raül Përez <[email protected] >
23
29
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
30
+ *
24
31
* @link https://github.com/repejota/phpnats
25
32
*/
26
- class TestConnection extends \PHPUnit_Framework_TestCase
33
+ class ConnectionTest extends \PHPUnit_Framework_TestCase
27
34
{
28
35
private $ _c ;
29
36
30
- /**
31
- * Setup tests
32
- *
33
- * @return null
34
- */
37
+ private static $ _process ;
38
+
39
+ private static $ _port ;
40
+
41
+ public static function setUpBeforeClass ()
42
+ {
43
+
44
+ self ::$ _process = new BackgroundProcess ('/usr/bin/php tests/Unit/ListeningServerStub.php & ' );
45
+ self ::$ _process ->run ();
46
+
47
+ }
48
+
49
+ public static function tearDownAfterClass ()
50
+ {
51
+ self ::$ _process ->stop ();
52
+ //socket_close(self::$_server);
53
+ }
54
+
35
55
public function setUp ()
36
56
{
37
- $ this ->_c = new Nats \Connection ();
57
+ $ this ->_c = new Nats \Connection (' localhost ' , 55555 );
38
58
$ this ->_c ->connect ();
39
59
}
40
60
41
61
/**
42
- * Test Dummy
43
- *
44
- * @return null
62
+ * Test Dummy.
45
63
*/
46
64
public function testDummy ()
47
65
{
48
66
$ this ->assertTrue (true );
49
67
}
50
68
51
69
/**
52
- * Test Connection
53
- *
54
- * @return null
70
+ * Test Connection.
55
71
*/
56
72
public function testConnection ()
57
73
{
@@ -65,66 +81,61 @@ public function testConnection()
65
81
}
66
82
67
83
/**
68
- * Test Ping command
69
- *
70
- * @return null
84
+ * Test Ping command.
71
85
*/
72
86
public function testPing ()
73
87
{
74
88
$ this ->_c ->ping ();
75
89
$ count = $ this ->_c ->pingsCount ();
76
- $ this ->assertInternalType (" int " , $ count );
90
+ $ this ->assertInternalType (' int ' , $ count );
77
91
$ this ->assertGreaterThan (0 , $ count );
78
92
$ this ->_c ->close ();
79
93
}
80
94
81
95
/**
82
- * Test Publish command
83
- *
84
- * @return null
96
+ * Test Publish command.
85
97
*/
86
98
public function testPublish ()
87
99
{
88
- $ this ->_c ->publish (" foo " , " bar " );
100
+ $ this ->_c ->publish (' foo ' , ' bar ' );
89
101
$ count = $ this ->_c ->pubsCount ();
90
- $ this ->assertInternalType (" int " , $ count );
102
+ $ this ->assertInternalType (' int ' , $ count );
91
103
$ this ->assertGreaterThan (0 , $ count );
92
104
$ this ->_c ->close ();
93
105
}
94
106
95
107
/**
96
- * Test Server reconnection
97
- *
98
- * @return null
108
+ * Test Reconnect command.
99
109
*/
100
110
public function testReconnect ()
101
111
{
102
112
$ this ->_c ->reconnect ();
103
113
$ count = $ this ->_c ->reconnectsCount ();
104
- $ this ->assertInternalType (" int " , $ count );
114
+ $ this ->assertInternalType (' int ' , $ count );
105
115
$ this ->assertGreaterThan (0 , $ count );
106
116
$ this ->_c ->close ();
107
117
}
108
118
109
119
/**
110
- * Test Server subscription
111
- *
112
- * @return null
120
+ * Test Subscription command.
113
121
*/
114
122
public function testSubscription ()
115
123
{
116
124
$ callback = function ($ message ) {
117
125
$ this ->assertNotNull ($ message );
118
- $ this ->assertEquals ($ message , " bar " );
126
+ $ this ->assertEquals ($ message , ' bar ' );
119
127
};
120
- $ this ->_c ->subscribe (" foo " , $ callback );
128
+ $ this ->_c ->subscribe (' foo ' , $ callback );
121
129
$ this ->assertGreaterThan (0 , $ this ->_c ->subscriptionsCount ());
122
-
123
130
$ subscriptions = $ this ->_c ->getSubscriptions ();
124
- $ this ->assertInternalType (" array " , $ subscriptions );
131
+ $ this ->assertInternalType (' array ' , $ subscriptions );
125
132
126
- $ this ->_c ->publish ("foo " , "bar " );
127
- $ this ->_c ->wait (1 );
133
+ $ this ->_c ->publish ('foo ' , 'bar ' );
134
+ $ this ->assertEquals (1 , $ this ->_c ->pubsCount ());
135
+ // $this->_c->wait(1);
128
136
}
129
137
138
+ public function testWait ()
139
+ {
140
+ }
130
141
}
0 commit comments