Skip to content

Commit

Permalink
Future/zmq/publish subscribe/close (#19)
Browse files Browse the repository at this point in the history
* refactored

* added close method  for ZmqSocketSuport
  • Loading branch information
Mararok authored Oct 17, 2016
1 parent 487eda4 commit b3f67b9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
],
"require-dev": {
"phpunit/phpunit": "5.4.*",
"phpunit/phpunit": "5.*",
"codeclimate/php-test-reporter": "dev-master",
"mikey179/vfsStream": "1.6.*",
"fig-r/psr2r-sniffer": "0.3.*",
Expand All @@ -23,7 +23,7 @@
"suggest": {
"guzzlehttp/guzzle": "~6.0 Used for rest api and other http communication",
"nannehuiges/jsend": "2.1.* Used for rest api",
"ext-zmq": "WHEN using ZMQ subpackage"
"ext-zmq": "when using ZMQ subpackage"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions src/SAREhub/Commons/Zmq/PublishSubscribe/Publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace SAREhub\Commons\Zmq\PublishSubscribe;

use SAREhub\Commons\Zmq\ZmqSocketBase;
use SAREhub\Commons\Zmq\ZmqSocketSupport;

/**
* Represents publisher ZMQ socket
*/
class Publisher extends ZmqSocketBase {
class Publisher extends ZmqSocketSupport {

public function __construct(\ZMQSocket $socket) {
parent::__construct($socket);
Expand Down
4 changes: 2 additions & 2 deletions src/SAREhub/Commons/Zmq/PublishSubscribe/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace SAREhub\Commons\Zmq\PublishSubscribe;

use SAREhub\Commons\Zmq\ZmqSocketBase;
use SAREhub\Commons\Zmq\ZmqSocketSupport;

/**
* Represents subscriber ZMQ socket
*/
class Subscriber extends ZmqSocketBase {
class Subscriber extends ZmqSocketSupport {

/**
* @var array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use SAREhub\Commons\Misc\Dsn;

abstract class ZmqSocketBase {
abstract class ZmqSocketSupport {

/**
* @var Dsn
Expand Down Expand Up @@ -97,7 +97,11 @@ public function disconnectAll() {

return $this;
}


public function close() {
$this->disconnectAll();
$this->unbind();
}

/**
* @return bool
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?php

use SAREhub\Commons\Misc\Dsn;
use SAREhub\Commons\Zmq\ZmqSocketBase;
use SAREhub\Commons\Zmq\ZmqSocketSupport;

class TestZmqSocketBase extends ZmqSocketBase {
class TestZmqSocketSupport extends ZmqSocketSupport {

}

class ZmqSocketBaseTest extends PHPUnit_Framework_TestCase {
class ZmqSocketSupportTest extends PHPUnit_Framework_TestCase {

/**
* @var PHPUnit_Framework_MockObject_MockObject
*/
private $socket;

/**
* @var ZmqSocketBase
* @var ZmqSocketSupport
*/
private $base;

Expand Down Expand Up @@ -142,11 +142,23 @@ public function testIsBindedOrConnectedWhenBindedThenReturnTrue() {
$this->base->bind($this->dsn);
$this->assertTrue($this->base->isBindedOrConnected());
}

public function testCloseThenDisconnectAll() {
$this->base = $this->createPartialMock(TestZmqSocketSupport::class, ['disconnectAll']);
$this->base->expects($this->once())->method('disconnectAll');
$this->base->close();
}

public function testCloseThenUnbind() {
$this->base = $this->createPartialMock(TestZmqSocketSupport::class, ['unbind']);
$this->base->expects($this->once())->method('unbind');
$this->base->close();
}

protected function setUp() {
parent::setUp();
$this->socket = $this->createMock(ZMQSocket::class);
$this->base = new TestZmqSocketBase($this->socket);
$this->base = new TestZmqSocketSupport($this->socket);

$this->dsn = Dsn::tcp()->endpoint('127.1.0.1:5000');
$this->dsn2 = Dsn::tcp()->endpoint('127.1.0.1:5001');
Expand Down

0 comments on commit b3f67b9

Please sign in to comment.