Skip to content

Commit e6d4c86

Browse files
authored
Merge pull request #159 from stof/test_http_client
Add a CI job using the HttpBrowser of BrowserKit and HttpClient
2 parents 0ed1919 + 133dda1 commit e6d4c86

7 files changed

Lines changed: 103 additions & 22 deletions

File tree

.github/workflows/tests.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,34 @@ defaults:
1111
jobs:
1212

1313
tests:
14-
name: Tests (PHP ${{ matrix.php }} ${{ matrix.minimum_stability }}, Symfony LTS ${{ matrix.symfony_lts }})
14+
name: Tests on PHP ${{ matrix.php }} with ${{ matrix.implementation }}${{ matrix.name_suffix }}
1515
runs-on: ubuntu-20.04
1616
strategy:
1717
matrix:
1818
php: [ '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ]
1919
minimum_stability: [ 'stable' ]
2020
symfony_lts: [ false ]
21+
name_suffix: [ '' ]
22+
implementation: [ 'http_kernel' ]
2123
include:
2224
- php: '8.0'
2325
minimum_stability: dev
26+
implementation: 'http_kernel'
27+
name_suffix: ' and dev deps'
2428
- php: '7.4'
2529
minimum_stability: dev
30+
implementation: 'http_kernel'
31+
name_suffix: ' and dev deps'
2632
- php: '7.2'
2733
symfony_lts: '^2'
34+
implementation: 'http_kernel'
35+
name_suffix: ' and Symfony 2'
2836
- php: '7.2'
2937
symfony_lts: '^3'
38+
implementation: 'http_kernel'
39+
name_suffix: ' and Symfony 3'
40+
- php: '8.0'
41+
implementation: http_client
3042
fail-fast: false
3143

3244
env:
@@ -60,14 +72,36 @@ jobs:
6072
run: |
6173
composer require --no-update --dev symfony/error-handler "^4.4 || ^5.0"
6274
75+
- name: Configure for HttpClient
76+
if: "${{ matrix.implementation == 'http_client'}}"
77+
run: composer require --no-update --dev symfony/http-client:^4.4 symfony/mime:^4.4
78+
6379
- name: Install dependencies
6480
run: |
6581
composer update --no-interaction --prefer-dist
6682
83+
- name: Setup Mink test server
84+
if: "${{ matrix.implementation == 'http_client'}}"
85+
run: |
86+
mkdir ./logs
87+
./vendor/bin/mink-test-server &> ./logs/mink-test-server.log &
88+
89+
- name: Wait for browser & PHP to start
90+
if: "${{ matrix.implementation == 'http_client'}}"
91+
run: |
92+
while ! nc -z localhost 8002 </dev/null; do echo Waiting for PHP server to start...; sleep 1; done
93+
94+
6795
- name: Run tests
96+
if: "${{ matrix.implementation == 'http_kernel'}}"
6897
run: |
6998
vendor/bin/phpunit -v --coverage-clover=coverage.clover
7099
100+
- name: Run tests
101+
if: "${{ matrix.implementation == 'http_client'}}"
102+
run: |
103+
vendor/bin/phpunit -c phpunit.http_client.xml -v --coverage-clover=coverage.clover
104+
71105
- name: Upload code coverage
72106
if: "${{ matrix.php > '5.4' && matrix.symfony_lts == false }}"
73107
run: |

phpunit.http_client.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit colors="true" bootstrap="vendor/autoload.php">
4+
<php>
5+
<var name="driver_config_factory" value="Behat\Mink\Tests\Driver\HttpClientBrowserKitConfig::getInstance" />
6+
</php>
7+
8+
<testsuites>
9+
<testsuite name="Driver test suite">
10+
<directory>tests</directory>
11+
<directory>vendor/mink/driver-testsuite/tests/Basic</directory>
12+
<directory>vendor/mink/driver-testsuite/tests/Form</directory>
13+
</testsuite>
14+
</testsuites>
15+
16+
<filter>
17+
<whitelist>
18+
<directory>./src</directory>
19+
</whitelist>
20+
</filter>
21+
</phpunit>

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<phpunit colors="true" bootstrap="vendor/autoload.php">
44
<php>
5-
<var name="driver_config_factory" value="Behat\Mink\Tests\Driver\BrowserKitConfig::getInstance" />
5+
<var name="driver_config_factory" value="Behat\Mink\Tests\Driver\HttpKernelBrowserKitConfig::getInstance" />
66
</php>
77

88
<testsuites>

src/BrowserKitDriver.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,14 @@ public function setBasicAuth($user, $password)
200200
{
201201
if (false === $user) {
202202
unset($this->serverParameters['PHP_AUTH_USER'], $this->serverParameters['PHP_AUTH_PW']);
203+
unset($this->serverParameters['HTTP_AUTHORIZATION']);
203204

204205
return;
205206
}
206207

207208
$this->serverParameters['PHP_AUTH_USER'] = $user;
208209
$this->serverParameters['PHP_AUTH_PW'] = $password;
210+
$this->serverParameters['HTTP_AUTHORIZATION'] = 'Basic ' . base64_encode($user . ':' . $password);
209211
}
210212

211213
/**
Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,11 @@
66
use Behat\Mink\Tests\Driver\Util\FixturesKernel;
77
use Symfony\Component\HttpKernel\Client;
88

9-
class BrowserKitConfig extends AbstractConfig
9+
abstract class AbstractBrowserKitConfig extends AbstractConfig
1010
{
1111
public static function getInstance()
1212
{
13-
return new self();
14-
}
15-
16-
/**
17-
* {@inheritdoc}
18-
*/
19-
public function createDriver()
20-
{
21-
$client = new Client(new FixturesKernel());
22-
23-
return new BrowserKitDriver($client);
24-
}
25-
26-
/**
27-
* {@inheritdoc}
28-
*/
29-
public function getWebFixturesUrl()
30-
{
31-
return 'http://localhost';
13+
return new static();
3214
}
3315

3416
protected function supportsJs()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Behat\Mink\Tests\Driver;
4+
5+
use Behat\Mink\Driver\BrowserKitDriver;
6+
use Symfony\Component\BrowserKit\HttpBrowser;
7+
8+
class HttpClientBrowserKitConfig extends AbstractBrowserKitConfig
9+
{
10+
public function createDriver()
11+
{
12+
return new BrowserKitDriver(new HttpBrowser());
13+
}
14+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Behat\Mink\Tests\Driver;
4+
5+
use Behat\Mink\Driver\BrowserKitDriver;
6+
use Behat\Mink\Tests\Driver\Util\FixturesKernel;
7+
use Symfony\Component\HttpKernel\Client;
8+
9+
class HttpKernelBrowserKitConfig extends AbstractBrowserKitConfig
10+
{
11+
/**
12+
* {@inheritdoc}
13+
*/
14+
public function createDriver()
15+
{
16+
$client = new Client(new FixturesKernel());
17+
18+
return new BrowserKitDriver($client);
19+
}
20+
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
public function getWebFixturesUrl()
25+
{
26+
return 'http://localhost';
27+
}
28+
}

0 commit comments

Comments
 (0)