Skip to content

Commit e886581

Browse files
committed
Update codebase to PHP 7.4
1 parent b6fa20b commit e886581

File tree

9 files changed

+271
-194
lines changed

9 files changed

+271
-194
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
strategy:
1010
matrix:
11-
php: [7.3, 7.4, 8.0]
11+
php: [7.4, 8.0]
1212

1313
steps:
1414
- name: Checkout code

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
],
1616
"minimum-stability": "RC",
1717
"require": {
18-
"php": "^7.3 || ^8.0",
18+
"php": "^7.4 || ^8.0",
1919
"ext-json": "*",
2020
"guzzlehttp/guzzle": "^7.3",
2121
"codeception/lib-innerbrowser": "^1.5 || *@dev",
2222
"codeception/codeception": "^5.0 || *@dev"
2323
},
2424
"require-dev": {
25+
"ext-curl": "*",
26+
"aws/aws-sdk-php": "^3.199",
2527
"codeception/module-rest": "^1.3 || *@dev"
2628
},
2729
"conflict": {

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A Codeception module for testing web application over HTTP.
99

1010
## Requirements
1111

12-
* `PHP 7.3` or higher.
12+
* `PHP 7.4` or higher.
1313

1414
## Installation
1515

src/Codeception/Lib/Connector/Guzzle.php

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
namespace Codeception\Lib\Connector;
66

7-
use Aws\Credentials\Credentials;
8-
use Aws\Signature\SignatureV4;
7+
use Aws\Credentials\Credentials as AwsCredentials;
8+
use Aws\Signature\SignatureV4 as AwsSignatureV4;
99
use Codeception\Util\Uri;
1010
use GuzzleHttp\Client as GuzzleClient;
11-
use GuzzleHttp\Cookie\CookieJar;
11+
use GuzzleHttp\Cookie\CookieJar as GuzzleCookieJar;
1212
use GuzzleHttp\Cookie\SetCookie;
1313
use GuzzleHttp\Exception\RequestException;
1414
use GuzzleHttp\Handler\CurlHandler;
1515
use GuzzleHttp\Handler\StreamHandler;
16-
use GuzzleHttp\HandlerStack;
16+
use GuzzleHttp\HandlerStack as GuzzleHandlerStack;
1717
use GuzzleHttp\Psr7\Request as Psr7Request;
1818
use GuzzleHttp\Psr7\Response as Psr7Response;
1919
use GuzzleHttp\Psr7\Uri as Psr7Uri;
@@ -23,33 +23,18 @@
2323

2424
class Guzzle extends AbstractBrowser
2525
{
26-
/**
27-
* @var array
28-
*/
29-
protected $requestOptions = [
26+
protected array $requestOptions = [
3027
'allow_redirects' => false,
3128
'headers' => [],
3229
];
3330

34-
/**
35-
* @var int
36-
*/
37-
protected $refreshMaxInterval = 0;
31+
protected int $refreshMaxInterval = 0;
3832

39-
/**
40-
* @var \Aws\Credentials\Credentials|null
41-
*/
42-
protected $awsCredentials;
33+
protected ?AwsCredentials $awsCredentials = null;
4334

44-
/**
45-
* @var \Aws\Signature\SignatureV4|null
46-
*/
47-
protected $awsSignature;
35+
protected ?AwsSignatureV4 $awsSignature = null;
4836

49-
/**
50-
* @var GuzzleClient
51-
*/
52-
protected $client;
37+
protected ?GuzzleClient $client = null;
5338

5439
/**
5540
* Sets the maximum allowable timeout interval for a meta tag refresh to
@@ -108,13 +93,12 @@ public function setAuth(string $username, string $password, string $type = 'basi
10893
unset($this->requestOptions['auth']);
10994
return;
11095
}
96+
11197
$this->requestOptions['auth'] = [$username, $password, $type];
11298
}
11399

114100
/**
115101
* Taken from Mink\BrowserKitDriver
116-
*
117-
* @return BrowserKitResponse
118102
*/
119103
protected function createResponse(Psr7Response $psr7Response): BrowserKitResponse
120104
{
@@ -126,6 +110,7 @@ protected function createResponse(Psr7Response $psr7Response): BrowserKitRespons
126110
if (isset($headers['Content-Type'])) {
127111
$contentType = reset($headers['Content-Type']);
128112
}
113+
129114
if (!$contentType) {
130115
$contentType = 'text/html';
131116
}
@@ -134,6 +119,7 @@ protected function createResponse(Psr7Response $psr7Response): BrowserKitRespons
134119
if (preg_match('#<meta[^>]+charset *= *["\']?([a-zA-Z\-0-9]+)#i', $body, $matches)) {
135120
$contentType .= ';charset=' . $matches[1];
136121
}
122+
137123
$headers['Content-Type'] = [$contentType];
138124
}
139125

@@ -182,17 +168,19 @@ protected function getAbsoluteUri($uri)
182168

183169
return Uri::appendPath((string)$baseUri, $uri);
184170
}
171+
185172
// relative url
186173
if (!$this->getHistory()->isEmpty()) {
187174
return Uri::mergeUrls((string)$this->getHistory()->current()->getUri(), $uri);
188175
}
189176
}
177+
190178
return Uri::mergeUrls((string)$baseUri, $uri);
191179
}
192180

