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

Commit 12e2bbf

Browse files
author
jgil
committed
Removing StreamWrapper from construct in Connection class.
1 parent def1b7e commit 12e2bbf

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/Connection.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,31 @@ public function getSubscriptions()
108108
/**
109109
* Constructor.
110110
*
111-
* @param ConnectionOptions $options Connection options object.
112-
* @param StreamWrapper $streamWrapper Wrapper for stream functions. Testing purposes.
111+
* @param ConnectionOptions $options Connection options object.
113112
*/
114-
public function __construct(ConnectionOptions $options = null, StreamWrapper $streamWrapper = null)
113+
public function __construct(ConnectionOptions $options = null)
115114
{
116115
$this->pings = 0;
117116
$this->pubs = 0;
118117
$this->subscriptions = [];
119118
$this->options = $options;
120-
$this->streamWrapper = $streamWrapper;
119+
$this->streamWrapper = new StreamWrapper();
120+
121121
if (is_null($options)) {
122122
$this->options = new ConnectionOptions();
123123
}
124-
if (is_null($streamWrapper)) {
125-
$this->streamWrapper = new StreamWrapper();
126-
}
124+
}
125+
126+
/**
127+
* Setter for $streamWrapper. For testing purposes.
128+
*
129+
* @param StreamWrapper $streamWrapper StreamWrapper for testing purposes.
130+
*
131+
* @return void
132+
*/
133+
public function setStreamWrapper(StreamWrapper $streamWrapper)
134+
{
135+
$this->streamWrapper = $streamWrapper;
127136
}
128137

129138
/**

tests/Unit/ConnectionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public function setUp()
5252

5353
$streamWrapper->setStreamTimeout(Argument::any(), Argument::any())->willReturn(true);
5454

55-
$this->c = new Nats\Connection($options, $streamWrapper->reveal());
55+
$this->c = new Nats\Connection($options);
56+
$this->c->setStreamWrapper($streamWrapper->reveal());
5657
$this->c->connect();
5758
}
5859

0 commit comments

Comments
 (0)