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

Commit 03c5e3a

Browse files
author
Raül Pérez
committed
Merge branch 'release/0.0.3'
2 parents 3794c8b + 5c9079e commit 03c5e3a

6 files changed

Lines changed: 74 additions & 44 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ cs:
1313
./phpcbf.phar src
1414
./phpcbf.phar tests
1515
./phpcbf.phar examples
16-
./phpcs.phar src tests examples
16+
./vendor/bin/phpcs src tests examples
1717

1818
.PHONY: lint test cs cover

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
phpnats
1+
phpnats
22
=======
33

44
**Travis**
@@ -18,7 +18,7 @@ A PHP client for the [NATS messaging system](https://nats.io).
1818
Requirements
1919
------------
2020

21-
* php ~5.3
21+
* php ~5.4
2222
* [nats](https://github.com/derekcollison/nats) or [gnatsd](https://github.com/apcera/gnatsd)
2323

2424

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.2
1+
0.0.3

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"email": "repejota@gmail.com",
1010
"homepage": "http://repejota.com"
1111
}],
12-
"require": {},
12+
"require": {
13+
"zerkalica/phpcs": "dev-master"
14+
},
1315
"require-dev": {
1416
"phpunit/phpunit": "4.7.*"
1517
},

src/Connection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ public function getSubscriptions()
137137
*/
138138
public function __construct($host = "localhost", $port = 4222)
139139
{
140+
$this->_pings = 0;
141+
$this->_pubs = 0;
142+
$this->_subscriptions = 0;
143+
140144
$this->_host = $host;
141145
$this->_port = $port;
142146
$this->_address = "tcp://" . $this->_host . ":" . $this->_port;

tests/Unit/ConnectionTest.php

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,57 @@
1616

1717
/**
1818
* Class TestConnection
19+
*
1920
* @category Class
20-
* @package Nats\Tests\Unit
21+
* @package Nats\Tests\Unit
2122
* @author Raül Përez <repejota@gmail.com>
2223
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
2324
* @link https://github.com/repejota/phpnats
2425
*/
2526
class TestConnection extends \PHPUnit_Framework_TestCase
2627
{
28+
private $_c;
29+
30+
/**
31+
* Setup tests
32+
*
33+
* @return null
34+
*/
35+
public function setUp()
36+
{
37+
$this->_c = $this->getMockBuilder('Nats\Connection')->getMock();
38+
39+
$this->_c->expects($this->any())
40+
->method("connect")
41+
->willReturn(null);
42+
43+
$this->_c->expects($this->any())
44+
->method("pingsCount")
45+
->willReturn(1);
46+
47+
$this->_c->expects($this->any())
48+
->method("pubsCount")
49+
->willReturn(1);
50+
51+
$this->_c->expects($this->any())
52+
->method("reconnectsCount")
53+
->willReturn(1);
54+
55+
$this->_c->expects($this->any())
56+
->method("subscriptionsCount")
57+
->willReturn(1);
58+
59+
$this->_c->expects($this->any())
60+
->method("getSubscriptions")
61+
->willReturn(["foo", "bar"]);
62+
}
2763

2864
/**
2965
* Test Dummy
3066
*
3167
* @return null
3268
*/
33-
public function testDummy()
69+
public function testDummy()
3470
{
3571
$this->assertTrue(true);
3672
}
@@ -40,44 +76,37 @@ public function testDummy()
4076
*
4177
* @return null
4278
*/
43-
public function testConnection()
79+
public function testConnection()
4480
{
45-
$c = new Nats\Connection();
46-
$c->connect();
47-
$c->close();
81+
$this->_c->connect();
82+
$this->_c->close();
4883
}
4984

5085
/**
5186
* Test Ping command
5287
*
5388
* @return null
5489
*/
55-
public function testPing()
90+
public function testPing()
5691
{
57-
$c = new Nats\Connection();
58-
$c->connect();
59-
$c->ping();
60-
$c->ping();
61-
$count = $c->pingsCount();
92+
$count = $this->_c->pingsCount();
6293
$this->assertInternalType("int", $count);
6394
$this->assertGreaterThan(0, $count);
64-
$c->close();
95+
$this->_c->close();
6596
}
6697

6798
/**
6899
* Test Publish command
69100
*
70101
* @return null
71102
*/
72-
public function testPublish()
103+
public function testPublish()
73104
{
74-
$c = new Nats\Connection();
75-
$c->connect();
76-
$c->publish("foo", "bar");
77-
$count = $c->pubsCount();
78-
$this->assertInternalType("int", $count);
79-
$this->assertGreaterThan(0, $count);
80-
$c->close();
105+
$this->_c->publish("foo", "bar");
106+
$this->count = $this->_c->pubsCount();
107+
$this->assertInternalType("int", $this->count);
108+
$this->assertGreaterThan(0, $this->count);
109+
$this->_c->close();
81110
}
82111

83112
/**
@@ -87,13 +116,11 @@ public function testPublish()
87116
*/
88117
public function testReconnect()
89118
{
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();
119+
$this->_c->reconnect();
120+
$this->count = $this->_c->reconnectsCount();
121+
$this->assertInternalType("int", $this->count);
122+
$this->assertGreaterThan(0, $this->count);
123+
$this->_c->close();
97124
}
98125

99126
/**
@@ -103,18 +130,15 @@ public function testReconnect()
103130
*/
104131
public function testSubscription()
105132
{
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();
133+
$callback = function ($message) {
134+
$this->assertNotNull($message);
135+
};
136+
$this->_c->subscribe("foo", $callback);
137+
$this->assertGreaterThan(0, $this->_c->subscriptionsCount());
138+
$subscriptions = $this->_c->getSubscriptions();
115139
$this->assertInternalType("array", $subscriptions);
116140

117-
$c->publish("foo", "bar");
118-
$c->wait(1);
141+
$this->_c->publish("foo", "bar");
142+
$this->_c->wait(1);
119143
}
120144
}

0 commit comments

Comments
 (0)