diff --git a/.gitignore b/.gitignore index 3ccd9ee..64c30a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ vendor composer.lock /phpunit.xml +/.phpunit.result.cache diff --git a/.travis.yml b/.travis.yml index c87c6e0..f903387 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/README.md b/README.md index f8c907b..a361ada 100644 --- a/README.md +++ b/README.md @@ -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 - 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. diff --git a/composer.json b/composer.json index dd8bc63..9a850ca 100644 --- a/composer.json +++ b/composer.json @@ -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/", @@ -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": { diff --git a/src/BrowserKitDriver.php b/src/BrowserKitDriver.php index 21b7936..2036124 100644 --- a/src/BrowserKitDriver.php +++ b/src/BrowserKitDriver.php @@ -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; @@ -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. @@ -46,15 +46,15 @@ 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)); } } @@ -62,7 +62,7 @@ public function __construct(Client $client, $baseUrl = null) /** * Returns BrowserKit HTTP client instance. * - * @return Client + * @return AbstractBrowser */ public function getClient() { @@ -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'); } diff --git a/tests/Custom/BaseUrlTest.php b/tests/Custom/BaseUrlTest.php index 8d4897d..b8e8178 100644 --- a/tests/Custom/BaseUrlTest.php +++ b/tests/Custom/BaseUrlTest.php @@ -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 @@ -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); diff --git a/tests/Custom/ErrorHandlingTest.php b/tests/Custom/ErrorHandlingTest.php index f53eb59..b1816d3 100644 --- a/tests/Custom/ErrorHandlingTest.php +++ b/tests/Custom/ErrorHandlingTest.php @@ -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; @@ -14,7 +16,7 @@ class ErrorHandlingTest extends TestCase */ private $client; - protected function setUp() + protected function setUp(): void { $this->client = new TestClient(); } @@ -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' @@ -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' @@ -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' @@ -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' @@ -165,7 +163,7 @@ private function getDriver() } } -class TestClient extends Client +class TestClient extends AbstractBrowser { protected $nextResponse = null; protected $nextScript = null;