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

Commit 7a8fdda

Browse files
committed
Merge pull request repejota#22 from octante/changed-vars-visibility-connection-options
Changed vars visibility from ConnectionOptions
2 parents 7e1a7f2 + 6969290 commit 7a8fdda

3 files changed

Lines changed: 273 additions & 10 deletions

File tree

src/ConnectionOptions.php

Lines changed: 225 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,63 +12,63 @@ class ConnectionOptions
1212
*
1313
* @var string
1414
*/
15-
public $host = "localhost";
15+
private $host = "localhost";
1616

1717
/**
1818
* Port number to connect
1919
*
2020
* @var integer
2121
*/
22-
public $port = 4222;
22+
private $port = 4222;
2323

2424
/**
2525
* Username to connect
2626
*
2727
* @var string
2828
*/
29-
public $user = null;
29+
private $user = null;
3030

3131
/**
3232
* Password to connect
3333
*
3434
* @var string
3535
*/
36-
public $pass = null;
36+
private $pass = null;
3737

3838
/**
3939
* Language of this client
4040
*
4141
* @var string
4242
*/
43-
public $lang = "php";
43+
private $lang = "php";
4444

4545
/**
4646
* Version of this client
4747
*
4848
* @var string
4949
*/
50-
public $version = "0.0.5";
50+
private $version = "0.0.5";
5151

5252
/**
5353
* If verbose mode is enabled
5454
*
5555
* @var boolean
5656
*/
57-
public $verbose = false;
57+
private $verbose = false;
5858

5959
/**
6060
* If pedantic mode is enabled
6161
*
6262
* @var boolean
6363
*/
64-
public $pedantic = false;
64+
private $pedantic = false;
6565

6666
/**
6767
* If reconnect mode is enabled
6868
*
6969
* @var boolean
7070
*/
71-
public $reconnect = true;
71+
private $reconnect = true;
7272

