1+ <?php
2+ namespace spec \Nats ;
3+
4+ use PhpSpec \ObjectBehavior ;
5+ use Prophecy \Argument ;
6+
7+ class ConnectionSpec extends ObjectBehavior
8+ {
9+ function it_is_initializable ()
10+ {
11+ $ this ->shouldHaveType ('Nats\Connection ' );
12+ }
13+
14+ function it_has_ping_count_to_zero ()
15+ {
16+ $ this ->pingsCount ()->shouldBe (0 );
17+ }
18+
19+ function it_has_pubs_count_to_zero ()
20+ {
21+ $ this ->pubsCount ()->shouldBe (0 );
22+ }
23+
24+ function it_has_reconnects_count_to_zero ()
25+ {
26+ $ this ->reconnectsCount ()->shouldBe (0 );
27+ }
28+
29+ function it_has_subscriptions_count_to_zero ()
30+ {
31+ $ this ->subscriptionsCount ()->shouldBe (0 );
32+ }
33+
34+ function it_subscriptions_array_is_empty ()
35+ {
36+ $ this ->getSubscriptions ()->shouldHaveCount (0 );
37+ }
38+
39+ function it_is_disconnected ()
40+ {
41+ $ this ->isConnected ()->shouldBe (false );
42+ }
43+
44+ function it_can_connect_and_disconnect_with_default_options ()
45+ {
46+ $ this ->connect ();
47+ $ this ->shouldHaveType ('Nats\Connection ' );
48+ $ this ->isConnected ()->shouldBe (true );
49+ $ this ->close ();
50+ $ this ->isConnected ()->shouldBe (false );
51+ }
52+
53+ function it_increases_reconnects_count_on_each_reconnection ()
54+ {
55+ $ this ->connect ();
56+ $ this ->reconnect ();
57+ $ this ->reconnectsCount ()->shouldBe (1 );
58+ $ this ->isConnected ()->shouldBe (true );
59+ $ this ->close ();
60+ }
61+
62+ function it_a_ping_is_sent_after_a_successful_connection ()
63+ {
64+ $ this ->connect ();
65+ $ this ->pingsCount ()->shouldBe (1 );
66+ $ this ->close ();
67+ }
68+
69+ function it_increases_pubs_after_publishing_a_message ()
70+ {
71+ $ this ->connect ();
72+ $ this ->publish ("foo " );
73+ $ this ->pubsCount ()->shouldBe (1 );
74+ $ this ->close ();
75+ }
76+
77+ function it_increases_subscriptions_after_subscribing_to_a_topic ()
78+ {
79+ $ this ->connect ();
80+ $ callback = function ($ payload ) {};
81+ $ sid = $ this ->subscribe ("foo " , $ callback );
82+ $ this ->subscriptionsCount ()->shouldBe (1 );
83+ $ this ->unsubscribe ($ sid );
84+ $ this ->close ();
85+ }
86+
87+ function it_decreases_subscriptions_after_unsubscribing_to_a_topic ()
88+ {
89+ $ this ->connect ();
90+ $ callback = function ($ payload ) {};
91+ $ sid = $ this ->subscribe ("foo " , $ callback );
92+ $ this ->unsubscribe ($ sid );
93+ $ this ->subscriptionsCount ()->shouldBe (0 );
94+ $ this ->close ();
95+ }
96+
97+
98+ }
0 commit comments