Skip to content

Commit

Permalink
minor #1 Support for PHP ^7.2 & Symfony 3.4/4.4/5+ (pamil)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.3.x-dev branch.

Discussion
----------



Commits
-------

8f60548 Clarify docs
46b3c0a Support for PHP ^7.2 & Symfony 3.4/4.4/5+
1402d74 Fix tests & drop Symfony 3.4
88bfed6 Replace the original package
8a7611e Fix the tests
  • Loading branch information
pamil authored Jan 15, 2020
2 parents 98cdff1 + 8a7611e commit 0b440bd
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 111 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
composer.lock
/phpunit.xml
/.phpunit.result.cache
37 changes: 14 additions & 23 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,27 @@ language: php

sudo: false

php: [5.6, 7.0, 7.1, 7.2, 7.3]

matrix:
include:
- php: 5.4
dist: trusty
- php: 5.5
dist: trusty
- php: 5.3
dist: precise
# Test against LTS versions
- php: 7.2
env: SYMFONY_VERSION='^2'
- php: 7.2
env: SYMFONY_VERSION='^3'
# Test against dev versions of dependencies
- php: 7.2
env: DEPENDENCIES='dev' SYMFONY_PHPUNIT_VERSION='7.5' # Avoid using PHPUnit 8 until our testsuite is compatible
php:
- 7.2
- 7.3
- 7.4

env:
- SYMFONY_VERSION=4.4.*
- SYMFONY_VERSION=5.0.*

cache:
directories:
- $HOME/.composer/cache/files
- $HOME/symfony-bridge/.phpunit

before_install:
- if [ "$DEPENDENCIES" = "dev" ]; then composer config minimum-stability dev; fi;
- sh -c 'if [ "$SYMFONY_VERSION" != "" ]; then composer require -n --no-update symfony/lts=$SYMFONY_VERSION; fi;'

install:
- composer install -n
- composer require symfony/browser-kit:$SYMFONY_VERSION --no-update --no-scripts --prefer-dist
- composer require symfony/dom-crawler:$SYMFONY_VERSION --no-update --no-scripts --prefer-dist
- composer require --dev symfony/http-kernel:$SYMFONY_VERSION --no-update --no-scripts --prefer-dist

- composer update

- vendor/bin/simple-phpunit install

script: vendor/bin/simple-phpunit -v --coverage-clover=coverage.clover
Expand Down
47 changes: 3 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,5 @@
Mink BrowserKit Driver
======================
This is the fork of MinkBrowserKitDriver library that supports PHP `^7.2` and supports Symfony `^4.4` and `^5.0`.

