Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #93 from stof/towards_v2
Browse files Browse the repository at this point in the history
Prepare the version 2 of the driver
  • Loading branch information
stof authored Dec 23, 2021
2 parents 715f8f1 + 2605e73 commit 22eeffb
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 108 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
php: [ '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0' ]
php: [ '7.2', '7.3', '7.4', '8.0' ]
symfony_deprecations_helper: [ '' ]
include:
- php: 8.1
Expand All @@ -40,11 +40,6 @@ jobs:
# PHP 7.1 development web server segfaults if timezone not set.
ini-values: date.timezone=Europe/Paris, error_reporting=-1, display_errors=On

- name: Configure for PHP >= 7.1
if: "${{ matrix.php >= '7.1' && matrix.symfony_version == '' }}"
run: |
composer require --no-update --dev symfony/error-handler "^4.4 || ^5.0"
- name: Install dependencies
run: |
composer update --no-interaction --prefer-dist
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require "vendor/autoload.php";
use Behat\Mink\Mink,
Behat\Mink\Session,
Behat\Mink\Driver\GoutteDriver,
Behat\Mink\Driver\Goutte\Client as GoutteClient;
Goutte\Client as GoutteClient;

$mink = new Mink(array(
'goutte' => new Session(new GoutteDriver(new GoutteClient())),
Expand All @@ -39,8 +39,8 @@ Add a file composer.json with content:
``` json
{
"require": {
"behat/mink": "~1.5",
"behat/mink-goutte-driver": "~1.0"
"behat/mink": "^1.9",
"behat/mink-goutte-driver": "^2.0"
}
}
```
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
],

"require": {
"php": ">=5.4",
"behat/mink-browserkit-driver": "~1.2@dev",
"fabpot/goutte": "~1.0.4|~2.0|~3.1"
"php": ">=7.2",
"behat/mink-browserkit-driver": "^2.0@dev",
"fabpot/goutte": "^4.0"
},

"require-dev": {
"mink/driver-testsuite": "dev-master"
"mink/driver-testsuite": "dev-master",
"symfony/error-handler": "^4.4 || ^5.0"
},

"autoload": {
Expand All @@ -38,7 +39,7 @@

"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
"dev-master": "2.x-dev"
}
}
}
23 changes: 0 additions & 23 deletions src/Goutte/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,10 @@
namespace Behat\Mink\Driver\Goutte;

use Goutte\Client as BaseClient;
use Symfony\Component\BrowserKit\Response;

/**
* Client overrides to support Mink functionality.
*/
class Client extends BaseClient
{
/**
* Reads response meta tags to guess content-type charset.
*
* @param Response $response
*
* @return Response
*/
protected function filterResponse($response)
{
$contentType = $response->getHeader('Content-Type');

if (!$contentType || false === strpos($contentType, 'charset=')) {
if (preg_match('/\<meta[^\>]+charset *= *["\']?([a-zA-Z\-0-9]+)/i', $response->getContent(), $matches)) {
$headers = $response->getHeaders();
$headers['Content-Type'] = $contentType.';charset='.$matches[1];

$response = new Response($response->getContent(), $response->getStatus(), $headers);
}
}

return parent::filterResponse($response);
}
}
53 changes: 1 addition & 52 deletions src/GoutteDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace Behat\Mink\Driver;

use Behat\Mink\Driver\Goutte\Client as ExtendedClient;
use Goutte\Client;

/**
Expand All @@ -27,56 +26,6 @@ class GoutteDriver extends BrowserKitDriver
*/
public function __construct(Client $client = null)
{
parent::__construct($client ?: new ExtendedClient());
}

/**
* {@inheritdoc}
*/
public function setBasicAuth($user, $password)
{
if (false === $user) {
$this->getClient()->resetAuth();

return;
}

$this->getClient()->setAuth($user, $password);
}

/**
* Gets the Goutte client.
*
* The method is overwritten only to provide the appropriate return type hint.
*
* @return Client
*/
public function getClient()
{
return parent::getClient();
}

/**
* {@inheritdoc}
*/
public function reset()
{
parent::reset();
$this->getClient()->resetAuth();
}

/**
* {@inheritdoc}
*/
protected function prepareUrl($url)
{
$parts = parse_url($url);
if (isset($parts['user']) || isset($parts['pass'])) {
$this->setBasicAuth(
isset($parts['user']) ? $parts['user'] : '',
isset($parts['pass']) ? $parts['pass'] : ''
);
}
return $url;
parent::__construct($client ?? new Client());
}
}
3 changes: 2 additions & 1 deletion tests/Custom/InstantiationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Behat\Mink\Tests\Driver\Custom;

use Behat\Mink\Driver\GoutteDriver;
use Goutte\Client;
use PHPUnit\Framework\TestCase;

class InstantiationTest extends TestCase
Expand All @@ -23,6 +24,6 @@ public function testInstantiateWithoutClient()
{
$driver = new GoutteDriver();

$this->assertInstanceOf('Behat\Mink\Driver\Goutte\Client', $driver->getClient());
$this->assertInstanceOf(Client::class, $driver->getClient());
}
}
18 changes: 0 additions & 18 deletions tests/GoutteConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,4 @@ protected function supportsJs()
{
return false;
}

public function skipMessage($testCase, $test)
{
if (
'Behat\Mink\Tests\Driver\Form\Html5Test' === $testCase
&& in_array($test, array(
'testHtml5FormAction',
'testHtml5FormMethod',
))
&& !method_exists('Symfony\Component\DomCrawler\Tests\FormTest', 'testGetMethodWithOverride')
// Symfony 4.4 removed tests from dist archives, making the previous detection return a false-positive
&& !method_exists('Symfony\Component\DomCrawler\Form', 'getName')
) {
return 'Mink Goutte doesn\'t support HTML5 form attributes before Symfony 3.3';
}

return parent::skipMessage($testCase, $test);
}
}

0 comments on commit 22eeffb

Please sign in to comment.