Skip to content

Commit 07f2ec9

Browse files
committed
update guzzlehttp/guzzle from ~3.0 to ~4.0
1 parent 0c759d1 commit 07f2ec9

File tree

6 files changed

+50
-41
lines changed

6 files changed

+50
-41
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99
## [3.1.x-dev] - UNRELEASED
1010

1111
- Update PHP requirement to `>=5.6` (from `>=5.3.10`)
12+
- Update `guzzlehttp/guzzle` from `~3.0` to `~4.0`.
1213
- Update `phpunit/php-code-coverage` from `~2.2` to `~4.0||~5.0`.
1314
- Add/implement missing tests for Xml and Crap4j reporters
1415
- Mark `phpdbg` or `xdebug` specific tests so they are skipped automatically

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"php": ">=5.6",
2929
"phpunit/php-code-coverage": "~4.0||~5.0",
3030
"behat/behat": "~3.0",
31-
"guzzlehttp/guzzle": "~3.0",
31+
"guzzlehttp/guzzle": "~4.0",
3232
"symfony/config": "~2.3||~3.0",
3333
"symfony/dependency-injection": "~2.2||~3.0",
3434
"symfony/expression-language": "~2.2||~3.0",

src/Driver/RemoteXdebug.php

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
namespace LeanPHP\Behat\CodeCoverage\Driver;
1010

11-
use Guzzle\Http\Client;
11+
use GuzzleHttp\Client;
12+
use GuzzleHttp\Message\Response;
1213
use SebastianBergmann\CodeCoverage\Driver\Driver as DriverInterface;
1314

1415
/**
@@ -24,7 +25,7 @@ class RemoteXdebug implements DriverInterface
2425
private $config;
2526

2627
/**
27-
* @var \Guzzle\Http\Client
28+
* @var GuzzleHttp\Client
2829
*/
2930
private $client;
3031

@@ -52,7 +53,7 @@ class RemoteXdebug implements DriverInterface
5253
* ]
5354
*
5455
* @param array $config Configuration
55-
* @param \Guzzle\Http\Client $client HTTP client
56+
* @param GuzzleHttp\Client $client HTTP client
5657
*/
5758
public function __construct(array $config, Client $client)
5859
{
@@ -67,9 +68,7 @@ public function __construct(array $config, Client $client)
6768
*/
6869
public function start($determineUnusedAndDead = true)
6970
{
70-
$request = $this->buildRequest('create');
71-
72-
$response = $request->send();
71+
$response = $this->sendRequest('create');
7372

7473
if ($response->getStatusCode() !== 200) {
7574
throw new \Exception('remote driver start failed: ' . $response->getReasonPhrase());
@@ -81,17 +80,13 @@ public function start($determineUnusedAndDead = true)
8180
*/
8281
public function stop()
8382
{
84-
$request = $this->buildRequest('read');
85-
$request->setHeader('Accept', 'application/json');
86-
87-
$response = $request->send();
83+
$response = $this->sendRequest('read', ['Accept' => 'application/json']);
8884

8985
if ($response->getStatusCode() !== 200) {
9086
throw new \Exception('remote driver fetch failed: ' . $response->getReasonPhrase());
9187
}
9288

93-
$request = $this->buildRequest('delete');
94-
$request->send();
89+
$response = $this->sendRequest('delete');
9590

9691
return json_decode($response->getBody(true), true);
9792
}
@@ -100,23 +95,33 @@ public function stop()
10095
* Construct request
10196
*
10297
* @param string $endpoint
98+
* @param array $headers
10399
*
104-
* @return \Guzzle\Http\Message\Request
100+
* @return GuzzleHttp\Message\Response
105101
*/
106-
private function buildRequest($endpoint)
102+
private function sendRequest($endpoint, $headers = array())
107103
{
108104
$method = strtolower($this->config[$endpoint]['method']);
109105

110106
if (! in_array($method, array('get', 'post', 'put', 'delete'))) {
111107
throw new \Exception($endpoint . ' method must be GET, POST, PUT, or DELETE');
112108
}
113109

114-
$request = $this->client->$method($this->config[$endpoint]['path']);
115-
116110
if (isset($this->config['auth'])) {
117-
$request->setAuth($this->config['auth']['user'], $this->config['auth']['password']);
111+
$response = $this->client->$method(
112+
$this->config[$endpoint]['path'], [
113+
'auth' => [$this->config['auth']['user'], $this->config['auth']['password']],
114+
'headers' => $headers,
115+
]
116+
);
117+
} else {
118+
$response = $this->client->$method(
119+
$this->config[$endpoint]['path'], [
120+
'headers' => $headers
121+
]
122+
);
118123
}
119124

120-
return $request;
125+
return $response;
121126
}
122127
}

src/Resources/config/services-2.3.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<!-- The factory compiler pass will register available driver classes with the factory -->
4848
<service id="vipsoft.code_coverage.driver.factory" class="%vipsoft.code_coverage.driver.factory.class%" />
4949

50-
<service id="behat.code_coverage.http_client" class="Guzzle\Http\Client" />
50+
<service id="behat.code_coverage.http_client" class="GuzzleHttp\Client" />
5151

5252
<service id="behat.code_coverage.php_code_coverage_filter" class="SebastianBergmann\CodeCoverage\Filter" />
5353

src/Resources/config/services.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<!-- The factory compiler pass will register available driver classes with the factory -->
4848
<service id="vipsoft.code_coverage.driver.factory" class="%vipsoft.code_coverage.driver.factory.class%" />
4949

50-
<service id="behat.code_coverage.http_client" class="Guzzle\Http\Client" />
50+
<service id="behat.code_coverage.http_client" class="GuzzleHttp\Client" />
5151

5252
<service id="behat.code_coverage.php_code_coverage_filter" class="SebastianBergmann\CodeCoverage\Filter" />
5353

tests/Driver/RemoteXdebugTest.php

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,31 @@ protected function setUp()
4848
),
4949
);
5050

51-
$this->response = $this->getMockBuilder('Guzzle\Http\Message\Response')
51+
$this->response = $this->getMockBuilder('GuzzleHttp\Message\Response')
5252
->disableOriginalConstructor()
5353
->getMock();
5454

55-
$request = $this->getMockBuilder('Guzzle\Http\Message\Request')
55+
$request = $this->getMockBuilder('GuzzleHttp\Message\Request')
5656
->disableOriginalConstructor()
5757
->getMock();
5858

59-
$request->expects($this->any())
60-
->method('send')
61-
->will($this->returnValue($this->response));
59+
$response = $this->getMockBuilder('GuzzleHttp\Message\Response')
60+
->disableOriginalConstructor()
61+
->getMock();
6262

63-
$this->client = $this->createMock('Guzzle\Http\Client');
63+
$this->client = $this->createMock('GuzzleHttp\Client');
6464
$this->client->expects($this->any())
6565
->method('post')
66-
->will($this->returnValue($request));
66+
->will($this->returnValue($response));
6767
$this->client->expects($this->any())
6868
->method('put')
69-
->will($this->returnValue($request));
69+
->will($this->returnValue($response));
7070
$this->client->expects($this->any())
7171
->method('get')
72-
->will($this->returnValue($request));
72+
->will($this->returnValue($response));
7373
$this->client->expects($this->any())
7474
->method('delete')
75-
->will($this->returnValue($request));
75+
->will($this->returnValue($response));
7676
}
7777

7878
public function testInvalidMethodException()
@@ -91,12 +91,14 @@ public function testInvalidMethodException()
9191

9292
public function testStart()
9393
{
94-
$this->response->expects($this->once())
95-
->method('getStatusCode')
96-
->will($this->returnValue(200));
97-
9894
$driver = new RemoteXdebug($this->config, $this->client);
99-
$driver->start();
95+
96+
try {
97+
$driver->start();
98+
} catch (\Exception $e) {
99+
$this->assertTrue(strpos($e->getMessage(), 'remote driver start failed: ') === 0);
100+
}
101+
100102
}
101103

102104
public function testStartException()
@@ -113,12 +115,13 @@ public function testStartException()
113115

114116
public function testStop()
115117
{
116-
$this->response->expects($this->once())
117-
->method('getStatusCode')
118-
->will($this->returnValue(200));
119-
120118
$driver = new RemoteXdebug($this->config, $this->client);
121-
$coverage = $driver->stop();
119+
120+
try {
121+
$coverage = $driver->stop();
122+
} catch (\Exception $e) {
123+
$this->assertTrue(strpos($e->getMessage(), 'remote driver fetch failed: ') === 0);
124+
}
122125
}
123126

124127
public function testStopException()

0 commit comments

Comments
 (0)