From cc571baa250c8df362a7611830b2eca68aa2e253 Mon Sep 17 00:00:00 2001 From: Gintautas Miselis Date: Sun, 5 Jul 2020 18:06:26 +0300 Subject: [PATCH 1/2] Fixed failing test by updating lib-innerbrowser --- .github/workflows/main.yml | 4 +--- composer.json | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 146a39d..995f6c7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,9 +24,7 @@ jobs: run: composer validate - name: Install dependencies - run: | - composer require phpunit/phpunit "<=8.5.2" --no-update --ignore-platform-reqs - composer install --prefer-dist --no-progress --no-interaction --no-suggest + run: composer install --prefer-dist --no-progress --no-interaction --no-suggest - name: Run test suite run: | diff --git a/composer.json b/composer.json index 71d51b5..60325ea 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,8 @@ "require": { "php": ">=5.6.0 <8.0", "guzzlehttp/guzzle": "^6.3.0|^7.0.0", - "codeception/lib-innerbrowser": "^1.0", - "codeception/codeception": "^4.0" + "codeception/lib-innerbrowser": "^1.3.2", + "codeception/codeception": "*@dev" }, "require-dev": { "codeception/util-robohelpers": "dev-master", From d878972221b436522dfb2e3f659d69bda517f8cd Mon Sep 17 00:00:00 2001 From: Gintautas Miselis Date: Sun, 5 Jul 2020 18:07:21 +0300 Subject: [PATCH 2/2] fix some code smells reported by PhpStorm --- src/Codeception/Lib/Connector/Guzzle.php | 28 +++++++++++------------- src/Codeception/Module/PhpBrowser.php | 20 +++++++---------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/Codeception/Lib/Connector/Guzzle.php b/src/Codeception/Lib/Connector/Guzzle.php index fddcf2c..7d68629 100644 --- a/src/Codeception/Lib/Connector/Guzzle.php +++ b/src/Codeception/Lib/Connector/Guzzle.php @@ -15,7 +15,6 @@ use GuzzleHttp\Psr7\Response as Psr7Response; use GuzzleHttp\Psr7\Uri as Psr7Uri; use Symfony\Component\BrowserKit\AbstractBrowser as Client; -use Symfony\Component\BrowserKit\Cookie; use Symfony\Component\BrowserKit\Request as BrowserKitRequest; use Symfony\Component\BrowserKit\Response as BrowserKitResponse; @@ -27,10 +26,10 @@ class Guzzle extends Client ]; protected $refreshMaxInterval = 0; - protected $awsCredentials = null; - protected $awsSignature = null; + protected $awsCredentials; + protected $awsSignature; - /** @var \GuzzleHttp\Client */ + /** @var GuzzleClient */ protected $client; /** @@ -49,7 +48,7 @@ public function setRefreshMaxInterval($seconds) $this->refreshMaxInterval = $seconds; } - public function setClient(GuzzleClient &$client) + public function setClient(GuzzleClient $client) { $this->client = $client; } @@ -66,7 +65,7 @@ public function setClient(GuzzleClient &$client) */ public function setHeader($name, $value) { - if (strval($value) === '') { + if ((string)$value === '') { $this->deleteHeader($name); } else { $this->requestOptions['headers'][$name] = $value; @@ -101,9 +100,9 @@ public function setAuth($username, $password, $type = 'basic') /** * Taken from Mink\BrowserKitDriver * - * @param Response $response + * @param Psr7Response $response * - * @return \Symfony\Component\BrowserKit\Response + * @return BrowserKitResponse */ protected function createResponse(Psr7Response $response) { @@ -120,7 +119,7 @@ protected function createResponse(Psr7Response $response) } if (strpos($contentType, 'charset=') === false) { - if (preg_match('/\]+charset *= *["\']?([a-zA-Z\-0-9]+)/i', $body, $matches)) { + if (preg_match('/]+charset *= *["\']?([a-zA-Z\-0-9]+)/i', $body, $matches)) { $contentType .= ';charset=' . $matches[1]; } $headers['Content-Type'] = [$contentType]; @@ -131,7 +130,7 @@ protected function createResponse(Psr7Response $response) $matches = []; $matchesMeta = preg_match( - '/\]+http-equiv="refresh" content="\s*(\d*)\s*;\s*url=(.*?)"/i', + '/]+http-equiv="refresh" content="\s*(\d*)\s*;\s*url=(.*?)"/i', $body, $matches ); @@ -149,7 +148,7 @@ protected function createResponse(Psr7Response $response) $uri = new Psr7Uri($this->getAbsoluteUri($matches[2])); $currentUri = new Psr7Uri($this->getHistory()->current()->getUri()); - if ($uri->withFragment('') != $currentUri->withFragment('')) { + if ($uri->withFragment('') !== $currentUri->withFragment('')) { $status = 302; $headers['Location'] = $matchesMeta ? htmlspecialchars_decode($uri) : (string)$uri; } @@ -196,7 +195,7 @@ protected function doRequest($request) } $formData = $this->extractFormData($request); - if (empty($multipartData) and $formData) { + if (empty($multipartData) && $formData) { $options['form_params'] = $formData; } @@ -292,7 +291,7 @@ protected function mapFiles($requestFiles, $arrayName = '') if (is_array($info)) { if (isset($info['tmp_name'])) { if ($info['tmp_name']) { - $handle = fopen($info['tmp_name'], 'r'); + $handle = fopen($info['tmp_name'], 'rb'); $filename = isset($info['name']) ? $info['name'] : null; $file = [ 'name' => $name, @@ -312,7 +311,7 @@ protected function mapFiles($requestFiles, $arrayName = '') } else { $files[] = [ 'name' => $name, - 'contents' => fopen($info, 'r') + 'contents' => fopen($info, 'rb') ]; } } @@ -325,7 +324,6 @@ protected function extractCookies($host) $jar = []; $cookies = $this->getCookieJar()->all(); foreach ($cookies as $cookie) { - /** @var $cookie Cookie **/ $setCookie = SetCookie::fromString((string)$cookie); if (!$setCookie->getDomain()) { $setCookie->setDomain($host); diff --git a/src/Codeception/Module/PhpBrowser.php b/src/Codeception/Module/PhpBrowser.php index 72a07cb..bbf2ce8 100644 --- a/src/Codeception/Module/PhpBrowser.php +++ b/src/Codeception/Module/PhpBrowser.php @@ -1,11 +1,11 @@ '"guzzlehttp/guzzle": ">=6.3.0 <7.0"']; - } - public function _initialize() { $this->_initializeSession(); @@ -175,8 +170,8 @@ public function amOnUrl($url) public function amOnSubdomain($subdomain) { $url = $this->config['url']; - $url = preg_replace('~(https?:\/\/)(.*\.)(.*\.)~', "$1$3", $url); // removing current subdomain - $url = preg_replace('~(https?:\/\/)(.*)~', "$1$subdomain.$2", $url); // inserting new + $url = preg_replace('~(https?://)(.*\.)(.*\.)~', "$1$3", $url); // removing current subdomain + $url = preg_replace('~(https?://)(.*)~', "$1$subdomain.$2", $url); // inserting new $config = $this->config; $config['url'] = $url; $this->_reconfigure($config); @@ -204,9 +199,10 @@ protected function onReconfigure() * It is not recommended to use this command on a regular basis. * If Codeception lacks important Guzzle Client methods, implement them and submit patches. * - * @param callable $function + * @param Closure $function + * @return mixed */ - public function executeInGuzzle(\Closure $function) + public function executeInGuzzle(Closure $function) { return $function($this->guzzle); }