forked from repejota/phpnats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncodedConnectionTest.php
More file actions
91 lines (79 loc) · 1.72 KB
/
Copy pathEncodedConnectionTest.php
File metadata and controls
91 lines (79 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Nats\tests\Unit;
use Nats;
use Nats\Connection;
use Nats\ConnectionOptions;
use Nats\Encoders\JSONEncoder;
/**
* Class EncodedConnectionTest.
*/
class EncodedConnectionTest extends \PHPUnit_Framework_TestCase
{
/**
* Client.
*
* @var Nats\Connection Client
*/
private $c;
/**
* SetUp test suite.
*
* @return void
*/
public function setUp()
{
$encoder = new JSONEncoder();
$options = new ConnectionOptions();
$this->c = new Connection($options, $encoder);
$this->c->connect();
}
/**
* Test Connection.
*
* @return void
*/
public function testConnection()
{
// Connect.
$this->c->connect();
$this->assertTrue($this->c->isConnected());
// Disconnect.
$this->c->close();
$this->assertFalse($this->c->isConnected());
}
/**
* Test Publish command.
*
* @return void
*/
public function testPublish()
{
$this->c->ping();
$this->c->publish('foo', 'bar');
$count = $this->c->pubsCount();
$this->assertInternalType('int', $count);
$this->assertGreaterThan(0, $count);
$this->c->close();
}
/**
* Test Request command.
*
* @return void
*/
public function testRequest()
{
$this->c->subscribe(
'sayhello',
function ($res) {
$res->reply('Hello, '.$res->getBody().' !!!');
}
);
$this->c->request(
'sayhello',
'McFly',
function ($res) {
$this->assertEquals('Hello, McFly !!!', $res->getBody());
}
);
}
}