diff --git a/Makefile b/Makefile index ac8303f..ac05b21 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,9 @@ deps-js: ## Install javascript dependencies deps-php: ## Install php dependencies @docker-compose run --rm composer install --prefer-dist +deps-php-update: ## Update php dependencies + @docker-compose run --rm composer update --prefer-dist + server-start: ## Start the test server @docker-compose up -d node diff --git a/composer.json b/composer.json index 11aeef8..910147f 100644 --- a/composer.json +++ b/composer.json @@ -27,9 +27,9 @@ }, "require-dev": { "adlawson/timezone": "~1.0", - "squizlabs/php_codesniffer": "^2.9", + "squizlabs/php_codesniffer": "^3", "mockery/mockery": "~0.9", "phpunit/phpunit": "~4.3", - "graze/standards": "^1.0" + "graze/standards": "^2.0" } } diff --git a/composer.lock b/composer.lock index 6b11ac5..00f7488 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "2cce8ebcf0b5369ed398d567fe6f8fdc", + "content-hash": "b8c5a75a8ffc4c6d80543e4ca6f10f0b", "packages": [ { "name": "guzzlehttp/guzzle", @@ -308,18 +308,21 @@ }, { "name": "graze/standards", - "version": "v1.0.0", + "version": "v2.0.1", "source": { "type": "git", "url": "https://github.com/graze/standards.git", - "reference": "ff7ea57e14cc222ff2c29f36a0bf40e707783bbb" + "reference": "0381502a55626f67b97dc85f0cb87cdf2c46bcbc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/graze/standards/zipball/ff7ea57e14cc222ff2c29f36a0bf40e707783bbb", - "reference": "ff7ea57e14cc222ff2c29f36a0bf40e707783bbb", + "url": "https://api.github.com/repos/graze/standards/zipball/0381502a55626f67b97dc85f0cb87cdf2c46bcbc", + "reference": "0381502a55626f67b97dc85f0cb87cdf2c46bcbc", "shasum": "" }, + "require-dev": { + "squizlabs/php_codesniffer": "^3.0" + }, "type": "library", "notification-url": "https://packagist.org/downloads/", "license": [ @@ -327,8 +330,8 @@ ], "authors": [ { - "name": "Will Pillar", - "email": "will.pillar@graze.com" + "name": "Graze Developers", + "email": "developers@graze.com" } ], "description": "Graze coding standards", @@ -338,7 +341,7 @@ "graze", "standards" ], - "time": "2016-02-16T12:04:19+00:00" + "time": "2017-11-06T11:45:35+00:00" }, { "name": "hamcrest/hamcrest-php", @@ -452,16 +455,16 @@ }, { "name": "phpdocumentor/reflection-common", - "version": "1.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c" + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c", - "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", "shasum": "" }, "require": { @@ -502,33 +505,39 @@ "reflection", "static analysis" ], - "time": "2015-12-27T11:43:31+00:00" + "time": "2017-09-11T18:02:19+00:00" }, { "name": "phpdocumentor/reflection-docblock", - "version": "3.2.2", + "version": "4.2.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "4aada1f93c72c35e22fb1383b47fee43b8f1d157" + "reference": "66465776cfc249844bde6d117abff1d22e06c2da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/4aada1f93c72c35e22fb1383b47fee43b8f1d157", - "reference": "4aada1f93c72c35e22fb1383b47fee43b8f1d157", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/66465776cfc249844bde6d117abff1d22e06c2da", + "reference": "66465776cfc249844bde6d117abff1d22e06c2da", "shasum": "" }, "require": { - "php": ">=5.5", - "phpdocumentor/reflection-common": "^1.0@dev", - "phpdocumentor/type-resolver": "^0.3.0", + "php": "^7.0", + "phpdocumentor/reflection-common": "^1.0.0", + "phpdocumentor/type-resolver": "^0.4.0", "webmozart/assert": "^1.0" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^4.4" + "doctrine/instantiator": "~1.0.5", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^6.4" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, "autoload": { "psr-4": { "phpDocumentor\\Reflection\\": [ @@ -547,20 +556,20 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-08-08T06:39:58+00:00" + "time": "2017-11-27T17:38:31+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "0.3.0", + "version": "0.4.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "fb3933512008d8162b3cdf9e18dba9309b7c3773" + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/fb3933512008d8162b3cdf9e18dba9309b7c3773", - "reference": "fb3933512008d8162b3cdf9e18dba9309b7c3773", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", "shasum": "" }, "require": { @@ -594,37 +603,37 @@ "email": "me@mikevanriel.com" } ], - "time": "2017-06-03T08:32:36+00:00" + "time": "2017-07-14T14:27:02+00:00" }, { "name": "phpspec/prophecy", - "version": "v1.7.0", + "version": "1.7.3", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "93d39f1f7f9326d746203c7c056f300f7f126073" + "reference": "e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/93d39f1f7f9326d746203c7c056f300f7f126073", - "reference": "93d39f1f7f9326d746203c7c056f300f7f126073", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf", + "reference": "e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", - "phpdocumentor/reflection-docblock": "^2.0|^3.0.2", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", "sebastian/comparator": "^1.1|^2.0", "sebastian/recursion-context": "^1.0|^2.0|^3.0" }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8 || ^5.6.5" + "phpunit/phpunit": "^4.8.35 || ^5.7" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.6.x-dev" + "dev-master": "1.7.x-dev" } }, "autoload": { @@ -657,7 +666,7 @@ "spy", "stub" ], - "time": "2017-03-02T20:05:34+00:00" + "time": "2017-11-24T13:59:53+00:00" }, { "name": "phpunit/php-code-coverage", @@ -723,16 +732,16 @@ }, { "name": "phpunit/php-file-iterator", - "version": "1.4.2", + "version": "1.4.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", - "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", "shasum": "" }, "require": { @@ -766,7 +775,7 @@ "filesystem", "iterator" ], - "time": "2016-10-03T07:40:28+00:00" + "time": "2017-11-27T13:52:08+00:00" }, { "name": "phpunit/php-text-template", @@ -860,16 +869,16 @@ }, { "name": "phpunit/php-token-stream", - "version": "1.4.11", + "version": "1.4.12", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7" + "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e03f8f67534427a787e21a385a67ec3ca6978ea7", - "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/1ce90ba27c42e4e44e6d8458241466380b51fa16", + "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16", "shasum": "" }, "require": { @@ -905,7 +914,7 @@ "keywords": [ "tokenizer" ], - "time": "2017-02-27T10:12:30+00:00" + "time": "2017-12-04T08:55:13+00:00" }, { "name": "phpunit/phpunit", @@ -1409,64 +1418,37 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "2.9.1", + "version": "3.2.0", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "dcbed1074f8244661eecddfc2a675430d8d33f62" + "reference": "ba816f2e1bacc16278792c78b67c730dfff064a6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/dcbed1074f8244661eecddfc2a675430d8d33f62", - "reference": "dcbed1074f8244661eecddfc2a675430d8d33f62", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ba816f2e1bacc16278792c78b67c730dfff064a6", + "reference": "ba816f2e1bacc16278792c78b67c730dfff064a6", "shasum": "" }, "require": { "ext-simplexml": "*", "ext-tokenizer": "*", "ext-xmlwriter": "*", - "php": ">=5.1.2" + "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0" }, "bin": [ - "scripts/phpcs", - "scripts/phpcbf" + "bin/phpcs", + "bin/phpcbf" ], "type": "library", "extra": { "branch-alias": { - "dev-master": "2.x-dev" + "dev-master": "3.x-dev" } }, - "autoload": { - "classmap": [ - "CodeSniffer.php", - "CodeSniffer/CLI.php", - "CodeSniffer/Exception.php", - "CodeSniffer/File.php", - "CodeSniffer/Fixer.php", - "CodeSniffer/Report.php", - "CodeSniffer/Reporting.php", - "CodeSniffer/Sniff.php", - "CodeSniffer/Tokens.php", - "CodeSniffer/Reports/", - "CodeSniffer/Tokenizers/", - "CodeSniffer/DocGenerators/", - "CodeSniffer/Standards/AbstractPatternSniff.php", - "CodeSniffer/Standards/AbstractScopeSniff.php", - "CodeSniffer/Standards/AbstractVariableSniff.php", - "CodeSniffer/Standards/IncorrectPatternException.php", - "CodeSniffer/Standards/Generic/Sniffs/", - "CodeSniffer/Standards/MySource/Sniffs/", - "CodeSniffer/Standards/PEAR/Sniffs/", - "CodeSniffer/Standards/PSR1/Sniffs/", - "CodeSniffer/Standards/PSR2/Sniffs/", - "CodeSniffer/Standards/Squiz/Sniffs/", - "CodeSniffer/Standards/Zend/Sniffs/" - ] - }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" @@ -1483,27 +1465,30 @@ "phpcs", "standards" ], - "time": "2017-05-22T02:43:20+00:00" + "time": "2017-12-12T21:36:10+00:00" }, { "name": "symfony/yaml", - "version": "v3.3.6", + "version": "v3.4.1", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "ddc23324e6cfe066f3dd34a37ff494fa80b617ed" + "reference": "f6a99b95b338799645fe9f7880d7d4ca1bf79cc1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/ddc23324e6cfe066f3dd34a37ff494fa80b617ed", - "reference": "ddc23324e6cfe066f3dd34a37ff494fa80b617ed", + "url": "https://api.github.com/repos/symfony/yaml/zipball/f6a99b95b338799645fe9f7880d7d4ca1bf79cc1", + "reference": "f6a99b95b338799645fe9f7880d7d4ca1bf79cc1", "shasum": "" }, "require": { - "php": ">=5.5.9" + "php": "^5.5.9|>=7.0.8" + }, + "conflict": { + "symfony/console": "<3.4" }, "require-dev": { - "symfony/console": "~2.8|~3.0" + "symfony/console": "~3.4|~4.0" }, "suggest": { "symfony/console": "For validating YAML files using the lint command" @@ -1511,7 +1496,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.3-dev" + "dev-master": "3.4-dev" } }, "autoload": { @@ -1538,7 +1523,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2017-07-23T12:43:26+00:00" + "time": "2017-12-04T18:15:22+00:00" }, { "name": "webmozart/assert", diff --git a/docker-compose.yml b/docker-compose.yml index 61a2fa3..0f5b559 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,13 +2,13 @@ version: '2' services: test: - image: graze/php-alpine:test + image: graze/php-alpine:7.1-test volumes: - .:/srv:cached working_dir: /srv node: - image: node:8 + image: node:8-alpine expose: - 80 volumes: @@ -18,8 +18,7 @@ services: command: node -- index.js composer: - image: graze/composer + image: composer volumes: - - .:/usr/src/app:delegated - - ~/.composer:/home/composer/.composer:delegated - - ~/.ssh/id_rsa:/home/composer/.ssh/id_rsa:ro + - .:/app:delegated + - ~/.composer:/tmp:delegated diff --git a/src/Client.php b/src/Client.php index 1c4282a..c141868 100644 --- a/src/Client.php +++ b/src/Client.php @@ -43,7 +43,7 @@ public function __construct(HttpClientInterface $httpClient) */ public static function factory($url, array $config = []) { - return new self(new HttpClient(array_replace_recursive([ + $client = new HttpClient(array_replace_recursive([ 'base_url' => $url, 'message_factory' => self::createMessageFactory(), 'defaults' => [ @@ -51,7 +51,11 @@ public static function factory($url, array $config = []) 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3' ] ] - ], $config))); + ], $config)); + if (isset($config['subscribers'])) { + array_map([$client->getEmitter(), 'attach'], $config['subscribers']); + } + return new self($client); } /** @@ -65,7 +69,7 @@ public static function factory($url, array $config = []) public function notification($method, array $params = null) { return $this->createRequest(RequestInterface::NOTIFICATION, array_filter([ - 'jsonrpc' => self::SPEC, + 'jsonrpc' => static::SPEC, 'method' => $method, 'params' => $params ])); @@ -83,7 +87,7 @@ public function notification($method, array $params = null) public function request($id, $method, array $params = null) { return $this->createRequest(RequestInterface::REQUEST, array_filter([ - 'jsonrpc' => self::SPEC, + 'jsonrpc' => static::SPEC, 'method' => $method, 'params' => $params, 'id' => $id diff --git a/test/functional/SubscribersFunctionalTest.php b/test/functional/SubscribersFunctionalTest.php new file mode 100644 index 0000000..ac1738f --- /dev/null +++ b/test/functional/SubscribersFunctionalTest.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @see http://github.com/graze/guzzle-jsonrpc/blob/master/LICENSE + * @link http://github.com/graze/guzzle-jsonrpc + */ + +namespace Graze\GuzzleHttp\JsonRpc; + +use Graze\GuzzleHttp\JsonRpc\Subscriber\ErrorSubscriber; +use Graze\GuzzleHttp\JsonRpc\Test\FunctionalTestCase; + +class SubscribersFunctionalTest extends FunctionalTestCase +{ + /** + * @expectedException \Graze\GuzzleHttp\JsonRpc\Exception\ClientException + */ + public function testSubscribersGetAddedToTheHttpClient() + { + $subscriber = new ErrorSubscriber(); + $client = $this->createClient( + null, + [ + 'subscribers' => [$subscriber], + ] + ); + + $id = 'abc'; + $method = 'bar'; + $request = $client->request($id, $method, []); + + $this->assertEquals(ClientInterface::SPEC, $request->getRpcVersion()); + $this->assertEquals($id, $request->getRpcId()); + $this->assertEquals($method, $request->getRpcMethod()); + $this->assertEquals(null, $request->getRpcParams()); + + $client->send($request); + } +}