Skip to content

Commit 5aa4f35

Browse files
Merge pull request #1 from xurumelous/master
Updated Guzzle to version 6.
2 parents eb39e37 + 9d27f24 commit 5aa4f35

File tree

6 files changed

+30
-34
lines changed

6 files changed

+30
-34
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
composer.lock
22
vendor
3+
.idea

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
language: php
22

33
php:
4-
- 5.4
54
- 5.5
65
- 5.6
6+
- 7.0
77
- hhvm
88

99
before_install:
@@ -23,3 +23,8 @@ after_failure:
2323
- cat server.log
2424
- sudo cat /var/log/nginx/error.log
2525
- sudo cat /var/log/nginx/access.log
26+
27+
matrix:
28+
allow_failures:
29+
- php: 7.0
30+
- php: hhvm

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"require": {
1818
"php": ">=5.4",
1919
"behat/behat": "~3.0",
20-
"guzzlehttp/guzzle": "4 - 5",
20+
"guzzlehttp/guzzle": "~6",
2121
"phpunit/phpunit": "~4.0"
2222
},
2323
"require-dev": {

features/testapp.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Feature: Test app verification
1111
progress: ~
1212
extensions:
1313
Behat\WebApiExtension:
14-
base_url: http://localhost:8080/
14+
base_uri: http://localhost:8080/
1515
1616
suites:
1717
default:

src/Context/WebApiContext.php

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use GuzzleHttp\ClientInterface;
1616
use GuzzleHttp\Exception\RequestException;
1717
use PHPUnit_Framework_Assert as Assertions;
18+
use GuzzleHttp\Psr7\Request;
19+
use Psr\Http\Message\ResponseInterface;
1820

1921
/**
2022
* Provides web API description definitions.
@@ -39,14 +41,14 @@ class WebApiContext implements ApiClientAwareContext
3941
protected $headers = array();
4042

4143
/**
42-
* @var \GuzzleHttp\Message\RequestInterface
44+
* @var ResponseInterface
4345
*/
44-
protected $request;
46+
protected $response;
4547

4648
/**
47-
* @var \GuzzleHttp\Message\ResponseInterface
49+
* @var Request
4850
*/
49-
protected $response;
51+
protected $request;
5052

5153
protected $placeHolders = array();
5254

@@ -97,10 +99,7 @@ public function iSetHeaderWithValue($name, $value)
9799
public function iSendARequest($method, $url)
98100
{
99101
$url = $this->prepareUrl($url);
100-
$this->request = $this->getClient()->createRequest($method, $url);
101-
if (!empty($this->headers)) {
102-
$this->request->addHeaders($this->headers);
103-
}
102+
$this->request = new Request($method, $url, $this->getHeaders());
104103

105104
$this->sendRequest();
106105
}
@@ -123,13 +122,7 @@ public function iSendARequestWithValues($method, $url, TableNode $post)
123122
$fields[$key] = $this->replacePlaceHolder($val);
124123
}
125124

126-
$bodyOption = array(
127-
'body' => json_encode($fields),
128-
);
129-
$this->request = $this->getClient()->createRequest($method, $url, $bodyOption);
130-
if (!empty($this->headers)) {
131-
$this->request->addHeaders($this->headers);
132-
}
125+
$this->request = new Request($method, $url, $this->getHeaders(), json_encode($fields));
133126

134127
$this->sendRequest();
135128
}
@@ -147,15 +140,8 @@ public function iSendARequestWithBody($method, $url, PyStringNode $string)
147140
{
148141
$url = $this->prepareUrl($url);
149142
$string = $this->replacePlaceHolder(trim($string));
143+
$this->request = new Request($method, $url, $this->getHeaders(), $string);
150144

151-
$this->request = $this->getClient()->createRequest(
152-
$method,
153-
$url,
154-
array(
155-
'headers' => $this->getHeaders(),
156-
'body' => $string,
157-
)
158-
);
159145
$this->sendRequest();
160146
}
161147

@@ -174,14 +160,18 @@ public function iSendARequestWithFormData($method, $url, PyStringNode $body)
174160
$body = $this->replacePlaceHolder(trim($body));
175161

176162
$fields = array();
163+
$requestFields = [];
177164
parse_str(implode('&', explode("\n", $body)), $fields);
178-
$this->request = $this->getClient()->createRequest($method, $url);
179-
/** @var \GuzzleHttp\Post\PostBodyInterface $requestBody */
180-
$requestBody = $this->request->getBody();
165+
181166
foreach ($fields as $key => $value) {
182-
$requestBody->setField($key, $value);
167+
$requestFields[] = sprintf('%s=%s', urlencode($key), urlencode($value));
183168
}
184169

170+
$requestBody = implode('&', $requestFields);
171+
172+
$headers = array_merge($this->getHeaders(), ['Content-Type' => 'application/x-www-form-urlencoded']);
173+
$this->request = new Request($method, $url, $headers, $requestBody);
174+
185175
$this->sendRequest();
186176
}
187177

@@ -241,7 +231,7 @@ public function theResponseShouldNotContain($text)
241231
public function theResponseShouldContainJson(PyStringNode $jsonString)
242232
{
243233
$etalon = json_decode($this->replacePlaceHolder($jsonString->getRaw()), true);
244-
$actual = $this->response->json();
234+
$actual = json_decode($this->response->getBody(), true);
245235

246236
if (null === $etalon) {
247237
throw new \RuntimeException(
@@ -268,8 +258,8 @@ public function printResponse()
268258

269259
echo sprintf(
270260
"%s %s => %d:\n%s",
271-
$request->getMethod(),
272-
$request->getUrl(),
261+
$this->request->getMethod(),
262+
$this->request->getUri(),
273263
$response->getStatusCode(),
274264
$response->getBody()
275265
);

src/ServiceContainer/WebApiExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function configure(ArrayNodeDefinition $builder)
5050
$builder
5151
->addDefaultsIfNotSet()
5252
->children()
53-
->scalarNode('base_url')
53+
->scalarNode('base_uri')
5454
->defaultValue('http://localhost')
5555
->end()
5656
->end()

0 commit comments

Comments
 (0)