[![Latest Stable Version](https://poser.pugx.org/behat/mink-browserkit-driver/v/stable.png)](https://packagist.org/packages/behat/mink-browserkit-driver)
[![Latest Unstable Version](https://poser.pugx.org/behat/mink-browserkit-driver/v/unstable.svg)](https://packagist.org/packages/behat/mink-browserkit-driver)
[![Total Downloads](https://poser.pugx.org/behat/mink-browserkit-driver/downloads.png)](https://packagist.org/packages/behat/mink-browserkit-driver)
[![Build Status](https://travis-ci.org/minkphp/MinkBrowserKitDriver.svg?branch=master)](https://travis-ci.org/minkphp/MinkBrowserKitDriver)
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/minkphp/MinkBrowserKitDriver/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/minkphp/MinkBrowserKitDriver/)
[![Code Coverage](https://scrutinizer-ci.com/g/minkphp/MinkBrowserKitDriver/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/minkphp/MinkBrowserKitDriver/)
[![License](https://poser.pugx.org/behat/mink-browserkit-driver/license.svg)](https://packagist.org/packages/behat/mink-browserkit-driver)
For the documentation, please [refer to the original repository](https://github.com/minkphp/MinkBrowserKitDriver).

Usage Example
-------------

``` php
<?php

use Behat\Mink\Mink,
Behat\Mink\Session,
Behat\Mink\Driver\BrowserKitDriver;

use Symfony\Component\HttpKernel\Client;

$app = require_once(__DIR__.'/app.php'); // Silex app

$mink = new Mink(array(
'silex' => new Session(new BrowserKitDriver(new Client($app))),
));

$mink->getSession('silex')->getPage()->findLink('Chat')->click();
```

Installation
------------

To install use the `composer require` command:

```bash
composer require --dev behat/mink behat/mink-browserkit-driver
```

Maintainers
-----------

* Christophe Coevoet [stof](https://github.com/stof)
* Other [awesome developers](https://github.com/minkphp/MinkBrowserKitDriver/graphs/contributors)
No updates other than Symfony compatibility will be provided, but this fork _might_ be synchronised with the original repository in the future.
18 changes: 11 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "behat/mink-browserkit-driver",
"name": "friends-of-behat/mink-browserkit-driver",
"description": "Symfony2 BrowserKit driver for Mink framework",
"keywords": ["Symfony2", "Mink", "testing", "browser"],
"homepage": "http://mink.behat.org/",
Expand All @@ -15,15 +15,19 @@
],

"require": {
"php": ">=5.3.6",
"behat/mink": "^1.7.1@dev",
"symfony/browser-kit": "~2.3|~3.0|~4.0",
"symfony/dom-crawler": "~2.3|~3.0|~4.0"
"php": "^7.2",
"behat/mink": "^1.7",
"symfony/browser-kit": "^4.4|^5.0",
"symfony/dom-crawler": "^4.4|^5.0"
},

"require-dev": {
"mink/driver-testsuite": "dev-master",
"symfony/http-kernel": "~2.3|~3.0|~4.0"
"friends-of-behat/mink-driver-testsuite": "dev-master",
"symfony/http-kernel": "^4.4|^5.0"
},

"replace": {
"behat/mink-browserkit-driver": "self.version"
},

"autoload": {
Expand Down
20 changes: 12 additions & 8 deletions src/BrowserKitDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use Behat\Mink\Exception\DriverException;
use Behat\Mink\Exception\UnsupportedDriverActionException;
use Symfony\Component\BrowserKit\Client;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\BrowserKit\Exception\BadMethodCallException;
use Symfony\Component\BrowserKit\Response;
Expand All @@ -23,7 +23,7 @@
use Symfony\Component\DomCrawler\Field\InputFormField;
use Symfony\Component\DomCrawler\Field\TextareaFormField;
use Symfony\Component\DomCrawler\Form;
use Symfony\Component\HttpKernel\Client as HttpKernelClient;
use Symfony\Component\HttpKernel\HttpKernelBrowser;

/**
* Symfony2 BrowserKit driver.
Expand All @@ -46,23 +46,23 @@ class BrowserKitDriver extends CoreDriver
/**
* Initializes BrowserKit driver.
*
* @param Client $client BrowserKit client instance
* @param AbstractBrowser $client BrowserKit client instance
* @param string|null $baseUrl Base URL for HttpKernel clients
*/
public function __construct(Client $client, $baseUrl = null)
public function __construct(AbstractBrowser $client, $baseUrl = null)
{
$this->client = $client;
$this->client->followRedirects(true);

if ($baseUrl !== null && $client instanceof HttpKernelClient) {
if ($baseUrl !== null && $client instanceof HttpKernelBrowser) {
$client->setServerParameter('SCRIPT_FILENAME', parse_url($baseUrl, PHP_URL_PATH));
}
}

/**
* Returns BrowserKit HTTP client instance.
*
* @return Client
* @return AbstractBrowser
*/
public function getClient()
{
Expand Down Expand Up @@ -874,9 +874,13 @@ private function getFilteredCrawler($xpath)
*/
private function getCrawler()
{
$crawler = $this->client->getCrawler();
try {
$crawler = $this->client->getCrawler();

if (null === $crawler) {
if (null === $crawler) {
throw new DriverException('Unable to access the response content before visiting a page');
}
} catch (BadMethodCallException $exception) {
throw new DriverException('Unable to access the response content before visiting a page');
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Custom/BaseUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Behat\Mink\Session;
use Behat\Mink\Tests\Driver\Util\FixturesKernel;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\Client;
use Symfony\Component\HttpKernel\HttpKernelBrowser;

/**
* @group functional
Expand All @@ -15,7 +15,7 @@ class BaseUrlTest extends TestCase
{
public function testBaseUrl()
{
$client = new Client(new FixturesKernel());
$client = new HttpKernelBrowser(new FixturesKernel());
$driver = new BrowserKitDriver($client, 'http://localhost/foo/');
$session = new Session($driver);

Expand Down
52 changes: 25 additions & 27 deletions tests/Custom/ErrorHandlingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace Behat\Mink\Tests\Driver\Custom;

use Behat\Mink\Driver\BrowserKitDriver;
use Behat\Mink\Exception\DriverException;
use PHPUnit\Framework\TestCase;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\BrowserKit\Client;
use Symfony\Component\BrowserKit\Response;

Expand All @@ -14,7 +16,7 @@ class ErrorHandlingTest extends TestCase
*/
private $client;

protected function setUp()
protected function setUp(): void
{
$this->client = new TestClient();
}
Expand All @@ -25,50 +27,49 @@ public function testGetClient()
}

/**
* @expectedException \Behat\Mink\Exception\DriverException
* @expectedExceptionMessage Unable to access the response before visiting a page
*
* Looks like we have to mark these tests as "legacy", otherwise we get deprecation errors.
* Although the deprecations are handled, there's no way to avoid the deprecation message here.
* @group legacy
*/
public function testGetResponseHeaderWithoutVisit()
{
$this->expectException(DriverException::class);
$this->expectExceptionMessage('Unable to access the response before visiting a page');

$this->getDriver()->getResponseHeaders();
}

/**
* @expectedException \Behat\Mink\Exception\DriverException
* @expectedExceptionMessage Unable to access the response content before visiting a page
*
* Looks like we have to mark these tests as "legacy", otherwise we get deprecation errors.
* Although the deprecations are handled, there's no way to avoid the deprecation message here.
* @group legacy
*/
public function testFindWithoutVisit()
{
$this->expectException(DriverException::class);
$this->expectExceptionMessage('Unable to access the response content before visiting a page');

$this->getDriver()->find('//html');
}

/**
* @expectedException \Behat\Mink\Exception\DriverException
* @expectedExceptionMessage Unable to access the request before visiting a page
*
* Looks like we have to mark these tests as "legacy", otherwise we get deprecation errors.
* Although the deprecations are handled, there's no way to avoid the deprecation message here.
* @group legacy
*/
public function testGetCurrentUrlWithoutVisit()
{
$this->expectException(DriverException::class);
$this->expectExceptionMessage('Unable to access the request before visiting a page');

$this->getDriver()->getCurrentUrl();
}

/**
* @expectedException \Behat\Mink\Exception\DriverException
* @expectedExceptionMessage The selected node has an invalid form attribute (foo)
*/
public function testNotMatchingHtml5FormId()
{
$this->expectException(DriverException::class);
$this->expectExceptionMessage('The selected node has an invalid form attribute (foo)');

$html = <<<'HTML'
<html>
<body>
Expand All @@ -87,12 +88,11 @@ public function testNotMatchingHtml5FormId()
$driver->setValue('//input[./@name="test"]', 'bar');
}

/**
* @expectedException \Behat\Mink\Exception\DriverException
* @expectedExceptionMessage The selected node has an invalid form attribute (foo)
*/
public function testInvalidHtml5FormId()
{
$this->expectException(DriverException::class);
$this->expectExceptionMessage('The selected node has an invalid form attribute (foo)');

$html = <<<'HTML'
<html>
<body>
Expand All @@ -112,12 +112,11 @@ public function testInvalidHtml5FormId()
$driver->setValue('//input[./@name="test"]', 'bar');
}

/**
* @expectedException \Behat\Mink\Exception\DriverException
* @expectedExceptionMessage The selected node does not have a form ancestor.
*/
public function testManipulateInputWithoutForm()
{
$this->expectException(DriverException::class);
$this->expectExceptionMessage('The selected node does not have a form ancestor.');

$html = <<<'HTML'
<html>
<body>
Expand All @@ -138,12 +137,11 @@ public function testManipulateInputWithoutForm()
$driver->setValue('//input[./@name="test"]', 'bar');
}

/**
* @expectedException \Behat\Mink\Exception\DriverException
* @expectedExceptionMessage Behat\Mink\Driver\BrowserKitDriver supports clicking on links and submit or reset buttons only. But "div" provided
*/
public function testClickOnUnsupportedElement()
{
$this->expectException(DriverException::class);
$this->expectExceptionMessage('Behat\Mink\Driver\BrowserKitDriver supports clicking on links and submit or reset buttons only. But "div" provided');

$html = <<<'HTML'
<html>
<body>
Expand All @@ -165,7 +163,7 @@ private function getDriver()
}
}

class TestClient extends Client
class TestClient extends AbstractBrowser
{
protected $nextResponse = null;
protected $nextScript = null;
Expand Down

0 comments on commit 0b440bd

Please sign in to comment.