diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2afec8ac..d76306f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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: @@ -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: @@ -54,7 +59,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') }} @@ -62,7 +67,7 @@ jobs: - 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 }} @@ -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: @@ -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: @@ -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') }} @@ -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 @@ -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 }} diff --git a/behat.yml.dist b/behat.yml.dist index cce96aee..ff9a80e1 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -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' diff --git a/src/Context/BrowserContext.php b/src/Context/BrowserContext.php index 930c7b16..804f86c9 100644 --- a/src/Context/BrowserContext.php +++ b/src/Context/BrowserContext.php @@ -25,7 +25,9 @@ public function __construct($timeout = 1) */ public function closeBrowser(): void { - $this->getSession()->stop(); + if ($this->getMink()->isSessionStarted()) { + $this->getSession()->stop(); + } } /** diff --git a/src/Context/JsonContext.php b/src/Context/JsonContext.php index 1ec593dd..f9a13b56 100644 --- a/src/Context/JsonContext.php +++ b/src/Context/JsonContext.php @@ -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'); } /** @@ -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'); } /** @@ -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'); } /** @@ -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() diff --git a/src/Context/XmlContext.php b/src/Context/XmlContext.php index 4ce049a3..1fa4ae8d 100644 --- a/src/Context/XmlContext.php +++ b/src/Context/XmlContext.php @@ -25,7 +25,7 @@ public function theResponseShouldBeInXml(): void public function theResponseShouldNotBeInXml(): void { $this->not( - [$this, 'theResponseShouldBeInXml'], + fn () => $this->theResponseShouldBeInXml(), 'The response is in XML' ); } @@ -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'"); } /** diff --git a/src/HttpCall/HttpCallListener.php b/src/HttpCall/HttpCallListener.php index aa293ab9..24d51441 100644 --- a/src/HttpCall/HttpCallListener.php +++ b/src/HttpCall/HttpCallListener.php @@ -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->httpCallResultPool->store( + new HttpCallResult($this->mink->getSession()->getPage()->getContent()) + ); + } } catch (\LogicException $e) { // Mink has no response } catch (\Behat\Mink\Exception\DriverException $e) { diff --git a/tests/features/browser.feature b/tests/features/browser.feature index e9939f5d..b95375d3 100644 --- a/tests/features/browser.feature +++ b/tests/features/browser.feature @@ -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 diff --git a/tests/features/fr/browser.feature b/tests/features/fr/browser.feature index 6885ee95..ea1f9b15 100644 --- a/tests/features/fr/browser.feature +++ b/tests/features/fr/browser.feature @@ -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 diff --git a/tests/features/fr/json.feature b/tests/features/fr/json.feature index 8bb92bba..c62baa76 100644 --- a/tests/features/fr/json.feature +++ b/tests/features/fr/json.feature @@ -1,4 +1,5 @@ #language: fr +@json Fonctionnalité: Scénario: diff --git a/tests/features/fr/rest.feature b/tests/features/fr/rest.feature index 2bd07d6f..5e245fc0 100644 --- a/tests/features/fr/rest.feature +++ b/tests/features/fr/rest.feature @@ -1,4 +1,5 @@ #language: fr +@rest Fonctionnalité: Scénario: diff --git a/tests/features/fr/table.feature b/tests/features/fr/table.feature index 3f87b16b..98f3defd 100644 --- a/tests/features/fr/table.feature +++ b/tests/features/fr/table.feature @@ -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" diff --git a/tests/features/fr/xml.feature b/tests/features/fr/xml.feature index afba5809..a2ba0654 100644 --- a/tests/features/fr/xml.feature +++ b/tests/features/fr/xml.feature @@ -1,4 +1,5 @@ #language: fr +@xml Fonctionnalité: Contexte: diff --git a/tests/features/ja/browser.feature b/tests/features/ja/browser.feature index 3ed9428d..4dad9445 100644 --- a/tests/features/ja/browser.feature +++ b/tests/features/ja/browser.feature @@ -11,6 +11,7 @@ 前提 "/index.html" を表示している ならば 画面に "Congratulations, you've correctly set up your apache environment." と表示されていること + @statusCode シナリオ: Basic authentication 前提 "/browser/auth.php" を表示している ならば レスポンスコードが 401 であること diff --git a/tests/features/ja/table.feature b/tests/features/ja/table.feature index e0cdb5c3..6a5e1651 100644 --- a/tests/features/ja/table.feature +++ b/tests/features/ja/table.feature @@ -9,12 +9,13 @@ シナリオ: Testing columns 前提 "/table/index.html" を表示している - ならば テーブル"table"が2個のカラムを持つこと + ならば テーブル"table"が3個のカラムを持つこと かつ テーブル"table"のカラムスキーマが下記と一致すること: | columns | | Lorem | | Ipsum | + | Integer | # ならば ブレークポイントを設置する シナリオ: Testing rows diff --git a/tests/features/json.feature b/tests/features/json.feature index 3521f60c..df6685c3 100644 --- a/tests/features/json.feature +++ b/tests/features/json.feature @@ -1,3 +1,4 @@ +@json Feature: Testing JSONContext Scenario: Am I a JSON ? diff --git a/tests/features/pt/browser.feature b/tests/features/pt/browser.feature index dfc51e3b..187e1f3d 100644 --- a/tests/features/pt/browser.feature +++ b/tests/features/pt/browser.feature @@ -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 @@ -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" \ No newline at end of file + Então Eu salvo o valor de "today" no parâmetro "today" diff --git a/tests/features/pt/json.feature b/tests/features/pt/json.feature index d6d1b90b..52a85a61 100644 --- a/tests/features/pt/json.feature +++ b/tests/features/pt/json.feature @@ -1,4 +1,5 @@ #language: pt +@json Funcionalidade: Testando o JSONContext Cenário: Eu sou um JSON? diff --git a/tests/features/pt/rest.feature b/tests/features/pt/rest.feature index 2cb3c21f..28a2f065 100644 --- a/tests/features/pt/rest.feature +++ b/tests/features/pt/rest.feature @@ -1,4 +1,5 @@ #language: pt +@rest Funcionalidade: Testando o RESTContext Cenário: Testando headers diff --git a/tests/features/pt/table.feature b/tests/features/pt/table.feature index 3b51baa4..1ce36570 100644 --- a/tests/features/pt/table.feature +++ b/tests/features/pt/table.feature @@ -8,12 +8,13 @@ Funcionalidade: Table Cenário: Testando colunas Quando estou em "/table/index.html" - Então devo ver 2 colunas na tabela "table" + Então devo ver 3 colunas na tabela "table" E as colunas da tabela "table" devem ser: | columns | | Lorem | | Ipsum | + | Integer | Cenário: Testando linhas Quando estou em "/table/index.html" diff --git a/tests/features/pt/xml.feature b/tests/features/pt/xml.feature index e378c491..2178a6cb 100644 --- a/tests/features/pt/xml.feature +++ b/tests/features/pt/xml.feature @@ -1,4 +1,5 @@ #language: pt +@xml Funcionalidade: Testando o XmlContext Contexto: diff --git a/tests/features/rest.feature b/tests/features/rest.feature index 3e45e6f8..0b0a93c2 100644 --- a/tests/features/rest.feature +++ b/tests/features/rest.feature @@ -1,3 +1,4 @@ +@rest Feature: Testing RESTContext Scenario: Testing headers diff --git a/tests/features/ru/browser.feature b/tests/features/ru/browser.feature index c2260c4c..d59e6b80 100644 --- a/tests/features/ru/browser.feature +++ b/tests/features/ru/browser.feature @@ -9,6 +9,7 @@ Пусть я на странице "/index.html" Тогда я должен видеть "Congratulations, you've correctly set up your apache environment." + @statusCode Сценарий: Basic-аутентификация Пусть я на странице "/browser/auth.php" Тогда код ответа сервера должен быть 401 diff --git a/tests/features/ru/json.feature b/tests/features/ru/json.feature index fa138626..9c46150a 100644 --- a/tests/features/ru/json.feature +++ b/tests/features/ru/json.feature @@ -1,4 +1,5 @@ #language: ru +@json Функционал: Тестирование JSONContext Сценарий: Я JSON ? diff --git a/tests/features/ru/rest.feature b/tests/features/ru/rest.feature index 1518ffa6..548c1e05 100644 --- a/tests/features/ru/rest.feature +++ b/tests/features/ru/rest.feature @@ -1,4 +1,5 @@ #language: ru +@rest Функционал: Тестирование RESTContext Сценарий: Тестирование заголовков diff --git a/tests/features/ru/table.feature b/tests/features/ru/table.feature index 0e721e19..51c5a1df 100644 --- a/tests/features/ru/table.feature +++ b/tests/features/ru/table.feature @@ -8,12 +8,13 @@ Сценарий: Тестирование столбцов Пусть я на странице "/table/index.html" - Тогда я должен видеть 2 столбца в таблице "table" + Тогда я должен видеть 3 столбца в таблице "table" И схема столбцов таблицы "table" должна соответствовать: | columns | | Lorem | | Ipsum | + | Integer | Сценарий: Тестирование строк Пусть я на странице "/table/index.html" diff --git a/tests/features/ru/xml.feature b/tests/features/ru/xml.feature index 3db87118..e8212954 100644 --- a/tests/features/ru/xml.feature +++ b/tests/features/ru/xml.feature @@ -1,4 +1,5 @@ #language: ru +@xml Функционал: Тестирование XmlContext Контекст: diff --git a/tests/features/xml.feature b/tests/features/xml.feature index bec80de9..24645c2d 100644 --- a/tests/features/xml.feature +++ b/tests/features/xml.feature @@ -1,3 +1,4 @@ +@xml Feature: Testing XmlContext Background: