diff --git a/CHANGELOG.md b/CHANGELOG.md index eba20440..8f25406a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. -## 1.16.0 - unreleased +## 1.16.0 - 2019-06-05 ### Changed @@ -12,12 +12,11 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Added - Integration for VCR Plugin -- curl-client v1.* is marked in conflict with the current bundle version. ### Fixed -- Fix compatibility with curl-client v2.*, the `CurlFactory` now build the - client using PSR17 factories. +- Fix compatibility with curl-client `2.*`. The `CurlFactory` now builds the + client using PSR-17 factories. Marked a conflict for curl-client `1.*`. ## 1.15.2 - 2019-04-18 diff --git a/tests/Functional/DiscoveryTest.php b/tests/Functional/DiscoveryTest.php index 7af9ef31..f4c5aaef 100644 --- a/tests/Functional/DiscoveryTest.php +++ b/tests/Functional/DiscoveryTest.php @@ -13,6 +13,7 @@ use Matthias\SymfonyDependencyInjectionTest\PhpUnit\ContainerBuilderHasAliasConstraint; use PHPUnit\Framework\Constraint\LogicalNot; use Symfony\Component\DependencyInjection\Definition; +use Http\Adapter\Guzzle6\Client; /** * @author Márk Sági-Kazár @@ -50,9 +51,9 @@ public function testDiscoveryFallbacks() public function testDiscoveryPartialFallbacks() { $this->load(); - $this->setDefinition('httplug.client.default', new Definition('Http\Adapter\Guzzle6\Client')); + $this->setDefinition('httplug.client.default', new Definition(Client::class)); - $this->assertContainerBuilderHasService('httplug.client.default', 'Http\Adapter\Guzzle6\Client'); + $this->assertContainerBuilderHasService('httplug.client.default', Client::class); $this->assertContainerBuilderHasService('httplug.message_factory.default', MessageFactory::class); $this->assertContainerBuilderHasService('httplug.uri_factory.default', UriFactory::class); $this->assertContainerBuilderHasService('httplug.stream_factory.default', StreamFactory::class); diff --git a/tests/Functional/Issue206.php b/tests/Functional/Issue206.php index 881cc6ee..9ec150d2 100644 --- a/tests/Functional/Issue206.php +++ b/tests/Functional/Issue206.php @@ -17,7 +17,7 @@ public function testCustomClientDoesNotCauseException() { static::bootKernel(); $container = static::$kernel->getContainer(); - PluginClientFactory::setFactory([$container->get('Http\Client\Common\PluginClientFactory'), 'createClient']); + PluginClientFactory::setFactory([$container->get(PluginClientFactory::class), 'createClient']); // Create a client $myCustomClient = new HttpMethodsClient(HttpClientDiscovery::find(), MessageFactoryDiscovery::find()); diff --git a/tests/Functional/ProfilingTest.php b/tests/Functional/ProfilingTest.php index be126957..b1f31b87 100644 --- a/tests/Functional/ProfilingTest.php +++ b/tests/Functional/ProfilingTest.php @@ -64,9 +64,6 @@ public function testProfilingWithCachePlugin() $this->assertEquals('example.com', $stack->getRequestHost()); } - /** - * @expectedException \Exception - */ public function testProfilingWhenPluginThrowException() { $client = $this->createClient([ @@ -74,6 +71,7 @@ public function testProfilingWhenPluginThrowException() ]); try { + $this->expectException(\Exception::class); $client->sendRequest(new Request('GET', 'https://example.com')); } finally { $this->assertCount(1, $this->collector->getStacks()); diff --git a/tests/Functional/ServiceInstantiationTest.php b/tests/Functional/ServiceInstantiationTest.php index 3ebecb1a..b0e09799 100644 --- a/tests/Functional/ServiceInstantiationTest.php +++ b/tests/Functional/ServiceInstantiationTest.php @@ -2,6 +2,7 @@ namespace Http\HttplugBundle\Tests\Functional; +use GuzzleHttp\Psr7\Request as GuzzleRequest; use Http\Client\Common\Plugin\RedirectPlugin; use Http\Client\Common\PluginClient; use Http\Client\HttpClient; @@ -14,7 +15,7 @@ use Psr\Http\Message\ResponseInterface; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Request as SymfonyRequest; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Kernel; @@ -98,7 +99,7 @@ public function testProfilingPsr18Decoration() $psr18Client = NSA::getProperty($flexibleClient, 'httpClient'); $this->assertInstanceOf(ClientInterface::class, $psr18Client); - $response = $client->sendRequest(new \GuzzleHttp\Psr7\Request('GET', 'https://example.com')); + $response = $client->sendRequest(new GuzzleRequest('GET', 'https://example.com')); $this->assertInstanceOf(ResponseInterface::class, $response); } @@ -112,7 +113,7 @@ protected static function bootKernel(array $options = []) /** @var EventDispatcherInterface $dispatcher */ $dispatcher = static::$kernel->getContainer()->get('event_dispatcher'); - $event = new GetResponseEvent(static::$kernel, new Request(), HttpKernelInterface::MASTER_REQUEST); + $event = new GetResponseEvent(static::$kernel, new SymfonyRequest(), HttpKernelInterface::MASTER_REQUEST); if (version_compare(Kernel::VERSION, '4.3.0', '>=')) { $dispatcher->dispatch($event, KernelEvents::REQUEST); diff --git a/tests/Resources/Fixtures/config/invalid_cache_config.yml b/tests/Resources/Fixtures/config/invalid_cache_config.yml index 4c94f331..e283f83f 100644 --- a/tests/Resources/Fixtures/config/invalid_cache_config.yml +++ b/tests/Resources/Fixtures/config/invalid_cache_config.yml @@ -3,7 +3,6 @@ httplug: cache: cache_pool: my_cache_pool config: - respect_cache_headers: true respect_response_cache_directives: - X-Foo - X-Bar diff --git a/tests/Unit/ClientFactory/BuzzFactoryTest.php b/tests/Unit/ClientFactory/BuzzFactoryTest.php index c1c8d19a..0ed32c9a 100644 --- a/tests/Unit/ClientFactory/BuzzFactoryTest.php +++ b/tests/Unit/ClientFactory/BuzzFactoryTest.php @@ -14,7 +14,7 @@ class BuzzFactoryTest extends TestCase { public function testCreateClient() { - if (!class_exists(\Http\Adapter\Buzz\Client::class)) { + if (!class_exists(Client::class)) { $this->markTestSkipped('Buzz adapter is not installed'); } diff --git a/tests/Unit/ClientFactory/CurlFactoryTest.php b/tests/Unit/ClientFactory/CurlFactoryTest.php index c78ee493..d3e42103 100644 --- a/tests/Unit/ClientFactory/CurlFactoryTest.php +++ b/tests/Unit/ClientFactory/CurlFactoryTest.php @@ -15,7 +15,7 @@ class CurlFactoryTest extends TestCase { public function testCreateClient() { - if (!class_exists(\Http\Client\Curl\Client::class)) { + if (!class_exists(Client::class)) { $this->markTestSkipped('Curl client is not installed'); } diff --git a/tests/Unit/ClientFactory/Guzzle6FactoryTest.php b/tests/Unit/ClientFactory/Guzzle6FactoryTest.php index fae1c294..c7581a82 100644 --- a/tests/Unit/ClientFactory/Guzzle6FactoryTest.php +++ b/tests/Unit/ClientFactory/Guzzle6FactoryTest.php @@ -13,7 +13,7 @@ class Guzzle6FactoryTest extends TestCase { public function testCreateClient() { - if (!class_exists(\Http\Adapter\Guzzle6\Client::class)) { + if (!class_exists(Client::class)) { $this->markTestSkipped('Guzzle6 adapter is not installed'); } diff --git a/tests/Unit/ClientFactory/ReactFactoryTest.php b/tests/Unit/ClientFactory/ReactFactoryTest.php index 4a8ce9a7..f0baa165 100644 --- a/tests/Unit/ClientFactory/ReactFactoryTest.php +++ b/tests/Unit/ClientFactory/ReactFactoryTest.php @@ -14,7 +14,7 @@ class ReactFactoryTest extends TestCase { public function testCreateClient() { - if (!class_exists(\Http\Adapter\React\Client::class)) { + if (!class_exists(Client::class)) { $this->markTestSkipped('React adapter is not installed'); } diff --git a/tests/Unit/ClientFactory/SocketFactoryTest.php b/tests/Unit/ClientFactory/SocketFactoryTest.php index 86fb6bd8..06affc57 100644 --- a/tests/Unit/ClientFactory/SocketFactoryTest.php +++ b/tests/Unit/ClientFactory/SocketFactoryTest.php @@ -14,7 +14,7 @@ class SocketFactoryTest extends TestCase { public function testCreateClient() { - if (!class_exists(\Http\Client\Socket\Client::class)) { + if (!class_exists(Client::class)) { $this->markTestSkipped('Socket client is not installed'); } diff --git a/tests/Unit/Collector/FormatterTest.php b/tests/Unit/Collector/FormatterTest.php index 105560f9..b0b18e15 100644 --- a/tests/Unit/Collector/FormatterTest.php +++ b/tests/Unit/Collector/FormatterTest.php @@ -9,17 +9,18 @@ use Http\HttplugBundle\Collector\Formatter; use Http\Message\Formatter as MessageFormatter; use Http\Message\Formatter\CurlCommandFormatter; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class FormatterTest extends TestCase { /** - * @var MessageFormatter|\PHPUnit_Framework_MockObject_MockObject + * @var MessageFormatter|MockObject */ private $formatter; /** - * @var CurlCommandFormatter|\PHPUnit_Framework_MockObject_MockObject + * @var CurlCommandFormatter|MockObject */ private $curlFormatter; diff --git a/tests/Unit/Collector/ProfilePluginTest.php b/tests/Unit/Collector/ProfilePluginTest.php index 7a06a527..843f4ec6 100644 --- a/tests/Unit/Collector/ProfilePluginTest.php +++ b/tests/Unit/Collector/ProfilePluginTest.php @@ -168,9 +168,6 @@ public function testOnFulfilled() $this->assertEquals('FormattedResponse', $profile->getResponse()); } - /** - * @expectedException \Http\Client\Exception\TransferException - */ public function testOnRejected() { $promise = $this->subject->handleRequest($this->request, function () { @@ -178,8 +175,7 @@ public function testOnRejected() }, function () { }); - $this->assertEquals($this->exception, $promise->wait()); - $profile = $this->currentStack->getProfiles()[0]; - $this->assertEquals('FormattedException', $profile->getResponse()); + $this->expectException(TransferException::class); + $promise->wait(); } } diff --git a/tests/Unit/Collector/StackPluginTest.php b/tests/Unit/Collector/StackPluginTest.php index c7416008..341459ad 100644 --- a/tests/Unit/Collector/StackPluginTest.php +++ b/tests/Unit/Collector/StackPluginTest.php @@ -11,6 +11,7 @@ use Http\HttplugBundle\Collector\StackPlugin; use Http\Promise\FulfilledPromise; use Http\Promise\RejectedPromise; +use PHPUnit\Framework\Error\Warning; use PHPUnit\Framework\TestCase; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -130,9 +131,6 @@ public function testOnFulfilled() $this->assertEquals('FormattedResponse', $currentStack->getResponse()); } - /** - * @expectedException \Exception - */ public function testOnRejected() { //Capture the current stack @@ -157,15 +155,10 @@ public function testOnRejected() $promise = $this->subject->handleRequest($this->request, $next, function () { }); - $this->assertEquals($this->exception, $promise->wait()); - $this->assertInstanceOf(Stack::class, $currentStack); - $this->assertEquals('FormattedException', $currentStack->getResponse()); - $this->assertTrue($currentStack->isFailed()); + $this->expectException(\Exception::class); + $promise->wait(); } - /** - * @expectedException \Exception - */ public function testOnException() { $this->collector @@ -177,27 +170,14 @@ public function testOnException() throw new \Exception(); }; + $this->expectException(\Exception::class); $this->subject->handleRequest($this->request, $next, function () { }); } public function testOnError() { - if (PHP_VERSION_ID <= 70000) { - $this->markTestSkipped(); - } - - /* - * Use the correct PHPUnit version - * PHPUnit wrap any \Error into a \PHPUnit\Framework\Error\Warning. - */ - if (class_exists('PHPUnit_Framework_Error')) { - // PHPUnit 5.7 - $this->setExpectedException(\PHPUnit_Framework_Error::class); - } else { - // PHPUnit 6.0 and above - $this->expectException(\PHPUnit\Framework\Error\Warning::class); - } + $this->expectException(Warning::class); $this->collector ->expects($this->once()) diff --git a/tests/Unit/DependencyInjection/ConfigurationTest.php b/tests/Unit/DependencyInjection/ConfigurationTest.php index 49dd4003..a9680077 100644 --- a/tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/tests/Unit/DependencyInjection/ConfigurationTest.php @@ -5,6 +5,11 @@ use Http\HttplugBundle\DependencyInjection\Configuration; use Http\HttplugBundle\DependencyInjection\HttplugExtension; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionConfigurationTestCase; +use Http\Adapter\Guzzle6\Client; +use Http\Message\MessageFactory\GuzzleMessageFactory; +use Http\Message\UriFactory\GuzzleUriFactory; +use Http\Message\StreamFactory\GuzzleStreamFactory; +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; /** * @author David Buchmann @@ -111,10 +116,10 @@ public function testSupportsAllConfigFormats() 'stream_factory' => 'my_stream_factory', ], 'classes' => [ - 'client' => 'Http\Adapter\Guzzle6\Client', - 'message_factory' => 'Http\Message\MessageFactory\GuzzleMessageFactory', - 'uri_factory' => 'Http\Message\UriFactory\GuzzleUriFactory', - 'stream_factory' => 'Http\Message\StreamFactory\GuzzleStreamFactory', + 'client' => Client::class, + 'message_factory' => GuzzleMessageFactory::class, + 'uri_factory' => GuzzleUriFactory::class, + 'stream_factory' => GuzzleStreamFactory::class, ], 'clients' => [ 'test' => [ @@ -280,44 +285,39 @@ public function testSupportsAllConfigFormats() } } - /** - * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage Nonexisting\Class - */ public function testMissingClass() { $file = __DIR__.'/../../Resources/Fixtures/config/invalid_class.yml'; + + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage('Nonexisting\Class'); $this->assertProcessedConfigurationEquals([], [$file]); } - /** - * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage Unrecognized option "foobar" under "httplug.clients.acme.plugins.0" - */ public function testInvalidPlugin() { $file = __DIR__.'/../../Resources/Fixtures/config/invalid_plugin.yml'; + + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage('Unrecognized option "foobar" under "httplug.clients.acme.plugins.0"'); $this->assertProcessedConfigurationEquals([], [$file]); } - /** - * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage password, service, username - */ public function testInvalidAuthentication() { $file = __DIR__.'/../../Resources/Fixtures/config/invalid_auth.yml'; + + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage('password, service, username'); $this->assertProcessedConfigurationEquals([], [$file]); } - /** - * @group legacy - * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage Invalid configuration for path "httplug.plugins.cache.config": You can't provide config option "respect_cache_headers" and "respect_response_cache_directives" simultaniously. Use "respect_response_cache_directives" instead. - */ public function testInvalidCacheConfig() { $file = __DIR__.'/../../Resources/Fixtures/config/invalid_cache_config.yml'; + + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage('Invalid configuration for path "httplug.plugins.cache.config": You can\'t provide config option "respect_cache_headers" and "respect_response_cache_directives" simultaniously. Use "respect_response_cache_directives" instead.'); $this->assertProcessedConfigurationEquals([], [$file]); } @@ -374,33 +374,30 @@ public function testCacheConfigDeprecationCompatibilityIssue166() $this->assertProcessedConfigurationEquals($config, [$file]); } - /** - * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage Can't configure both "toolbar" and "profiling" section. The "toolbar" config is deprecated as of version 1.3.0, please only use "profiling". - */ public function testProfilingToolbarCollision() { $file = __DIR__.'/../../Resources/Fixtures/config/bc/profiling_toolbar.yml'; + + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage('Can\'t configure both "toolbar" and "profiling" section. The "toolbar" config is deprecated as of version 1.3.0, please only use "profiling".'); $this->assertProcessedConfigurationEquals([], [$file]); } - /** - * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage The child node "cache_pool" at path "httplug.clients.test.plugins.0.cache" must be configured. - */ public function testClientCacheConfigMustHavePool() { $file = __DIR__.'/../../Resources/Fixtures/config/client_cache_config_with_no_pool.yml'; + + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage('The child node "cache_pool" at path "httplug.clients.test.plugins.0.cache" must be configured.'); $this->assertProcessedConfigurationEquals([], [$file]); } - /** - * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage The child node "cache_pool" at path "httplug.plugins.cache" must be configured. - */ public function testCacheConfigMustHavePool() { $file = __DIR__.'/../../Resources/Fixtures/config/cache_config_with_no_pool.yml'; + + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage('The child node "cache_pool" at path "httplug.plugins.cache" must be configured.'); $this->assertProcessedConfigurationEquals([], [$file]); } @@ -412,13 +409,12 @@ public function testLimitlessCapturedBodyLength() $this->assertProcessedConfigurationEquals($config, [$file]); } - /** - * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage The child node "captured_body_length" at path "httplug.profiling" must be an integer or null - */ public function testInvalidCapturedBodyLengthString() { $file = __DIR__.'/../../Resources/Fixtures/config/invalid_captured_body_length.yml'; + + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage('The child node "captured_body_length" at path "httplug.profiling" must be an integer or null'); $this->assertProcessedConfigurationEquals([], [$file]); } } diff --git a/tests/Unit/DependencyInjection/HttplugExtensionTest.php b/tests/Unit/DependencyInjection/HttplugExtensionTest.php index 8b2757f7..e67a2b27 100644 --- a/tests/Unit/DependencyInjection/HttplugExtensionTest.php +++ b/tests/Unit/DependencyInjection/HttplugExtensionTest.php @@ -9,6 +9,7 @@ use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\Kernel; +use Http\Adapter\Guzzle6\Client; /** * @author David Buchmann @@ -43,11 +44,11 @@ public function testConfigLoadClass() { $this->load([ 'classes' => [ - 'client' => 'Http\Adapter\Guzzle6\Client', + 'client' => Client::class, ], ]); - $this->assertContainerBuilderHasService('httplug.client.default', 'Http\Adapter\Guzzle6\Client'); + $this->assertContainerBuilderHasService('httplug.client.default', Client::class); } public function testConfigLoadService() @@ -457,7 +458,7 @@ public function testBatchClientCanBePublic() */ public function testVcrPluginConfiguration(array $config, array $services, array $arguments = []) { - if (!class_exists(\Http\Client\Plugin\Vcr\Recorder\InMemoryRecorder::class)) { + if (!class_exists(InMemoryRecorder::class)) { $this->markTestSkipped('VCR plugin is not installed.'); } @@ -481,7 +482,7 @@ public function testVcrPluginConfiguration(array $config, array $services, array */ public function testIsNotLoadedUnlessNeeded() { - if (!class_exists(\Http\Client\Plugin\Vcr\Recorder\InMemoryRecorder::class)) { + if (!class_exists(InMemoryRecorder::class)) { $this->markTestSkipped('VCR plugin is not installed.'); }