Skip to content

Commit 5044b65

Browse files
authored
Merge pull request #344 from php-http/class-constants
prepare release, use class constants in all tests
2 parents aed7e5a + c31dc87 commit 5044b65

15 files changed

+65
-89
lines changed

CHANGELOG.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
44

5-
## 1.16.0 - unreleased
5+
## 1.16.0 - 2019-06-05
66

77
### Changed
88

@@ -12,12 +12,11 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
1212
### Added
1313

1414
- Integration for VCR Plugin
15-
- curl-client v1.* is marked in conflict with the current bundle version.
1615

1716
### Fixed
1817

19-
- Fix compatibility with curl-client v2.*, the `CurlFactory` now build the
20-
client using PSR17 factories.
18+
- Fix compatibility with curl-client `2.*`. The `CurlFactory` now builds the
19+
client using PSR-17 factories. Marked a conflict for curl-client `1.*`.
2120

2221
## 1.15.2 - 2019-04-18
2322

tests/Functional/DiscoveryTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\ContainerBuilderHasAliasConstraint;
1414
use PHPUnit\Framework\Constraint\LogicalNot;
1515
use Symfony\Component\DependencyInjection\Definition;
16+
use Http\Adapter\Guzzle6\Client;
1617

1718
/**
1819
* @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
@@ -50,9 +51,9 @@ public function testDiscoveryFallbacks()
5051
public function testDiscoveryPartialFallbacks()
5152
{
5253
$this->load();
53-
$this->setDefinition('httplug.client.default', new Definition('Http\Adapter\Guzzle6\Client'));
54+
$this->setDefinition('httplug.client.default', new Definition(Client::class));
5455

55-
$this->assertContainerBuilderHasService('httplug.client.default', 'Http\Adapter\Guzzle6\Client');
56+
$this->assertContainerBuilderHasService('httplug.client.default', Client::class);
5657
$this->assertContainerBuilderHasService('httplug.message_factory.default', MessageFactory::class);
5758
$this->assertContainerBuilderHasService('httplug.uri_factory.default', UriFactory::class);
5859
$this->assertContainerBuilderHasService('httplug.stream_factory.default', StreamFactory::class);

tests/Functional/Issue206.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function testCustomClientDoesNotCauseException()
1717
{
1818
static::bootKernel();
1919
$container = static::$kernel->getContainer();
20-
PluginClientFactory::setFactory([$container->get('Http\Client\Common\PluginClientFactory'), 'createClient']);
20+
PluginClientFactory::setFactory([$container->get(PluginClientFactory::class), 'createClient']);
2121

2222
// Create a client
2323
$myCustomClient = new HttpMethodsClient(HttpClientDiscovery::find(), MessageFactoryDiscovery::find());

tests/Functional/ProfilingTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,14 @@ public function testProfilingWithCachePlugin()
6464
$this->assertEquals('example.com', $stack->getRequestHost());
6565
}
6666

67-
/**
68-
* @expectedException \Exception
69-
*/
7067
public function testProfilingWhenPluginThrowException()
7168
{
7269
$client = $this->createClient([
7370
new ExceptionThrowerPlugin(),
7471
]);
7572

7673
try {
74+
$this->expectException(\Exception::class);
7775
$client->sendRequest(new Request('GET', 'https://example.com'));
7876
} finally {
7977
$this->assertCount(1, $this->collector->getStacks());

tests/Functional/ServiceInstantiationTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Http\HttplugBundle\Tests\Functional;
44

5+
use GuzzleHttp\Psr7\Request as GuzzleRequest;
56
use Http\Client\Common\Plugin\RedirectPlugin;
67
use Http\Client\Common\PluginClient;
78
use Http\Client\HttpClient;
@@ -14,7 +15,7 @@
1415
use Psr\Http\Message\ResponseInterface;
1516
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1617
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
17-
use Symfony\Component\HttpFoundation\Request;
18+
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
1819
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
1920
use Symfony\Component\HttpKernel\HttpKernelInterface;
2021
use Symfony\Component\HttpKernel\Kernel;
@@ -98,7 +99,7 @@ public function testProfilingPsr18Decoration()
9899
$psr18Client = NSA::getProperty($flexibleClient, 'httpClient');
99100
$this->assertInstanceOf(ClientInterface::class, $psr18Client);
100101

101-
$response = $client->sendRequest(new \GuzzleHttp\Psr7\Request('GET', 'https://example.com'));
102+
$response = $client->sendRequest(new GuzzleRequest('GET', 'https://example.com'));
102103
$this->assertInstanceOf(ResponseInterface::class, $response);
103104
}
104105

@@ -112,7 +113,7 @@ protected static function bootKernel(array $options = [])
112113
/** @var EventDispatcherInterface $dispatcher */
113114
$dispatcher = static::$kernel->getContainer()->get('event_dispatcher');
114115

115-
$event = new GetResponseEvent(static::$kernel, new Request(), HttpKernelInterface::MASTER_REQUEST);
116+
$event = new GetResponseEvent(static::$kernel, new SymfonyRequest(), HttpKernelInterface::MASTER_REQUEST);
116117

117118
if (version_compare(Kernel::VERSION, '4.3.0', '>=')) {
118119
$dispatcher->dispatch($event, KernelEvents::REQUEST);

tests/Unit/ClientFactory/BuzzFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class BuzzFactoryTest extends TestCase
1414
{
1515
public function testCreateClient()
1616
{
17-
if (!class_exists(\Http\Adapter\Buzz\Client::class)) {
17+
if (!class_exists(Client::class)) {
1818
$this->markTestSkipped('Buzz adapter is not installed');
1919
}
2020

tests/Unit/ClientFactory/CurlFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CurlFactoryTest extends TestCase
1515
{
1616
public function testCreateClient()
1717
{
18-
if (!class_exists(\Http\Client\Curl\Client::class)) {
18+
if (!class_exists(Client::class)) {
1919
$this->markTestSkipped('Curl client is not installed');
2020
}
2121

tests/Unit/ClientFactory/Guzzle6FactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Guzzle6FactoryTest extends TestCase
1313
{
1414
public function testCreateClient()
1515
{
16-
if (!class_exists(\Http\Adapter\Guzzle6\Client::class)) {
16+
if (!class_exists(Client::class)) {
1717
$this->markTestSkipped('Guzzle6 adapter is not installed');
1818
}
1919

tests/Unit/ClientFactory/ReactFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ReactFactoryTest extends TestCase
1414
{
1515
public function testCreateClient()
1616
{
17-
if (!class_exists(\Http\Adapter\React\Client::class)) {
17+
if (!class_exists(Client::class)) {
1818
$this->markTestSkipped('React adapter is not installed');
1919
}
2020

tests/Unit/ClientFactory/SocketFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class SocketFactoryTest extends TestCase
1414
{
1515
public function testCreateClient()
1616
{
17-
if (!class_exists(\Http\Client\Socket\Client::class)) {
17+
if (!class_exists(Client::class)) {
1818
$this->markTestSkipped('Socket client is not installed');
1919
}
2020

tests/Unit/Collector/FormatterTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@
99
use Http\HttplugBundle\Collector\Formatter;
1010
use Http\Message\Formatter as MessageFormatter;
1111
use Http\Message\Formatter\CurlCommandFormatter;
12+
use PHPUnit\Framework\MockObject\MockObject;
1213
use PHPUnit\Framework\TestCase;
1314

1415
class FormatterTest extends TestCase
1516
{
1617
/**
17-
* @var MessageFormatter|\PHPUnit_Framework_MockObject_MockObject
18+
* @var MessageFormatter|MockObject
1819
*/
1920
private $formatter;
2021

2122
/**
22-
* @var CurlCommandFormatter|\PHPUnit_Framework_MockObject_MockObject
23+
* @var CurlCommandFormatter|MockObject
2324
*/
2425
private $curlFormatter;
2526

tests/Unit/Collector/ProfilePluginTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,14 @@ public function testOnFulfilled()
168168
$this->assertEquals('FormattedResponse', $profile->getResponse());
169169
}
170170

171-
/**
172-
* @expectedException \Http\Client\Exception\TransferException
173-
*/
174171
public function testOnRejected()
175172
{
176173
$promise = $this->subject->handleRequest($this->request, function () {
177174
return $this->rejectedPromise;
178175
}, function () {
179176
});
180177

181-
$this->assertEquals($this->exception, $promise->wait());
182-
$profile = $this->currentStack->getProfiles()[0];
183-
$this->assertEquals('FormattedException', $profile->getResponse());
178+
$this->expectException(TransferException::class);
179+
$promise->wait();
184180
}
185181
}

tests/Unit/Collector/StackPluginTest.php

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Http\HttplugBundle\Collector\StackPlugin;
1212
use Http\Promise\FulfilledPromise;
1313
use Http\Promise\RejectedPromise;
14+
use PHPUnit\Framework\Error\Warning;
1415
use PHPUnit\Framework\TestCase;
1516
use Psr\Http\Message\RequestInterface;
1617
use Psr\Http\Message\ResponseInterface;
@@ -130,9 +131,6 @@ public function testOnFulfilled()
130131
$this->assertEquals('FormattedResponse', $currentStack->getResponse());
131132
}
132133

133-
/**
134-
* @expectedException \Exception
135-
*/
136134
public function testOnRejected()
137135
{
138136
//Capture the current stack
@@ -157,15 +155,10 @@ public function testOnRejected()
157155
$promise = $this->subject->handleRequest($this->request, $next, function () {
158156
});
159157

160-
$this->assertEquals($this->exception, $promise->wait());
161-
$this->assertInstanceOf(Stack::class, $currentStack);
162-
$this->assertEquals('FormattedException', $currentStack->getResponse());
163-
$this->assertTrue($currentStack->isFailed());
158+
$this->expectException(\Exception::class);
159+
$promise->wait();
164160
}
165161

166-
/**
167-
* @expectedException \Exception
168-
*/
169162
public function testOnException()
170163
{
171164
$this->collector
@@ -177,27 +170,14 @@ public function testOnException()
177170
throw new \Exception();
178171
};
179172

173+
$this->expectException(\Exception::class);
180174
$this->subject->handleRequest($this->request, $next, function () {
181175
});
182176
}
183177

184178
public function testOnError()
185179
{
186-
if (PHP_VERSION_ID <= 70000) {
187-
$this->markTestSkipped();
188-
}
189-
190-
/*
191-
* Use the correct PHPUnit version
192-
* PHPUnit wrap any \Error into a \PHPUnit\Framework\Error\Warning.
193-
*/
194-
if (class_exists('PHPUnit_Framework_Error')) {
195-
// PHPUnit 5.7
196-
$this->setExpectedException(\PHPUnit_Framework_Error::class);
197-
} else {
198-
// PHPUnit 6.0 and above
199-
$this->expectException(\PHPUnit\Framework\Error\Warning::class);
200-
}
180+
$this->expectException(Warning::class);
201181

202182
$this->collector
203183
->expects($this->once())

0 commit comments

Comments
 (0)