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

Commit e1031b5

Browse files
committed
Merge branch 'release/0.8.4'
2 parents ade4ce4 + 5fe2077 commit e1031b5

8 files changed

Lines changed: 204 additions & 55 deletions

File tree

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ cache:
1313
before_install:
1414
- docker run -d -p 4222:4222 --name nats nats
1515
before_script:
16+
- make dist-clean
1617
- make deps
18+
- make dev-deps
1719
script:
1820
- mkdir -p build/logs
1921
- make lint

Makefile

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1+
PHPCS_PHAR = https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
2+
COMPOSER_PHAR = https://getcomposer.org/composer.phar
3+
PHPDOCUMENTOR_PHAR_URL = https://github.com/phpDocumentor/phpDocumentor2/releases/download/v2.9.0/phpDocumentor.phar
4+
CLEAN_FILES = composer.phar composer.lock phpDocumentor.phar phpcs.phar phpcbf.phar
5+
CLEAN_FOLDERS = bin build cover vendor docs/api
6+
CLEAN_PATHS = $(CLEAN_FILES) $(CLEAN_FOLDERS)
7+
SOURCE_CODE_PATHS = src test examples
8+
API_DOCS_PATH = ./docs/api
9+
COVERAGE_PATH = ./cover
10+
11+
define require_phar
12+
@[ -f ./$(1) ] || wget -q $(2) -O ./$(1) && chmod +x $(1);
13+
endef
14+
115
lint: lint-php lint-psr2 lint-squiz
216

317
.PHONY: lint-php
418
lint-php:
5-
find src -name *.php -exec php -l {} \;
6-
find test -name *.php -exec php -l {} \;
7-
find spec -name *.php -exec php -l {} \;
8-
find examples -name *.php -exec php -l {} \;
19+
find $(SOURCE_CODE_PATHS) spec -name *.php -exec php -l {} \;
920

1021
.PHONY: lint-psr2
1122
lint-psr2:
12-
#./vendor/bin/phpcbf --standard=PSR2 src test examples
13-
./vendor/bin/phpcs --standard=PSR2 --colors -w -s --warning-severity=0 src test examples
23+
$(call require_phar,phpcs.phar,$(PHPCS_PHAR))
24+
./phpcs.phar --standard=PSR2 --colors -w -s --warning-severity=0 $(SOURCE_CODE_PATHS)
1425

1526
.PHONY: lint-squiz
1627
lint-squiz:
17-
# ./vendor/bin/phpcbf --standard=Squiz,./ruleset.xml src test examples
18-
./vendor/bin/phpcs --standard=Squiz,./ruleset.xml --colors -w -s --warning-severity=0 src test examples
28+
$(call require_phar,phpcs.phar,$(PHPCS_PHAR))
29+
./phpcs.phar --standard=Squiz,./ruleset.xml --colors -w -s --warning-severity=0 $(SOURCE_CODE_PATHS)
1930

2031

2132
test: test-tdd test-bdd
@@ -29,28 +40,25 @@ test-bdd:
2940
./vendor/bin/phpspec run --format=pretty -v
3041

3142
cover:
32-
./vendor/bin/phpunit --coverage-html ./cover test
43+
./vendor/bin/phpunit --coverage-html $(COVERAGE_PATH) test
3344

3445
deps:
35-
wget -q https://getcomposer.org/composer.phar -O ./composer.phar
36-
chmod +x composer.phar
37-
php composer.phar install
46+
$(call require_phar,composer.phar,$(COMPOSER_PHAR))
47+
./composer.phar install --no-dev
48+
49+
dev-deps:
50+
$(call require_phar,composer.phar,$(COMPOSER_PHAR))
51+
./composer.phar install
3852

3953
dist-clean:
40-
rm -rf bin
41-
rm -rf vendor
42-
rm -f composer.phar
43-
rm -f composer.lock
44-
rm -f phpDocumentor.phar
45-
rm -rf docs/api
54+
rm -rf $(CLEAN_PATHS)
4655

4756
docker-nats:
4857
docker run --rm -p 8222:8222 -p 4222:4222 -d --name nats-main nats
4958

5059
phpdoc:
51-
wget -q https://github.com/phpDocumentor/phpDocumentor2/releases/download/v2.9.0/phpDocumentor.phar -O ./phpDocumentor.phar
52-
chmod +x phpDocumentor.phar
53-
./phpDocumentor.phar -d ./src/ -t ./docs/api --template=checkstyle --template=responsive-twig
60+
$(call require_phar,phpdoc.phar,$(PHPDOCUMENTOR_PHAR_URL))
61+
./phpdoc.phar -d ./src/ -t $(API_DOCS_PATH) --template=checkstyle --template=responsive-twig
5462

5563
serve-phpdoc:
56-
cd docs/api && php -S localhost:8000 && cd ../..
64+
cd $(API_DOCS_PATH) && php -S localhost:8000 && cd ../..

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.8.3
1+
0.8.4

composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
"minimum-stability": "dev",
66
"license": "MIT",
77
"require": {
8-
"ircmaxell/random-lib": "^1.1"
8+
"ircmaxell/random-lib": "^1.2"
99
},
1010
"require-dev": {
1111
"phpunit/phpunit": "5.*",
12-
"satooshi/php-coveralls": "dev-master",
13-
"squizlabs/php_codesniffer": "~2.0",
14-
"phpspec/phpspec": "~2.0"
12+
"phpspec/phpspec": "^3.0",
13+
"satooshi/php-coveralls": "dev-master"
1514
},
1615
"authors": [
1716
{

src/Nats/Encoders/YAMLEncoder.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
namespace Nats\Encoders;
3+
4+
/**
5+
* Class YAMLEncoder
6+
*
7+
* Encodes and decodes messages in YAML format.
8+
*
9+
* @package Nats
10+
*/
11+
class YAMLEncoder implements Encoder
12+
{
13+
14+
15+
/**
16+
* Encodes a message to YAML.
17+
*
18+
* @param string $payload Message to decode.
19+
*
20+
* @return mixed
21+
*/
22+
public function encode($payload)
23+
{
24+
$payload = yaml_emit($payload);
25+
return $payload;
26+
}
27+
28+
/**
29+
* Decodes a message from YAML.
30+
*
31+
* @param string $payload Message to decode.
32+
*
33+
* @return mixed
34+
*/
35+
public function decode($payload)
36+
{
37+
$payload = yaml_parse($payload);
38+
return $payload;
39+
}
40+
}

test/EncodedConnectionTest.php

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
namespace Nats\tests\Unit;
33

44
use Nats;
5+
use Nats\Connection;
56
use Nats\ConnectionOptions;
6-
use Nats\EncodedConnection;
77
use Nats\Encoders\JSONEncoder;
88

99
/**
@@ -29,7 +29,7 @@ public function setUp()
2929
{
3030
$encoder = new JSONEncoder();
3131
$options = new ConnectionOptions();
32-
$this->c = new EncodedConnection($options, $encoder);
32+
$this->c = new Connection($options, $encoder);
3333
$this->c->connect();
3434
}
3535

@@ -88,30 +88,4 @@ function ($res) {
8888
}
8989
);
9090
}
91-
92-
/**
93-
* Test Request command.
94-
*
95-
* @return void
96-
*/
97-
public function testRequestArray()
98-
{
99-
$this->c->subscribe(
100-
'sayhello',
101-
function ($res) {
102-
$res->reply('Hello, '.$res->getBody()[1].' !!!');
103-
}
104-
);
105-
106-
$this->c->request(
107-
'sayhello',
108-
[
109-
'foo',
110-
'McFly',
111-
],
112-
function ($res) {
113-
$this->assertEquals('Hello, McFly !!!', $res->getBody());
114-
}
115-
);
116-
}
11791
}

test/JSONEncoderTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
namespace Nats\tests\Unit;
3+
4+
use Nats;
5+
use Nats\ConnectionOptions;
6+
use Nats\EncodedConnection;
7+
use Nats\Encoders\JSONEncoder;
8+
9+
/**
10+
* Class JSONEncoderTest.
11+
*/
12+
class JSONEncoderTest extends \PHPUnit_Framework_TestCase
13+
{
14+
15+
/**
16+
* Client.
17+
*
18+
* @var Nats\Connection Client
19+
*/
20+
private $c;
21+
22+
23+
/**
24+
* SetUp test suite.
25+
*
26+
* @return void
27+
*/
28+
public function setUp()
29+
{
30+
$encoder = new JSONEncoder();
31+
$options = new ConnectionOptions();
32+
$this->c = new EncodedConnection($options, $encoder);
33+
$this->c->connect();
34+
}
35+
36+
/**
37+
* Test Request command.
38+
*
39+
* @return void
40+
*/
41+
public function testRequestArray()
42+
{
43+
$this->c->subscribe(
44+
'sayhello',
45+
function ($res) {
46+
$res->reply('Hello, '.$res->getBody()[1].' !!!');
47+
}
48+
);
49+
50+
$this->c->request(
51+
'sayhello',
52+
[
53+
'foo',
54+
'McFly',
55+
],
56+
function ($res) {
57+
$this->assertEquals('Hello, McFly !!!', $res->getBody());
58+
}
59+
);
60+
}
61+
}

test/YAMLEncoderTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
namespace Nats\tests\Unit;
3+
4+
use Nats;
5+
use Nats\ConnectionOptions;
6+
use Nats\EncodedConnection;
7+
use Nats\Encoders\YAMLEncoder;
8+
9+
/**
10+
* Class YAMLEncoderTest.
11+
*/
12+
class YAMLEncoderTest extends \PHPUnit_Framework_TestCase
13+
{
14+
15+
/**
16+
* Client.
17+
*
18+
* @var Nats\Connection Client
19+
*/
20+
private $c;
21+
22+
23+
/**
24+
* SetUp test suite.
25+
*
26+
* @return void
27+
*/
28+
public function setUp()
29+
{
30+
$encoder = new YAMLEncoder();
31+
$options = new ConnectionOptions();
32+
$this->c = new EncodedConnection($options, $encoder);
33+
$this->c->connect();
34+
}
35+
36+
/**
37+
* Test Request command.
38+
*
39+
* @return void
40+
*/
41+
public function testRequestArray()
42+
{
43+
$this->markTestSkipped(
44+
'The YAML extension is not available.'
45+
);
46+
47+
$this->c->subscribe(
48+
'sayhello',
49+
function ($res) {
50+
$res->reply('Hello, '.$res->getBody()[1].' !!!');
51+
}
52+
);
53+
54+
$this->c->request(
55+
'sayhello',
56+
[
57+
'foo',
58+
'McFly',
59+
],
60+
function ($res) {
61+
$this->assertEquals('Hello, McFly !!!', $res->getBody());
62+
}
63+
);
64+
}
65+
}

0 commit comments

Comments
 (0)