Skip to content

Commit

Permalink
Fix CI (#19)
Browse files Browse the repository at this point in the history
* fix(ci): use Selenium from ubuntu-22.04

* try

* back to https://github.com/Jean-Beru/soyuka-contexts/actions/runs/4102075581/jobs/7074593908

* cleanup

* java

* fix tests

* fix w3c

* use old chromedriver

* fix Behat

* skip status code for Selenium

* debug

* wait for selenium
  • Loading branch information
Jean-Beru authored Mar 29, 2023
1 parent 2eb5e5e commit 8215019
Show file tree
Hide file tree
Showing 27 changed files with 93 additions and 59 deletions.
54 changes: 29 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ name: CI

on:
push:
branches:
- 'main'
pull_request:
branches:
- 'main'

env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -17,7 +22,7 @@ jobs:
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -41,7 +46,7 @@ jobs:
APP_DEBUG: '1' # https://github.com/phpstan/phpstan-symfony/issues/37
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -54,15 +59,15 @@ jobs:
id: composercache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Update project dependencies
run: composer update --no-interaction --no-progress --ansi
- name: Cache PHPStan results
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: /tmp/phpstan
key: phpstan-php${{ matrix.php }}-${{ github.sha }}
Expand All @@ -74,7 +79,7 @@ jobs:
run: phpstan analyse --no-interaction --no-progress --no-interaction --ansi

atoum:
name: Atoum (PHP ${{ matrix.php }})
name: Atoum
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -84,7 +89,7 @@ jobs:
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -97,7 +102,7 @@ jobs:
id: composercache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand All @@ -107,23 +112,26 @@ jobs:
- name: Run tests
run: ./bin/atoum

# See https://github.com/SeleniumHQ/selenium/issues/9044
# See
behat:
runs-on: ubuntu-latest
name: Behat
runs-on: ubuntu-22.04
strategy:
matrix:
php:
- '8.1'
profile:
- 'default'
- 'symfony2'
fail-fast: false
env:
DISPLAY: ':99'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: nanasess/setup-chromedriver@v1
- name: Fix Java version # Use JDK8 due to https://github.com/SeleniumHQ/selenium/issues/4964
run: |
sudo apt-get install openjdk-8-jre
sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
- name: Setup
run: |
export DISPLAY=:99
chromedriver --url-base=/wd/hub &
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # optional
- name: Setup PHP
Expand All @@ -134,24 +142,20 @@ jobs:
extensions: intl, bcmath, curl, openssl, mbstring
coverage: pcov
ini-values: memory_limit=-1
- name: Run selenium
run: java -jar $SELENIUM_JAR_PATH standalone &
- name: Run php fixtures server
run: php -S localhost:8080 -t tests/fixtures/www &> ./fixtures.log &
- name: Get composer cache directory
id: composercache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Update project dependencies
run: composer update --no-interaction --no-progress --ansi
- name: Run selenium
run: |
wget "https://selenium-release.storage.googleapis.com/3.9/selenium-server-standalone-3.9.1.jar" -O selenium.jar
java -jar selenium.jar &> /dev/null &
- name: Run php fixtures server
run: php -S localhost:8080 -t tests/fixtures/www &> /dev/null &
- name: Run behat tests (default)
run: ./bin/behat -fprogress --tags="~@user" --no-interaction --profile=default
- name: Run behat tests (symfony 2)
run: ./bin/behat -fprogress --tags="~@user" --no-interaction --profile=symfony2
- name: Run behat tests
run: ./bin/behat -fprogress --no-interaction --profile=${{ matrix.profile }}
40 changes: 24 additions & 16 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,46 @@ default:
- behatch:context:browser:
timeout: 1
- behatch:context:debug:
screenshotDir: "."
screenshotDir: '.'
- behatch:context:json:
evaluationMode: javascript
- behatch:context:rest
- behatch:context:system:
root: "."
root: '.'
- behatch:context:table
- behatch:context:xml
filters:
tags: '~@user'
extensions:
Behat\MinkExtension:
base_url: 'http://localhost:8080'
files_path: 'tests/fixtures/files'
goutte: ~
selenium2:
capabilities:
chrome:
switches:
- "--headless"
- "--disable-gpu"
- "--no-sandbox"
extra_capabilities:
"goog:chromeOptions":
w3c: false
files_path: '%paths.base%/tests/fixtures/files'
browser_name: 'chrome'
sessions:
default:
goutte: ~
symfony2:
goutte: ~
selenium2:
capabilities:
browser: 'chrome'
browserName: 'chrome'
chrome:
switches:
- '--headless'
- '--disable-gpu'
- '--no-sandbox'
extra_capabilities:
"goog:chromeOptions":
w3c: false
Behatch\Extension: ~

symfony2:
suites:
default:
filters:
# Ignore @statusCode and @rest tags because Selenium2Driver does not support headers or status code (https://github.com/php-webdriver/php-webdriver/issues/811)
# Ignore @json and @xml tags because response is wrapped inside html tags
tags: '~@user&&~@statusCode&&~@rest&&~@json&&~@xml'
extensions:
Behat\MinkExtension:
default_session: symfony2
default_session: 'symfony2'
4 changes: 3 additions & 1 deletion src/Context/BrowserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public function __construct($timeout = 1)
*/
public function closeBrowser(): void
{
$this->getSession()->stop();
if ($this->getMink()->isSessionStarted()) {
$this->getSession()->stop();
}
}

/**
Expand Down
11 changes: 4 additions & 7 deletions src/Context/JsonContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ public function theResponseShouldBeInJson(): void
*/
public function theResponseShouldNotBeInJson(): void
{
$this->not(
[$this, 'theResponseShouldBeInJson'],
'The response is in JSON'
);
$this->not(fn () => $this->theResponseShouldBeInJson(), 'The response is in JSON');
}

/**
Expand Down Expand Up @@ -311,7 +308,7 @@ public function theJsonShouldBeValidAccordingToThisSchema(PyStringNode $schema):
*/
public function theJsonShouldBeInvalidAccordingToThisSchema(PyStringNode $schema): void
{
$this->not([$this, 'theJsonShouldBeValidAccordingToThisSchema'], 'Expected to receive invalid json, got valid one');
$this->not(fn () => $this->theJsonShouldBeValidAccordingToThisSchema($schema), 'Expected to receive invalid json, got valid one');
}

/**
Expand All @@ -337,7 +334,7 @@ public function theJsonShouldBeInvalidAccordingToTheSchema($filename): void
{
$this->checkSchemaFile($filename);

$this->not([$this, 'theJsonShouldBeValidAccordingToTheSchema'], 'The schema was valid');
$this->not(fn () => $this->theJsonShouldBeValidAccordingToTheSchema($filename), 'The schema was valid');
}

/**
Expand Down Expand Up @@ -398,7 +395,7 @@ public function theJsonShouldBeValidAccordingToTheSwaggerSchema($dumpPath, $sche
*/
public function theJsonShouldNotBeValidAccordingToTheSwaggerSchema($dumpPath, $schemaName): void
{
$this->not([$this, 'theJsonShouldBeValidAccordingToTheSwaggerSchema'], 'JSON Schema matches but it should not');
$this->not(fn () => $this->theJsonShouldBeValidAccordingToTheSwaggerSchema($dumpPath, $schemaName), 'JSON Schema matches but it should not');
}

protected function getJson()
Expand Down
4 changes: 2 additions & 2 deletions src/Context/XmlContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function theResponseShouldBeInXml(): void
public function theResponseShouldNotBeInXml(): void
{
$this->not(
[$this, 'theResponseShouldBeInXml'],
fn () => $this->theResponseShouldBeInXml(),
'The response is in XML'
);
}
Expand Down Expand Up @@ -88,7 +88,7 @@ public function theXmlElementShouldBeEqualTo($element, $text): void
*/
public function theXmlElementShouldNotBeEqualTo($element, $text): void
{
$this->not([$this, 'theXmlElementShouldBeEqualTo'], "The element '$element' value is not '$text'");
$this->not(fn () => $this->theXmlElementShouldBeEqualTo($element, $text), "The element '$element' value is not '$text'");
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/HttpCall/HttpCallListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ public function afterStep(AfterStepTested $event)
// For now to avoid modification on MinkContext
// We add fallback on Mink
try {
$this->httpCallResultPool->store(
new HttpCallResult($this->mink->getSession()->getPage()->getContent())
);
if ($this->mink->getSession()->isStarted()) {

This comment has been minimized.

Copy link
@develth

develth Apr 21, 2023

@soyuka This causes a issue i have on my setup:

Fatal error: Call to a member function getValue() on null (Behat\Testwork\Call\Exception\FatalThrowableError)
Because getResult is null in JsonContext::getJson()

This comment has been minimized.

Copy link
@NicoHaase

NicoHaase Jun 21, 2023

@soyuka same problem here - $this->mink->getSession()->isStarted() returns false and the HTTP response is no longer stored :(

This comment has been minimized.

Copy link
@walva

walva Dec 20, 2023

Same here.

$this->httpCallResultPool->store(
new HttpCallResult($this->mink->getSession()->getPage()->getContent())
);
}
} catch (\LogicException $e) {
// Mink has no response
} catch (\Behat\Mink\Exception\DriverException $e) {
Expand Down
1 change: 1 addition & 0 deletions tests/features/browser.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Feature: Browser Feature
Given I am on "/index.html"
Then I should see "Congratulations, you've correctly set up your apache environment."

@statusCode
Scenario: Basic authentication
Given I am on "/browser/auth.php"
Then the response status code should be 401
Expand Down
1 change: 1 addition & 0 deletions tests/features/fr/browser.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Fonctionnalité:
Étant donné je suis sur "/index.html"
Alors je devrais voir "Congratulations, you've correctly set up your apache environment."

@statusCode
Scénario:
Étant donnée je suis sur "/browser/auth.php"
Alors le code de status de la réponse devrait être 401
Expand Down
1 change: 1 addition & 0 deletions tests/features/fr/json.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#language: fr
@json
Fonctionnalité:

Scénario:
Expand Down
1 change: 1 addition & 0 deletions tests/features/fr/rest.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#language: fr
@rest
Fonctionnalité:

Scénario:
Expand Down
3 changes: 2 additions & 1 deletion tests/features/fr/table.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ Fonctionnalité:
Scénario:
Étant donné je suis sur "/table/index.html"

Alors je devrais voir 2 colonnes dans le tableau "table"
Alors je devrais voir 3 colonnes dans le tableau "table"

Et le schéma des colonnes du tableau "table" devrait correspondre à :
| columns |
| Lorem |
| Ipsum |
| Integer |

Scénario:
Étant donné je suis sur "/table/index.html"
Expand Down
1 change: 1 addition & 0 deletions tests/features/fr/xml.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#language: fr
@xml
Fonctionnalité:

Contexte:
Expand Down
1 change: 1 addition & 0 deletions tests/features/ja/browser.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
前提 "/index.html" を表示している
ならば 画面に "Congratulations, you've correctly set up your apache environment." と表示されていること

@statusCode
シナリオ: Basic authentication
前提 "/browser/auth.php" を表示している
ならば レスポンスコードが 401 であること
Expand Down
3 changes: 2 additions & 1 deletion tests/features/ja/table.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
シナリオ: Testing columns
前提 "/table/index.html" を表示している

ならば テーブル"table"が2個のカラムを持つこと
ならば テーブル"table"が3個のカラムを持つこと

かつ テーブル"table"のカラムスキーマが下記と一致すること:
| columns |
| Lorem |
| Ipsum |
| Integer |
# ならば ブレークポイントを設置する

シナリオ: Testing rows
Expand Down
1 change: 1 addition & 0 deletions tests/features/json.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@json
Feature: Testing JSONContext

Scenario: Am I a JSON ?
Expand Down
3 changes: 2 additions & 1 deletion tests/features/pt/browser.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Funcionalidade: Browser
Quando estou em "/index.html"
Então devo ver "Congratulations, you've correctly set up your apache environment."

@statusCode
Cenário: Basic Authentication
Quando Eu estou em "/browser/auth.php"
Então o código de status da resposta deve ser 401
Expand Down Expand Up @@ -79,4 +80,4 @@ Funcionalidade: Browser

Cenário:
Quando Eu estou em "/browser/elements.html"
Então Eu salvo o valor de "today" no parâmetro "today"
Então Eu salvo o valor de "today" no parâmetro "today"
1 change: 1 addition & 0 deletions tests/features/pt/json.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#language: pt
@json
Funcionalidade: Testando o JSONContext

Cenário: Eu sou um JSON?
Expand Down
1 change: 1 addition & 0 deletions tests/features/pt/rest.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#language: pt
@rest
Funcionalidade: Testando o RESTContext

Cenário: Testando headers
Expand Down
Loading

0 comments on commit 8215019

Please sign in to comment.