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

prepare release, use class constants in all tests #344

Merged
merged 1 commit into from Jun 5, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions CHANGELOG.md
Expand Up @@ -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

Expand All @@ -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

Expand Down
5 changes: 3 additions & 2 deletions tests/Functional/DiscoveryTest.php
Expand Up @@ -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 <mark.sagikazar@gmail.com>
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Issue206.php
Expand Up @@ -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());
Expand Down
4 changes: 1 addition & 3 deletions tests/Functional/ProfilingTest.php
Expand Up @@ -64,16 +64,14 @@ public function testProfilingWithCachePlugin()
$this->assertEquals('example.com', $stack->getRequestHost());
}

/**
* @expectedException \Exception
*/
public function testProfilingWhenPluginThrowException()
{
$client = $this->createClient([
new ExceptionThrowerPlugin(),
]);

try {
$this->expectException(\Exception::class);
$client->sendRequest(new Request('GET', 'https://example.com'));
} finally {
$this->assertCount(1, $this->collector->getStacks());
Expand Down
7 changes: 4 additions & 3 deletions tests/Functional/ServiceInstantiationTest.php
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/ClientFactory/BuzzFactoryTest.php
Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/ClientFactory/CurlFactoryTest.php
Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/ClientFactory/Guzzle6FactoryTest.php
Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/ClientFactory/ReactFactoryTest.php
Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/ClientFactory/SocketFactoryTest.php
Expand Up @@ -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');
}

Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/Collector/FormatterTest.php
Expand Up @@ -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;

Expand Down
8 changes: 2 additions & 6 deletions tests/Unit/Collector/ProfilePluginTest.php
Expand Up @@ -168,18 +168,14 @@ public function testOnFulfilled()
$this->assertEquals('FormattedResponse', $profile->getResponse());
}

/**
* @expectedException \Http\Client\Exception\TransferException
*/
public function testOnRejected()
{
$promise = $this->subject->handleRequest($this->request, function () {
return $this->rejectedPromise;
}, function () {
});

$this->assertEquals($this->exception, $promise->wait());
$profile = $this->currentStack->getProfiles()[0];
$this->assertEquals('FormattedException', $profile->getResponse());
$this->expectException(TransferException::class);
$promise->wait();
}
}
30 changes: 5 additions & 25 deletions tests/Unit/Collector/StackPluginTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -130,9 +131,6 @@ public function testOnFulfilled()
$this->assertEquals('FormattedResponse', $currentStack->getResponse());
}

/**
* @expectedException \Exception
*/
public function testOnRejected()
{
//Capture the current stack
Expand All @@ -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
Expand All @@ -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())
Expand Down