Skip to content

Commit

Permalink
Merge pull request #6 from Codeception/maintenance
Browse files Browse the repository at this point in the history
Maintenance
  • Loading branch information
Naktibalda authored Jul 5, 2020
2 parents 2f03dd3 + d878972 commit c196265
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 32 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
28 changes: 13 additions & 15 deletions src/Codeception/Lib/Connector/Guzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

/**
Expand All @@ -49,7 +48,7 @@ public function setRefreshMaxInterval($seconds)
$this->refreshMaxInterval = $seconds;
}

public function setClient(GuzzleClient &$client)
public function setClient(GuzzleClient $client)
{
$this->client = $client;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -120,7 +119,7 @@ protected function createResponse(Psr7Response $response)
}

if (strpos($contentType, 'charset=') === false) {
if (preg_match('/\<meta[^\>]+charset *= *["\']?([a-zA-Z\-0-9]+)/i', $body, $matches)) {
if (preg_match('/<meta[^>]+charset *= *["\']?([a-zA-Z\-0-9]+)/i', $body, $matches)) {
$contentType .= ';charset=' . $matches[1];
}
$headers['Content-Type'] = [$contentType];
Expand All @@ -131,7 +130,7 @@ protected function createResponse(Psr7Response $response)
$matches = [];

$matchesMeta = preg_match(
'/\<meta[^\>]+http-equiv="refresh" content="\s*(\d*)\s*;\s*url=(.*?)"/i',
'/<meta[^>]+http-equiv="refresh" content="\s*(\d*)\s*;\s*url=(.*?)"/i',
$body,
$matches
);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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,
Expand All @@ -312,7 +311,7 @@ protected function mapFiles($requestFiles, $arrayName = '')
} else {
$files[] = [
'name' => $name,
'contents' => fopen($info, 'r')
'contents' => fopen($info, 'rb')
];
}
}
Expand All @@ -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);
Expand Down
20 changes: 8 additions & 12 deletions src/Codeception/Module/PhpBrowser.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
namespace Codeception\Module;

use Closure;
use Codeception\Lib\Connector\Guzzle;
use Codeception\Lib\InnerBrowser;
use Codeception\Lib\Interfaces\MultiSession;
use Codeception\Lib\Interfaces\Remote;
use Codeception\Lib\Interfaces\RequiresPackage;
use Codeception\TestInterface;
use Codeception\Util\Uri;
use GuzzleHttp\Client as GuzzleClient;
Expand Down Expand Up @@ -74,7 +74,7 @@
* * `client` - Symfony BrowserKit instance.
*
*/
class PhpBrowser extends InnerBrowser implements Remote, MultiSession, RequiresPackage
class PhpBrowser extends InnerBrowser implements Remote, MultiSession
{

protected $requiredFields = ['url'];
Expand Down Expand Up @@ -110,7 +110,7 @@ class PhpBrowser extends InnerBrowser implements Remote, MultiSession, RequiresP
];

/**
* @var \Codeception\Lib\Connector\Guzzle
* @var Guzzle
*/
public $client;

Expand All @@ -119,11 +119,6 @@ class PhpBrowser extends InnerBrowser implements Remote, MultiSession, RequiresP
*/
public $guzzle;

public function _requires()
{
return ['GuzzleHttp\Client' => '"guzzlehttp/guzzle": ">=6.3.0 <7.0"'];
}

public function _initialize()
{
$this->_initializeSession();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit c196265

Please sign in to comment.