193181
protected function doRequest($request)
194182
{
195-
/** @var $request BrowserKitRequest **/
183+
/** @var $request BrowserKitRequest **/
196184
$guzzleRequest = new Psr7Request(
197185
$request->getMethod(),
198186
$request->getUri(),
@@ -217,15 +205,20 @@ protected function doRequest($request)
217205
} else {
218206
$response = $this->client->send($guzzleRequest, $options);
219207
}
220-
} catch (RequestException $e) {
221-
if (!$e->hasResponse()) {
222-
throw $e;
208+
} catch (RequestException $exception) {
209+
if (!$exception->hasResponse()) {
210+
throw $exception;
223211
}
224-
$response = $e->getResponse();
212+
213+
$response = $exception->getResponse();
225214
}
215+
226216
return $this->createResponse($response);
227217
}
228218

219+
/**
220+
* @return array<string, mixed>
221+
*/
229222
protected function extractHeaders(BrowserKitRequest $request): array
230223
{
231224
$headers = [];
@@ -240,6 +233,7 @@ protected function extractHeaders(BrowserKitRequest $request): array
240233
$headers[$header] = $val;
241234
}
242235
}
236+
243237
return $headers;
244238
}
245239

@@ -255,9 +249,11 @@ protected function extractFormData(BrowserKitRequest $browserKitRequest): ?array
255249
if (isset($headers['HTTP_CONTENT_TYPE']) && $headers['HTTP_CONTENT_TYPE'] !== 'application/x-www-form-urlencoded') {
256250
return null;
257251
}
252+
258253
if ($browserKitRequest->getContent() !== null) {
259254
return null;
260255
}
256+
261257
return $browserKitRequest->getParameters();
262258
}
263259

@@ -275,6 +271,7 @@ protected function extractMultipartFormData(BrowserKitRequest $browserKitRequest
275271
foreach ($browserKitRequest->getParameters() as $k => $parameter) {
276272
$parts = $this->formatMultipart($parts, $k, $parameter);
277273
}
274+
278275
return $parts;
279276
}
280277

@@ -284,8 +281,10 @@ protected function formatMultipart($parts, $key, $value)
284281
foreach ($value as $subKey => $subValue) {
285282
$parts = array_merge($this->formatMultipart([], $key.sprintf('[%s]', $subKey), $subValue), $parts);
286283
}
284+
287285
return $parts;
288286
}
287+
289288
$parts[] = ['name' => $key, 'contents' => (string) $value];
290289
return $parts;
291290
}
@@ -313,6 +312,7 @@ protected function mapFiles($requestFiles, $arrayName = ''): array
313312
'content-type' => $info['type']
314313
];
315314
}
315+
316316
$files[] = $file;
317317
}
318318
} else {
@@ -329,7 +329,7 @@ protected function mapFiles($requestFiles, $arrayName = ''): array
329329
return $files;
330330
}
331331

332-
protected function extractCookies($host): \GuzzleHttp\Cookie\CookieJar
332+
protected function extractCookies($host): GuzzleCookieJar
333333
{
334334
$jar = [];
335335
$cookies = $this->getCookieJar()->all();
@@ -338,34 +338,41 @@ protected function extractCookies($host): \GuzzleHttp\Cookie\CookieJar
338338
if (!$setCookie->getDomain()) {
339339
$setCookie->setDomain($host);
340340
}
341+
341342
$jar[] = $setCookie;
342343
}
343-
return new CookieJar(false, $jar);
344+
345+
return new GuzzleCookieJar(false, $jar);
344346
}
345347

