Skip to content

Commit

Permalink
Removing StreamWrapper from construct in Connection class.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgil committed Oct 25, 2015
1 parent 202e1c4 commit 16a60f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
23 changes: 16 additions & 7 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,31 @@ public function getSubscriptions()
/**
* Constructor.
*
* @param ConnectionOptions $options Connection options object.
* @param StreamWrapper $streamWrapper Wrapper for stream functions. Testing purposes.
* @param ConnectionOptions $options Connection options object.
*/
public function __construct(ConnectionOptions $options = null, StreamWrapper $streamWrapper = null)
public function __construct(ConnectionOptions $options = null)
{
$this->pings = 0;
$this->pubs = 0;
$this->subscriptions = [];
$this->options = $options;
$this->streamWrapper = $streamWrapper;
$this->streamWrapper = new StreamWrapper();

if (is_null($options)) {
$this->options = new ConnectionOptions();
}
if (is_null($streamWrapper)) {
$this->streamWrapper = new StreamWrapper();
}
}

/**
* Setter for $streamWrapper. For testing purposes.
*
* @param StreamWrapper $streamWrapper StreamWrapper for testing purposes.
*
* @return void
*/
public function setStreamWrapper(StreamWrapper $streamWrapper)
{
$this->streamWrapper = $streamWrapper;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public function setUp()

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

$this->c = new Nats\Connection($options, $streamWrapper->reveal());
$this->c = new Nats\Connection($options);
$this->c->setStreamWrapper($streamWrapper->reveal());
$this->c->connect();
}

Expand Down

0 comments on commit 16a60f5

Please sign in to comment.