Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit afd41d8

Browse files
author
Raül Pérez
committed
Added more tests
1 parent 4622b13 commit afd41d8

3 files changed

Lines changed: 46 additions & 7 deletions

File tree

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ cs:
1414
./phpcbf.phar tests
1515
./phpcbf.phar examples
1616
./phpcs.phar src tests examples
17+
18+
.PHONY: lint test cs cover

src/Connection.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,6 @@ public function wait($quantity = 0)
282282
while (!feof($this->_fp)) {
283283
$line = $this->_receive();
284284

285-
// Debug
286-
if ($line) {
287-
echo ">>>>>>>>> " . $line . PHP_EOL;
288-
}
289-
290285
// PING
291286
if (strpos($line, 'PING') === 0) {
292287
$this->_send("PONG");

tests/Unit/ConnectionTest.php

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public function testPing()
5858
$c->connect();
5959
$c->ping();
6060
$c->ping();
61-
$this->assertGreaterThan(0, $c->pingsCount());
61+
$count = $c->pingsCount();
62+
$this->assertInternalType("int", $count);
63+
$this->assertGreaterThan(0, $count);
6264
$c->close();
6365
}
6466

@@ -72,7 +74,47 @@ public function testPublish()
7274
$c = new Nats\Connection();
7375
$c->connect();
7476
$c->publish("foo", "bar");
75-
$this->assertGreaterThan(0, $c->pubsCount());
77+
$count = $c->pubsCount();
78+
$this->assertInternalType("int", $count);
79+
$this->assertGreaterThan(0, $count);
7680
$c->close();
7781
}
82+
83+
/**
84+
* Test Server reconnection
85+
*
86+
* @return null
87+
*/
88+
public function testReconnect()
89+
{
90+
$c = new Nats\Connection();
91+
$c->connect();
92+
$c->reconnect();
93+
$count = $c->reconnectsCount();
94+
$this->assertInternalType("int", $count);
95+
$this->assertGreaterThan(0, $count);
96+
$c->close();
97+
}
98+
99+
/**
100+
* Test Server subscription
101+
*
102+
* @return null
103+
*/
104+
public function testSubscription()
105+
{
106+
$c = new Nats\Connection();
107+
$c->connect();
108+
$c->subscribe(
109+
"foo", function ($message) {
110+
$this->assertNotNull($message);
111+
}
112+
);
113+
$this->assertGreaterThan(0, $c->subscriptionsCount());
114+
$subscriptions = $c->getSubscriptions();
115+
$this->assertInternalType("array", $subscriptions);
116+
117+
$c->publish("foo", "bar");
118+
$c->wait(1);
119+
}
78120
}

0 commit comments

Comments
 (0)