346-
public static function createHandler($handler): \GuzzleHttp\HandlerStack
348+
public static function createHandler($handler): GuzzleHandlerStack
347349
{
348-
if ($handler instanceof HandlerStack) {
350+
if ($handler instanceof GuzzleHandlerStack) {
349351
return $handler;
350352
}
353+
351354
if ($handler === 'curl') {
352-
return HandlerStack::create(new CurlHandler());
355+
return GuzzleHandlerStack::create(new CurlHandler());
353356
}
357+
354358
if ($handler === 'stream') {
355-
return HandlerStack::create(new StreamHandler());
359+
return GuzzleHandlerStack::create(new StreamHandler());
356360
}
361+
357362
if (is_string($handler) && class_exists($handler)) {
358-
return HandlerStack::create(new $handler);
363+
return GuzzleHandlerStack::create(new $handler);
359364
}
365+
360366
if (is_callable($handler)) {
361-
return HandlerStack::create($handler);
367+
return GuzzleHandlerStack::create($handler);
362368
}
363-
return HandlerStack::create();
369+
370+
return GuzzleHandlerStack::create();
364371
}
365372

366373
public function setAwsAuth($config): void
367374
{
368-
$this->awsCredentials = new Credentials($config['key'], $config['secret']);
369-
$this->awsSignature = new SignatureV4($config['service'], $config['region']);
375+
$this->awsCredentials = new AwsCredentials($config['key'], $config['secret']);
376+
$this->awsSignature = new AwsSignatureV4($config['service'], $config['region']);
370377
}
371378
}

src/Codeception/Module/PhpBrowser.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use GuzzleHttp\Client as GuzzleClient;
1515

1616
/**
17-
* Uses [Guzzle](http://guzzlephp.org/) to interact with your application over CURL.
17+
* Uses [Guzzle](https://docs.guzzlephp.org/en/stable/) to interact with your application over CURL.
1818
* Module works over CURL and requires **PHP CURL extension** to be enabled.
1919
*
2020
* Use to perform web acceptance tests with non-javascript browser.
@@ -106,7 +106,7 @@ class PhpBrowser extends InnerBrowser implements Remote, MultiSession
106106
/**
107107
* @var string[]
108108
*/
109-
protected $guzzleConfigFields = [
109+
protected array $guzzleConfigFields = [
110110
'auth',
111111
'proxy',
112112
'verify',
@@ -125,10 +125,7 @@ class PhpBrowser extends InnerBrowser implements Remote, MultiSession
125125
*/
126126
public $client;
127127

128-
/**
129-
* @var GuzzleClient
130-
*/
131-
public $guzzle;
128+
public ?GuzzleClient $guzzle = null;
132129

133130
public function _initialize()
134131
{
@@ -140,6 +137,7 @@ public function _before(TestInterface $test)
140137
if (!$this->client) {
141138
$this->client = new Guzzle();
142139
}
140+
143141
$this->_prepareSession();
144142
}
145143

@@ -171,6 +169,7 @@ public function amOnUrl($url): void
171169
if ($page === '') {
172170
$page = '/';
173171
}
172+
174173
$this->debugSection('Host', $host);
175174
$this->amOnPage($page);
176175
}
@@ -214,6 +213,9 @@ public function executeInGuzzle(Closure $function)
214213
return $function($this->guzzle);
215214
}
216215

216+
/**
217+
* @return int|string
218+
*/
217219
public function _getResponseCode()
218220
{
219221
return $this->getResponseStatusCode();
@@ -226,7 +228,7 @@ public function _initializeSession(): void
226228
$this->_prepareSession();
227229
}
228230

229-
public function _prepareSession()
231+
public function _prepareSession(): void
230232
{
231233
$defaults = array_intersect_key($this->config, array_flip($this->guzzleConfigFields));
232234
$curlOptions = [];
@@ -248,6 +250,7 @@ public function _prepareSession()
248250
$handler->push($middleware);
249251
}
250252
}
253+
251254
$defaults['handler'] = $handler;
252255
$this->guzzle = new GuzzleClient($defaults);
253256

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy