From f40a03b16bc85925813113a82861a17558500ee3 Mon Sep 17 00:00:00 2001 From: Oliboy50 Date: Tue, 3 Dec 2019 10:28:23 +0100 Subject: [PATCH] feat(symfony5): support Symfony5 and restore travis ci --- .travis.yml | 31 +++++++++++++------ README.md | 4 ++- composer.json | 17 +++++----- src/DataCollector/GuzzleHttpDataCollector.php | 2 +- src/DependencyInjection/Configuration.php | 5 ++- src/Handler/CurlFactory.php | 1 + src/Handler/CurlHandler.php | 3 +- src/Handler/CurlMultiHandler.php | 3 +- src/M6WebGuzzleHttpBundle.php | 3 +- src/Middleware/EventDispatcherMiddleware.php | 11 +------ .../M6WebGuzzleHttpExtension.php | 16 +++++----- .../Middleware/EventDispatcherMiddleware.php | 4 +-- 12 files changed, 51 insertions(+), 49 deletions(-) diff --git a/.travis.yml b/.travis.yml index 926f5ad..62a7ed2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,21 +1,32 @@ -language: php +# inspired from https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/.travis.yml -php: - - 5.5 - - 5.6 - - 7.0 - - 7.1 - - 7.2 +language: php -before_script: - - phpenv config-rm xdebug.ini +cache: + directories: + - $HOME/.composer/cache/files branches: only: - master +matrix: + include: + - php: 7.1 + env: COMPOSER_FLAGS="--prefer-lowest" + - php: 7.2 + - php: 7.3 + - php: 7.4 + allow_failures: + # @TODO remove when atoum will support php7.4 + - php: 7.4 + +before_install: + - phpenv config-rm xdebug.ini || true + install: - - composer install -n --dev + - composer update $COMPOSER_FLAGS --prefer-dist -n + - if [ "$COMPOSER_PREFER" = "lowest" ]; then composer update --prefer-lowest -n; fi; script: - bin/coke diff --git a/README.md b/README.md index 3b3d6ca..b1c79e7 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,13 @@ Require the bundle in your composer.json file : ```json { "require": { - "m6web/guzzle-http-bundle": "~2.0" + "m6web/guzzle-http-bundle": "~3.0" } } ``` +> For older Symfony versions, you can try to install an older version of this bundle. + Register the bundle in your kernel : ```php diff --git a/composer.json b/composer.json index 82465cb..cfdd115 100644 --- a/composer.json +++ b/composer.json @@ -12,19 +12,20 @@ } ], "require": { - "php": ">=7.0", + "php": ">=7.1", "ext-curl": "*", "guzzlehttp/guzzle": "^6.3.0", - "symfony/dependency-injection": "~2.3||~3.0||~4.0", - "symfony/event-dispatcher": "~4.3-stable", - "symfony/config" : "~2.3||~3.0||~4.0", - "symfony/yaml" : "~2.3||~3.0||~4.0" + "symfony/config" : "~4.3||~5.0", + "symfony/dependency-injection": "~3.4||~4.3||~5.0", + "symfony/event-dispatcher": "~4.3||~5.0", + "symfony/http-kernel": "~3.4||~4.3||~5.0", + "symfony/yaml" : "~3.4||~4.3||~5.0" }, "require-dev": { - "atoum/atoum": "^2.8||^3.0", + "atoum/atoum": "^3.1", "atoum/stubs": "*", - "m6web/coke": "~1.2||^2.2", - "m6web/symfony2-coding-standard": "~2.0||^3.3" + "m6web/coke": "^2.2", + "m6web/symfony2-coding-standard": "^3.3" }, "autoload": { "psr-4": {"M6Web\\Bundle\\GuzzleHttpBundle\\": "src/"} diff --git a/src/DataCollector/GuzzleHttpDataCollector.php b/src/DataCollector/GuzzleHttpDataCollector.php index 2b9562f..f39e315 100644 --- a/src/DataCollector/GuzzleHttpDataCollector.php +++ b/src/DataCollector/GuzzleHttpDataCollector.php @@ -25,7 +25,7 @@ public function __construct() * @param Response $response The response object * @param \Exception $exception An exception */ - public function collect(Request $request, Response $response, \Exception $exception = null) + public function collect(Request $request, Response $response, \Throwable $exception = null) { } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 6be38c8..a81b86e 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -17,10 +17,9 @@ class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('m6web_guzzlehttp'); + $treeBuilder = new TreeBuilder('m6web_guzzlehttp'); - $rootNode + $treeBuilder->getRootNode() ->children() ->arrayNode('clients') ->isRequired() diff --git a/src/Handler/CurlFactory.php b/src/Handler/CurlFactory.php index afb5438..0f48345 100644 --- a/src/Handler/CurlFactory.php +++ b/src/Handler/CurlFactory.php @@ -2,6 +2,7 @@ namespace M6Web\Bundle\GuzzleHttpBundle\Handler; use GuzzleHttp\Handler\CurlFactory as GuzzleCurlFactory; +// @TODO use something else since EasyHandle class is @internal (=> BC is not ensured) use GuzzleHttp\Handler\EasyHandle; /** diff --git a/src/Handler/CurlHandler.php b/src/Handler/CurlHandler.php index 6e3fbaa..d48ac11 100644 --- a/src/Handler/CurlHandler.php +++ b/src/Handler/CurlHandler.php @@ -3,7 +3,6 @@ use GuzzleHttp\Handler\CurlHandler as GuzzleCurlHandler; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; /** * Extends the guzzle curl handler @@ -23,7 +22,7 @@ class CurlHandler extends GuzzleCurlHandler */ public function __construct(EventDispatcherInterface $eventDispatcher, array $options) { - $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); + $this->eventDispatcher = $eventDispatcher; parent::__construct($options); } diff --git a/src/Handler/CurlMultiHandler.php b/src/Handler/CurlMultiHandler.php index 39614de..f9d01da 100644 --- a/src/Handler/CurlMultiHandler.php +++ b/src/Handler/CurlMultiHandler.php @@ -3,7 +3,6 @@ use GuzzleHttp\Handler\CurlMultiHandler as GuzzleCurlMultiHandler; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; /** * Extends guzzle CurlMultiHandler @@ -23,7 +22,7 @@ class CurlMultiHandler extends GuzzleCurlMultiHandler */ public function __construct(EventDispatcherInterface $eventDispatcher, array $options) { - $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); + $this->eventDispatcher = $eventDispatcher; parent::__construct($options); } diff --git a/src/M6WebGuzzleHttpBundle.php b/src/M6WebGuzzleHttpBundle.php index 206eee2..55daf77 100644 --- a/src/M6WebGuzzleHttpBundle.php +++ b/src/M6WebGuzzleHttpBundle.php @@ -3,6 +3,7 @@ use M6Web\Bundle\GuzzleHttpBundle\DependencyInjection\MiddlewarePass; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; use Symfony\Component\HttpKernel\Bundle\Bundle; /** @@ -11,7 +12,7 @@ class M6WebGuzzleHttpBundle extends Bundle { /** - * @return DependencyInjection\M6WebCassandraExtension|null|\Symfony\Component\DependencyInjection\Extension\ExtensionInterface + * @return null|ExtensionInterface */ public function getContainerExtension() { diff --git a/src/Middleware/EventDispatcherMiddleware.php b/src/Middleware/EventDispatcherMiddleware.php index 7915744..e3bc520 100644 --- a/src/Middleware/EventDispatcherMiddleware.php +++ b/src/Middleware/EventDispatcherMiddleware.php @@ -2,17 +2,11 @@ namespace M6Web\Bundle\GuzzleHttpBundle\Middleware; use GuzzleHttp\HandlerStack; -use GuzzleHttp\Psr7\Request; -use GuzzleHttp\Middleware; -use GuzzleHttp\Psr7\Response; use M6Web\Bundle\GuzzleHttpBundle\EventDispatcher\GuzzleHttpErrorEvent; use M6Web\Bundle\GuzzleHttpBundle\EventDispatcher\GuzzleHttpEvent; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use M6Web\Bundle\GuzzleHttpBundle\EventDispatcher\AbstractGuzzleHttpEvent; -use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; -use Symfony\Component\EventDispatcher\LegacyEventProxy; /** * Handler for event dispatching @@ -43,8 +37,7 @@ class EventDispatcherMiddleware implements MiddlewareInterface */ public function __construct(EventDispatcherInterface $eventDispatcher, $clientId) { - - $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); + $this->eventDispatcher = $eventDispatcher; $this->events = []; $this->clientId = $clientId; } @@ -109,7 +102,6 @@ protected function sendEvent(RequestInterface $request, ResponseInterface $respo $event->setClientId($this->clientId); $event->setExecutionStop(); $event->setResponse($response); - $event = new LegacyEventProxy($event); $this->eventDispatcher->dispatch($event, GuzzleHttpEvent::EVENT_NAME); } @@ -127,7 +119,6 @@ protected function sendErrorEvent(RequestInterface $request, $reason) $event->setClientId($this->clientId); $event->setExecutionStop(); $event->setReason($reason); - $event = new LegacyEventProxy($event); $this->eventDispatcher->dispatch($event, GuzzleHttpErrorEvent::EVENT_ERROR_NAME); } } diff --git a/tests/Units/DependencyInjection/M6WebGuzzleHttpExtension.php b/tests/Units/DependencyInjection/M6WebGuzzleHttpExtension.php index e7bbf8d..44d65d5 100644 --- a/tests/Units/DependencyInjection/M6WebGuzzleHttpExtension.php +++ b/tests/Units/DependencyInjection/M6WebGuzzleHttpExtension.php @@ -275,10 +275,7 @@ public function testClientConfigurationWithHeaders() public function testEventDispatcherMiddleWare() { - $mockDispatcher = new \mock\Symfony\Component\EventDispatcher\EventDispatcherInterface(); - $container = $this->getContainerForConfiguration('default-config'); - $container->set('event_dispatcher', $mockDispatcher); $container->compile(); $this @@ -289,7 +286,7 @@ public function testEventDispatcherMiddleWare() ]) ->and($rep = Promise\unwrap($promises)) ->then - ->mock($mockDispatcher) + ->mock($container->get('event_dispatcher')) ->call('dispatch') ->twice() ; @@ -297,10 +294,7 @@ public function testEventDispatcherMiddleWare() public function testEventDispatcherMultiClient() { - $mockDispatcher = new \mock\Symfony\Component\EventDispatcher\EventDispatcherInterface(); - $container = $this->getContainerForConfiguration('multiclient-config'); - $container->set('event_dispatcher', $mockDispatcher); $container->compile(); $this @@ -313,7 +307,7 @@ public function testEventDispatcherMultiClient() ->and($rep = Promise\unwrap($promises)) ->and($client2->get('http://httpbin.org')) ->then - ->mock($mockDispatcher) + ->mock($container->get('event_dispatcher')) ->call('dispatch') ->exactly(3) ; @@ -527,7 +521,11 @@ protected function getContainerForConfiguration($fixtureName, ContainerBuilder $ $container = $this->getContainerBuilder(); } - $container->set('event_dispatcher', new \mock\Symfony\Component\EventDispatcher\EventDispatcherInterface()); + $mockDispatcher = new \mock\Symfony\Component\EventDispatcher\EventDispatcherInterface(); + $mockDispatcher->getMockController()->dispatch = function($event) { + return $event; + }; + $container->set('event_dispatcher', $mockDispatcher); $container->set('cache_service', new \mock\M6Web\Bundle\GuzzleHttpBundle\Cache\CacheInterface()); $container->set('cache_service2', new \mock\M6Web\Bundle\GuzzleHttpBundle\Cache\CacheInterface()); $container->registerExtension($extension); diff --git a/tests/Units/Middleware/EventDispatcherMiddleware.php b/tests/Units/Middleware/EventDispatcherMiddleware.php index bcdc5a6..fb50519 100644 --- a/tests/Units/Middleware/EventDispatcherMiddleware.php +++ b/tests/Units/Middleware/EventDispatcherMiddleware.php @@ -5,7 +5,6 @@ use M6Web\Bundle\GuzzleHttpBundle\EventDispatcher\GuzzleHttpErrorEvent; use M6Web\Bundle\GuzzleHttpBundle\EventDispatcher\GuzzleHttpEvent; use M6Web\Bundle\GuzzleHttpBundle\Middleware\EventDispatcherMiddleware as Base; -use M6Web\Bundle\GuzzleHttpBundle\EventDispatcher\AbstractGuzzleHttpEvent; /** * Class EventDispatcherMiddleware test @@ -19,6 +18,7 @@ public function testPush() $dispatcherMock = new \mock\Symfony\Component\EventDispatcher\EventDispatcherInterface(); $dispatcherMock->getMockController()->dispatch = function($event, $name) use (&$eventSend) { $eventSend = $event; + return $event; }; // Mock HandlerStack @@ -104,4 +104,4 @@ function() use ($errorCallable) { ->once() ; } -} \ No newline at end of file +}