7373
/**
7474
* Get the URI for a server
@@ -101,4 +101,220 @@ public function toJSON()
101101
}
102102
return json_encode($a);
103103
}
104+
105+
/**
106+
* Get host
107+
*
108+
* @return string
109+
*/
110+
public function getHost()
111+
{
112+
return $this->host;
113+
}
114+
115+
/**
116+
* Set host
117+
*
118+
* @param string $host Host.
119+
*
120+
* @return $this
121+
*/
122+
public function setHost($host)
123+
{
124+
$this->host = $host;
125+
126+
return $this;
127+
}
128+
129+
/**
130+
* Get port
131+
*
132+
* @return integer
133+
*/
134+
public function getPort()
135+
{
136+
return $this->port;
137+
}
138+
139+
/**
140+
* Set port
141+
*
142+
* @param integer $port Port.
143+
*
144+
* @return $this
145+
*/
146+
public function setPort($port)
147+
{
148+
$this->port = $port;
149+
150+
return $this;
151+
}
152+
153+
/**
154+
* Get user
155+
*
156+
* @return string
157+
*/
158+
public function getUser()
159+
{
160+
return $this->user;
161+
}
162+
163+
/**
164+
* Set user
165+
*
166+
* @param string $user User.
167+
*
168+
* @return $this
169+
*/
170+
public function setUser($user)
171+
{
172+
$this->user = $user;
173+
174+
return $this;
175+
}
176+
177+
/**
178+
* Get password
179+
*
180+
* @return string
181+
*/
182+
public function getPass()
183+
{
184+
return $this->pass;
185+
}
186+
187+
/**
188+
* Set password
189+
*
190+
* @param string $pass Password.
191+
*
192+
* @return $this
193+
*/
194+
public function setPass($pass)
195+
{
196+
$this->pass = $pass;
197+
198+
return $this;
199+
}
200+
201+
/**
202+
* Get language
203+
*
204+
* @return string
205+
*/
206+
public function getLang()
207+
{
208+
return $this->lang;
209+
}
210+
211+
/**
212+
* Set language
213+
*
214+
* @param string $lang Language.
215+
*
216+
* @return $this
217+
*/
218+
public function setLang($lang)
219+
{
220+
$this->lang = $lang;
221+
222+
return $this;
223+
}
224+
225+
/**
226+
* Get version
227+
*
228+
* @return string
229+
*/
230+
public function getVersion()
231+
{
232+
return $this->version;
233+
}
234+
235+
/**
236+
* Set version
237+
*
238+
* @param string $version Version number.
239+
*
240+
* @return $this
241+
*/
242+
public function setVersion($version)
243+
{
244+
$this->version = $version;
245+
246+
return $this;
247+
}
248+
249+
/**
250+
* Get verbose
251+
*
252+
* @return boolean
253+
*/
254+
public function isVerbose()
255+
{
256+
return $this->verbose;
257+
}
258+
259+
/**
260+
* Set verbose
261+
*
262+
* @param boolean $verbose Verbose flag.
263+
*
264+
* @return $this
265+
*/
266+
public function setVerbose($verbose)
267+
{
268+
$this->verbose = $verbose;
269+
270+
return $this;
271+
}
272+
273+
/**
274+
* Get pedantic
275+
*
276+
* @return boolean
277+
*/
278+
public function isPedantic()
279+
{
280+
return $this->pedantic;
281+
}
282+
283+
/**
284+
* Set pedantic
285+
*
286+
* @param boolean $pedantic Pedantic flag.
287+
*
288+
* @return $this
289+
*/
290+
public function setPedantic($pedantic)
291+
{
292+
$this->pedantic = $pedantic;
293+
294+
return $this;
295+
}
296+
297+
/**
298+
* Get reconnect
299+
*
300+
* @return boolean
301+
*/
302+
public function isReconnect()
303+
{
304+
return $this->reconnect;
305+
}
306+
307+
/**
308+
* Set reconnect
309+
*
310+
* @param boolean $reconnect Reconnect flag.
311+
*
312+
* @return $this
313+
*/
314+
public function setReconnect($reconnect)
315+
{
316+
$this->reconnect = $reconnect;
317+
318+
return $this;
319+
}
104320
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: isselguberna
5+
* Date: 29/9/15
6+
* Time: 23:48
7+
*/
8+
9+
namespace Nats\tests\Unit;
10+
11+
use Nats\ConnectionOptions;
12+
13+
/**
14+
* Class ConnectionOptionsTest
15+
*/
16+
class ConnectionOptionsTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* Tests Connection Options getters and setters. Only necessary for code coverage.
20+
*
21+
* @return void
22+
*/
23+
public function testSettersAndGetters()
24+
{
25+
$options = new ConnectionOptions();
26+
$options
27+
->setHost('host')
28+
->setPort(4222)
29+
->setUser('user')
30+
->setPass('password')
31+
->setLang('lang')
32+
->setVersion('version')
33+
->setVerbose(true)
34+
->setPedantic(true)
35+
->setReconnect(true);
36+
37+
$this->assertEquals('host', $options->getHost());
38+
$this->assertEquals(4222, $options->getPort());
39+
$this->assertEquals('user', $options->getUser());
40+
$this->assertEquals('password', $options->getPass());
41+
$this->assertEquals('lang', $options->getLang());
42+
$this->assertEquals('version', $options->getVersion());
43+
$this->assertTrue($options->isVerbose());
44+
$this->assertTrue($options->isPedantic());
45+
$this->assertTrue($options->isReconnect());
46+
}
47+
}

tests/Unit/ConnectionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function setUp()
6262
$options = new ConnectionOptions();
6363
if (!self::$isGnatsd) {
6464
time_nanosleep(1, 700000000);
65-
$options->port = 4222;
65+
$options->setPort(4222);
6666
}
6767
$this->c = new Nats\Connection($options);
6868
$this->c->connect();

0 commit comments

Comments
 (0)