Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(symfony5): support Symfony5 and restore travis ci #66

Merged
merged 1 commit into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"guzzlehttp/guzzle": "~6.3",
"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/"}
Expand Down
2 changes: 1 addition & 1 deletion src/DataCollector/GuzzleHttpDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down
5 changes: 2 additions & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/Handler/CurlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Oliboy50 marked this conversation as resolved.
Show resolved Hide resolved
use GuzzleHttp\Handler\EasyHandle;

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Handler/CurlHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Handler/CurlMultiHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use GuzzleHttp\Handler\CurlMultiHandler as GuzzleCurlMultiHandler;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;

/**
* Extends guzzle CurlMultiHandler
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/M6WebGuzzleHttpBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
class M6WebGuzzleHttpBundle extends Bundle
{
/**
* @return DependencyInjection\M6WebCassandraExtension|null|\Symfony\Component\DependencyInjection\Extension\ExtensionInterface
* {@inheritdoc}
*/
public function getContainerExtension()
{
return new DependencyInjection\M6WebGuzzleHttpExtension();
}

/**
* @param ContainerBuilder $container
* {@inheritdoc}
*/
public function build(ContainerBuilder $container)
{
Expand Down
11 changes: 1 addition & 10 deletions src/Middleware/EventDispatcherMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
}
16 changes: 7 additions & 9 deletions tests/Units/DependencyInjection/M6WebGuzzleHttpExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -289,18 +286,15 @@ public function testEventDispatcherMiddleWare()
])
->and($rep = Promise\unwrap($promises))
->then
->mock($mockDispatcher)
->mock($container->get('event_dispatcher'))
->call('dispatch')
->twice()
;
}

public function testEventDispatcherMultiClient()
{
$mockDispatcher = new \mock\Symfony\Component\EventDispatcher\EventDispatcherInterface();

$container = $this->getContainerForConfiguration('multiclient-config');
$container->set('event_dispatcher', $mockDispatcher);
$container->compile();

$this
Expand All @@ -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)
;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/Units/Middleware/EventDispatcherMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -104,4 +104,4 @@ function() use ($errorCallable) {
->once()
;
}
}
}