Merge pull request #50 from FriendsOfBehat/ci/modernize-php-symfony-versions

Modernize PHP/Symfony requirements, add Symfony 8 + Behat 4 CI support
This commit is contained in:
Kamil Kokot
2026-06-12 17:21:00 +02:00
committed by GitHub
10 changed files with 150 additions and 376 deletions

3
.github/workflows/lock-behat-version.sh vendored Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
jq --indent 4 --arg version "$VERSION" '.require |= with_entries(.key as $k | if ($k == "behat/behat") then .value = $version else . end)' < composer.json > composer.json.tmp && mv composer.json.tmp composer.json

4
.github/workflows/lock-symfony-version.sh vendored Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
jq --indent 4 --arg version "$VERSION" '.require |= with_entries(.key as $k | if ($k | test("^symfony/")) then .value = $version else . end)' < composer.json > composer.json.tmp && mv composer.json.tmp composer.json
jq --indent 4 --arg version "$VERSION" '."require-dev" |= with_entries(.key as $k | if ($k | test("^symfony/")) then .value = $version else . end)' < composer.json > composer.json.tmp && mv composer.json.tmp composer.json

View File

@@ -2,36 +2,46 @@ name: Test
on: on:
push: push:
branches:
- master
pull_request: pull_request:
types: [opened, synchronize, edited, reopened] schedule:
-
cron: "0 1 * * 6" # Run at 1am every Saturday
jobs: jobs:
test: test:
name: PHP ${{ matrix.php-version }} + Symfony ${{ matrix.symfony-version }} name: PHP ${{ matrix.php-version }} + Symfony ${{ matrix.symfony-version }} + Behat ${{ matrix.behat-version }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
continue-on-error: false continue-on-error: false
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
php-version: php-version:
- '7.4' - '8.3'
- '8.0' - '8.4'
- '8.1' - '8.5'
symfony-version: symfony-version:
- '4.4.*' - '7.4.*'
- '5.4.*' - '8.0.*'
- '6.4.*' - '8.1.*'
behat-version:
- stable
- 4.x-dev
exclude: exclude:
- php-version: '7.4' # Symfony 8.x requires PHP >= 8.4
symfony-version: '6.4.*' - php-version: '8.3'
- php-version: '8.0' symfony-version: '8.0.*'
symfony-version: '6.4.*' - php-version: '8.3'
include: symfony-version: '8.1.*'
- php-version: '8.2' # Behat 3.31 (stable) cannot install with Symfony 8.x
symfony-version: '7.0.*' - behat-version: stable
symfony-version: '8.0.*'
- behat-version: stable
symfony-version: '8.1.*'
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v6 uses: actions/checkout@v5
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2
@@ -42,10 +52,17 @@ jobs:
tools: composer:v2 tools: composer:v2
- name: Validate composer.json - name: Validate composer.json
run: composer validate --no-check-lock run: composer validate --strict
- name: Configure Symfony version - name: Lock Symfony version
run: composer require --no-update "symfony/config:${{ matrix.symfony-version }}" "symfony/dependency-injection:${{ matrix.symfony-version }}" run: VERSION=${{ matrix.symfony-version }} .github/workflows/lock-symfony-version.sh
- name: Require behat 4.x
if: matrix.behat-version == '4.x-dev'
run: |
VERSION="4.x-dev as 3.31.0" .github/workflows/lock-behat-version.sh
composer config minimum-stability dev
composer config prefer-stable true
- name: Install dependencies - name: Install dependencies
run: composer install --prefer-dist --no-progress run: composer install --prefer-dist --no-progress
@@ -54,4 +71,4 @@ jobs:
run: vendor/bin/phpspec run -f pretty run: vendor/bin/phpspec run -f pretty
- name: Behat - name: Behat
run: vendor/bin/behat -fprogress --strict run: vendor/bin/behat --config behat.dist.php -fprogress --strict

28
behat.dist.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
use Behat\Config\Config;
use Behat\Config\Extension;
use Behat\Config\Profile;
use Behat\Config\Suite;
return (new Config())
->withProfile(
(new Profile('default'))
->withSuite(
(new Suite('default'))
->withPaths('%paths.base%/features')
->withContexts(\Behat\MinkExtension\Context\MinkContext::class)
)
->withExtension(
new Extension(\Behat\MinkExtension\ServiceContainer\MinkExtension::class, [
'base_url' => 'http://en.wikipedia.org/',
'sessions' => [
'default' => [
'browserkit_http' => null,
],
],
])
)
);

View File

@@ -1,11 +0,0 @@
default:
suites:
default:
path: "%paths.base%/features"
contexts: [Behat\MinkExtension\Context\MinkContext]
extensions:
Behat\MinkExtension:
base_url: http://en.wikipedia.org/
sessions:
default:
goutte: ~

View File

@@ -21,16 +21,16 @@
], ],
"homepage": "https://github.com/FriendsOfBehat/MinkExtension#readme", "homepage": "https://github.com/FriendsOfBehat/MinkExtension#readme",
"require": { "require": {
"php": "^7.4 || ^8", "php": "^8.3",
"behat/behat": "^3.0.5", "behat/behat": "^3.31",
"behat/mink": "^1.5", "behat/mink": "^1.5",
"symfony/config": "^4.4 || ^5.0 || ^6.0 || ^7.0", "symfony/config": "^7.4 || ^8.0"
"symfony/deprecation-contracts": "^1.0 || ^2.0 || ^3.0"
}, },
"require-dev": { "require-dev": {
"behat/mink-goutte-driver": "^1.1 || ^2.0", "behat/mink-browserkit-driver": "^2.0",
"phpspec/phpspec": "^6.0 || ^7.0 || 7.1.x-dev", "phpspec/phpspec": "^8.0",
"mink/webdriver-classic-driver": "^1.0@dev" "symfony/browser-kit": "^7.4 || ^8.0",
"symfony/http-client": "^7.4 || ^8.0"
}, },
"replace": { "replace": {
"behat/mink-extension": "self.version" "behat/mink-extension": "self.version"
@@ -44,5 +44,11 @@
"branch-alias": { "branch-alias": {
"dev-master": "2.x-dev" "dev-master": "2.x-dev"
} }
},
"scripts": {
"test": [
"vendor/bin/phpspec run -f pretty",
"vendor/bin/behat --config behat.dist.php -fprogress --strict"
]
} }
} }

View File

@@ -24,27 +24,13 @@ use Behat\MinkExtension\Context\MinkAwareContext;
*/ */
class MinkAwareInitializer implements ContextInitializer class MinkAwareInitializer implements ContextInitializer
{ {
private $mink; public function __construct(
private $parameters; private readonly Mink $mink,
private readonly array $parameters,
/** ) {
* Initializes initializer.
*
* @param Mink $mink
* @param array $parameters
*/
public function __construct(Mink $mink, array $parameters)
{
$this->mink = $mink;
$this->parameters = $parameters;
} }
/** public function initializeContext(Context $context): void
* Initializes provided context.
*
* @param Context $context
*/
public function initializeContext(Context $context)
{ {
if (!$context instanceof MinkAwareContext) { if (!$context instanceof MinkAwareContext) {
return; return;

View File

@@ -21,103 +21,55 @@ use Behat\Gherkin\Node\TableNode;
*/ */
class MinkContext extends RawMinkContext implements TranslatableContext class MinkContext extends RawMinkContext implements TranslatableContext
{ {
/** #[\Behat\Step\Given('/^(?:|I )am on (?:|the )homepage$/')]
* Opens homepage #[\Behat\Step\When('/^(?:|I )go to (?:|the )homepage$/')]
* Example: Given I am on "/"
* Example: When I go to "/"
* Example: And I go to "/"
*
* @Given /^(?:|I )am on (?:|the )homepage$/
* @When /^(?:|I )go to (?:|the )homepage$/
*/
public function iAmOnHomepage() public function iAmOnHomepage()
{ {
$this->visitPath('/'); $this->visitPath('/');
} }
/** #[\Behat\Step\Given('/^(?:|I )am on "(?P<page>[^"]+)"$/')]
* Opens specified page #[\Behat\Step\When('/^(?:|I )go to "(?P<page>[^"]+)"$/')]
* Example: Given I am on "http://batman.com"
* Example: And I am on "/articles/isBatmanBruceWayne"
* Example: When I go to "/articles/isBatmanBruceWayne"
*
* @Given /^(?:|I )am on "(?P<page>[^"]+)"$/
* @When /^(?:|I )go to "(?P<page>[^"]+)"$/
*/
public function visit($page) public function visit($page)
{ {
$this->visitPath($page); $this->visitPath($page);
} }
/** #[\Behat\Step\When('/^(?:|I )reload the page$/')]
* Reloads current page
* Example: When I reload the page
* Example: And I reload the page
*
* @When /^(?:|I )reload the page$/
*/
public function reload() public function reload()
{ {
$this->getSession()->reload(); $this->getSession()->reload();
} }
/** #[\Behat\Step\When('/^(?:|I )move backward one page$/')]
* Moves backward one page in history
* Example: When I move backward one page
*
* @When /^(?:|I )move backward one page$/
*/
public function back() public function back()
{ {
$this->getSession()->back(); $this->getSession()->back();
} }
/** #[\Behat\Step\When('/^(?:|I )move forward one page$/')]
* Moves forward one page in history
* Example: And I move forward one page
*
* @When /^(?:|I )move forward one page$/
*/
public function forward() public function forward()
{ {
$this->getSession()->forward(); $this->getSession()->forward();
} }
/** #[\Behat\Step\When('/^(?:|I )press "(?P<button>(?:[^"]|\\")*)"$/')]
* Presses button with specified id|name|title|alt|value
* Example: When I press "Log In"
* Example: And I press "Log In"
*
* @When /^(?:|I )press "(?P<button>(?:[^"]|\\")*)"$/
*/
public function pressButton($button) public function pressButton($button)
{ {
$button = $this->fixStepArgument($button); $button = $this->fixStepArgument($button);
$this->getSession()->getPage()->pressButton($button); $this->getSession()->getPage()->pressButton($button);
} }
/** #[\Behat\Step\When('/^(?:|I )follow "(?P<link>(?:[^"]|\\")*)"$/')]
* Clicks link with specified id|title|alt|text
* Example: When I follow "Log In"
* Example: And I follow "Log In"
*
* @When /^(?:|I )follow "(?P<link>(?:[^"]|\\")*)"$/
*/
public function clickLink($link) public function clickLink($link)
{ {
$link = $this->fixStepArgument($link); $link = $this->fixStepArgument($link);
$this->getSession()->getPage()->clickLink($link); $this->getSession()->getPage()->clickLink($link);
} }
/** #[\Behat\Step\When('/^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)"$/')]
* Fills in form field with specified id|name|label|value #[\Behat\Step\When('/^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with:$/')]
* Example: When I fill in "username" with: "bwayne" #[\Behat\Step\When('/^(?:|I )fill in "(?P<value>(?:[^"]|\\")*)" for "(?P<field>(?:[^"]|\\")*)"$/')]
* Example: And I fill in "bwayne" for "username"
*
* @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)"$/
* @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with:$/
* @When /^(?:|I )fill in "(?P<value>(?:[^"]|\\")*)" for "(?P<field>(?:[^"]|\\")*)"$/
*/
public function fillField($field, $value) public function fillField($field, $value)
{ {
$field = $this->fixStepArgument($field); $field = $this->fixStepArgument($field);
@@ -125,17 +77,7 @@ class MinkContext extends RawMinkContext implements TranslatableContext
$this->getSession()->getPage()->fillField($field, $value); $this->getSession()->getPage()->fillField($field, $value);
} }
/** #[\Behat\Step\When('/^(?:|I )fill in the following:$/')]
* Fills in form fields with provided table
* Example: When I fill in the following"
* | username | bruceWayne |
* | password | iLoveBats123 |
* Example: And I fill in the following"
* | username | bruceWayne |
* | password | iLoveBats123 |
*
* @When /^(?:|I )fill in the following:$/
*/
public function fillFields(TableNode $fields) public function fillFields(TableNode $fields)
{ {
foreach ($fields->getRowsHash() as $field => $value) { foreach ($fields->getRowsHash() as $field => $value) {
@@ -143,13 +85,7 @@ class MinkContext extends RawMinkContext implements TranslatableContext
} }
} }
/** #[\Behat\Step\When('/^(?:|I )select "(?P<option>(?:[^"]|\\")*)" from "(?P<select>(?:[^"]|\\")*)"$/')]
* Selects option in select field with specified id|name|label|value
* Example: When I select "Bats" from "user_fears"
* Example: And I select "Bats" from "user_fears"
*
* @When /^(?:|I )select "(?P<option>(?:[^"]|\\")*)" from "(?P<select>(?:[^"]|\\")*)"$/
*/
public function selectOption($select, $option) public function selectOption($select, $option)
{ {
$select = $this->fixStepArgument($select); $select = $this->fixStepArgument($select);
@@ -157,13 +93,7 @@ class MinkContext extends RawMinkContext implements TranslatableContext
$this->getSession()->getPage()->selectFieldOption($select, $option); $this->getSession()->getPage()->selectFieldOption($select, $option);
} }
/** #[\Behat\Step\When('/^(?:|I )additionally select "(?P<option>(?:[^"]|\\")*)" from "(?P<select>(?:[^"]|\\")*)"$/')]
* Selects additional option in select field with specified id|name|label|value
* Example: When I additionally select "Deceased" from "parents_alive_status"
* Example: And I additionally select "Deceased" from "parents_alive_status"
*
* @When /^(?:|I )additionally select "(?P<option>(?:[^"]|\\")*)" from "(?P<select>(?:[^"]|\\")*)"$/
*/
public function additionallySelectOption($select, $option) public function additionallySelectOption($select, $option)
{ {
$select = $this->fixStepArgument($select); $select = $this->fixStepArgument($select);
@@ -171,39 +101,21 @@ class MinkContext extends RawMinkContext implements TranslatableContext
$this->getSession()->getPage()->selectFieldOption($select, $option, true); $this->getSession()->getPage()->selectFieldOption($select, $option, true);
} }
/** #[\Behat\Step\When('/^(?:|I )check "(?P<option>(?:[^"]|\\")*)"$/')]
* Checks checkbox with specified id|name|label|value
* Example: When I check "Pearl Necklace"
* Example: And I check "Pearl Necklace"
*
* @When /^(?:|I )check "(?P<option>(?:[^"]|\\")*)"$/
*/
public function checkOption($option) public function checkOption($option)
{ {
$option = $this->fixStepArgument($option); $option = $this->fixStepArgument($option);
$this->getSession()->getPage()->checkField($option); $this->getSession()->getPage()->checkField($option);
} }
/** #[\Behat\Step\When('/^(?:|I )uncheck "(?P<option>(?:[^"]|\\")*)"$/')]
* Unchecks checkbox with specified id|name|label|value
* Example: When I uncheck "Broadway Plays"
* Example: And I uncheck "Broadway Plays"
*
* @When /^(?:|I )uncheck "(?P<option>(?:[^"]|\\")*)"$/
*/
public function uncheckOption($option) public function uncheckOption($option)
{ {
$option = $this->fixStepArgument($option); $option = $this->fixStepArgument($option);
$this->getSession()->getPage()->uncheckField($option); $this->getSession()->getPage()->uncheckField($option);
} }
/** #[\Behat\Step\When('/^(?:|I )attach the file "(?P<path>[^"]*)" to "(?P<field>(?:[^"]|\\")*)"$/')]
* Attaches file to field with specified id|name|label|value
* Example: When I attach the file "bwayne_profile.png" to "profileImageUpload"
* Example: And I attach the file "bwayne_profile.png" to "profileImageUpload"
*
* @When /^(?:|I )attach the file "(?P<path>[^"]*)" to "(?P<field>(?:[^"]|\\")*)"$/
*/
public function attachFileToField($field, $path) public function attachFileToField($field, $path)
{ {
$field = $this->fixStepArgument($field); $field = $this->fixStepArgument($field);
@@ -218,219 +130,109 @@ class MinkContext extends RawMinkContext implements TranslatableContext
$this->getSession()->getPage()->attachFileToField($field, $path); $this->getSession()->getPage()->attachFileToField($field, $path);
} }
/** #[\Behat\Step\Then('/^(?:|I )should be on "(?P<page>[^"]+)"$/')]
* Checks, that current page PATH is equal to specified
* Example: Then I should be on "/"
* Example: And I should be on "/bats"
* Example: And I should be on "http://google.com"
*
* @Then /^(?:|I )should be on "(?P<page>[^"]+)"$/
*/
public function assertPageAddress($page) public function assertPageAddress($page)
{ {
$this->assertSession()->addressEquals($this->locatePath($page)); $this->assertSession()->addressEquals($this->locatePath($page));
} }
/** #[\Behat\Step\Then('/^(?:|I )should be on (?:|the )homepage$/')]
* Checks, that current page is the homepage
* Example: Then I should be on the homepage
* Example: And I should be on the homepage
*
* @Then /^(?:|I )should be on (?:|the )homepage$/
*/
public function assertHomepage() public function assertHomepage()
{ {
$this->assertSession()->addressEquals($this->locatePath('/')); $this->assertSession()->addressEquals($this->locatePath('/'));
} }
/** #[\Behat\Step\Then('/^the (?i)url(?-i) should match (?P<pattern>"(?:[^"]|\\")*")$/')]
* Checks, that current page PATH matches regular expression
* Example: Then the url should match "superman is dead"
* Example: Then the uri should match "log in"
* Example: And the url should match "log in"
*
* @Then /^the (?i)url(?-i) should match (?P<pattern>"(?:[^"]|\\")*")$/
*/
public function assertUrlRegExp($pattern) public function assertUrlRegExp($pattern)
{ {
$this->assertSession()->addressMatches($this->fixStepArgument($pattern)); $this->assertSession()->addressMatches($this->fixStepArgument($pattern));
} }
/** #[\Behat\Step\Then('/^the response status code should be (?P<code>\d+)$/')]
* Checks, that current page response status is equal to specified
* Example: Then the response status code should be 200
* Example: And the response status code should be 400
*
* @Then /^the response status code should be (?P<code>\d+)$/
*/
public function assertResponseStatus($code) public function assertResponseStatus($code)
{ {
$this->assertSession()->statusCodeEquals($code); $this->assertSession()->statusCodeEquals($code);
} }
/** #[\Behat\Step\Then('/^the response status code should not be (?P<code>\d+)$/')]
* Checks, that current page response status is not equal to specified
* Example: Then the response status code should not be 501
* Example: And the response status code should not be 404
*
* @Then /^the response status code should not be (?P<code>\d+)$/
*/
public function assertResponseStatusIsNot($code) public function assertResponseStatusIsNot($code)
{ {
$this->assertSession()->statusCodeNotEquals($code); $this->assertSession()->statusCodeNotEquals($code);
} }
/** #[\Behat\Step\Then('/^(?:|I )should see "(?P<text>(?:[^"]|\\")*)"$/')]
* Checks, that page contains specified text
* Example: Then I should see "Who is the Batman?"
* Example: And I should see "Who is the Batman?"
*
* @Then /^(?:|I )should see "(?P<text>(?:[^"]|\\")*)"$/
*/
public function assertPageContainsText($text) public function assertPageContainsText($text)
{ {
$this->assertSession()->pageTextContains($this->fixStepArgument($text)); $this->assertSession()->pageTextContains($this->fixStepArgument($text));
} }
/** #[\Behat\Step\Then('/^(?:|I )should not see "(?P<text>(?:[^"]|\\")*)"$/')]
* Checks, that page doesn't contain specified text
* Example: Then I should not see "Batman is Bruce Wayne"
* Example: And I should not see "Batman is Bruce Wayne"
*
* @Then /^(?:|I )should not see "(?P<text>(?:[^"]|\\")*)"$/
*/
public function assertPageNotContainsText($text) public function assertPageNotContainsText($text)
{ {
$this->assertSession()->pageTextNotContains($this->fixStepArgument($text)); $this->assertSession()->pageTextNotContains($this->fixStepArgument($text));
} }
/** #[\Behat\Step\Then('/^(?:|I )should see text matching (?P<pattern>"(?:[^"]|\\")*")$/')]
* Checks, that page contains text matching specified pattern
* Example: Then I should see text matching "Batman, the vigilante"
* Example: And I should not see "Batman, the vigilante"
*
* @Then /^(?:|I )should see text matching (?P<pattern>"(?:[^"]|\\")*")$/
*/
public function assertPageMatchesText($pattern) public function assertPageMatchesText($pattern)
{ {
$this->assertSession()->pageTextMatches($this->fixStepArgument($pattern)); $this->assertSession()->pageTextMatches($this->fixStepArgument($pattern));
} }
/** #[\Behat\Step\Then('/^(?:|I )should not see text matching (?P<pattern>"(?:[^"]|\\")*")$/')]
* Checks, that page doesn't contain text matching specified pattern
* Example: Then I should see text matching "Bruce Wayne, the vigilante"
* Example: And I should not see "Bruce Wayne, the vigilante"
*
* @Then /^(?:|I )should not see text matching (?P<pattern>"(?:[^"]|\\")*")$/
*/
public function assertPageNotMatchesText($pattern) public function assertPageNotMatchesText($pattern)
{ {
$this->assertSession()->pageTextNotMatches($this->fixStepArgument($pattern)); $this->assertSession()->pageTextNotMatches($this->fixStepArgument($pattern));
} }
/** #[\Behat\Step\Then('/^the response should contain "(?P<text>(?:[^"]|\\")*)"$/')]
* Checks, that HTML response contains specified string
* Example: Then the response should contain "Batman is the hero Gotham deserves."
* Example: And the response should contain "Batman is the hero Gotham deserves."
*
* @Then /^the response should contain "(?P<text>(?:[^"]|\\")*)"$/
*/
public function assertResponseContains($text) public function assertResponseContains($text)
{ {
$this->assertSession()->responseContains($this->fixStepArgument($text)); $this->assertSession()->responseContains($this->fixStepArgument($text));
} }
/** #[\Behat\Step\Then('/^the response should not contain "(?P<text>(?:[^"]|\\")*)"$/')]
* Checks, that HTML response doesn't contain specified string
* Example: Then the response should not contain "Bruce Wayne is a billionaire, play-boy, vigilante."
* Example: And the response should not contain "Bruce Wayne is a billionaire, play-boy, vigilante."
*
* @Then /^the response should not contain "(?P<text>(?:[^"]|\\")*)"$/
*/
public function assertResponseNotContains($text) public function assertResponseNotContains($text)
{ {
$this->assertSession()->responseNotContains($this->fixStepArgument($text)); $this->assertSession()->responseNotContains($this->fixStepArgument($text));
} }
/** #[\Behat\Step\Then('/^(?:|I )should see "(?P<text>(?:[^"]|\\")*)" in the "(?P<element>[^"]*)" element$/')]
* Checks, that element with specified CSS contains specified text
* Example: Then I should see "Batman" in the "heroes_list" element
* Example: And I should see "Batman" in the "heroes_list" element
*
* @Then /^(?:|I )should see "(?P<text>(?:[^"]|\\")*)" in the "(?P<element>[^"]*)" element$/
*/
public function assertElementContainsText($element, $text) public function assertElementContainsText($element, $text)
{ {
$this->assertSession()->elementTextContains('css', $element, $this->fixStepArgument($text)); $this->assertSession()->elementTextContains('css', $element, $this->fixStepArgument($text));
} }
/** #[\Behat\Step\Then('/^(?:|I )should not see "(?P<text>(?:[^"]|\\")*)" in the "(?P<element>[^"]*)" element$/')]
* Checks, that element with specified CSS doesn't contain specified text
* Example: Then I should not see "Bruce Wayne" in the "heroes_alter_egos" element
* Example: And I should not see "Bruce Wayne" in the "heroes_alter_egos" element
*
* @Then /^(?:|I )should not see "(?P<text>(?:[^"]|\\")*)" in the "(?P<element>[^"]*)" element$/
*/
public function assertElementNotContainsText($element, $text) public function assertElementNotContainsText($element, $text)
{ {
$this->assertSession()->elementTextNotContains('css', $element, $this->fixStepArgument($text)); $this->assertSession()->elementTextNotContains('css', $element, $this->fixStepArgument($text));
} }
/** #[\Behat\Step\Then('/^the "(?P<element>[^"]*)" element should contain "(?P<value>(?:[^"]|\\")*)"$/')]
* Checks, that element with specified CSS contains specified HTML
* Example: Then the "body" element should contain "style=\"color:black;\""
* Example: And the "body" element should contain "style=\"color:black;\""
*
* @Then /^the "(?P<element>[^"]*)" element should contain "(?P<value>(?:[^"]|\\")*)"$/
*/
public function assertElementContains($element, $value) public function assertElementContains($element, $value)
{ {
$this->assertSession()->elementContains('css', $element, $this->fixStepArgument($value)); $this->assertSession()->elementContains('css', $element, $this->fixStepArgument($value));
} }
/** #[\Behat\Step\Then('/^the "(?P<element>[^"]*)" element should not contain "(?P<value>(?:[^"]|\\")*)"$/')]
* Checks, that element with specified CSS doesn't contain specified HTML
* Example: Then the "body" element should not contain "style=\"color:black;\""
* Example: And the "body" element should not contain "style=\"color:black;\""
*
* @Then /^the "(?P<element>[^"]*)" element should not contain "(?P<value>(?:[^"]|\\")*)"$/
*/
public function assertElementNotContains($element, $value) public function assertElementNotContains($element, $value)
{ {
$this->assertSession()->elementNotContains('css', $element, $this->fixStepArgument($value)); $this->assertSession()->elementNotContains('css', $element, $this->fixStepArgument($value));
} }
/** #[\Behat\Step\Then('/^(?:|I )should see an? "(?P<element>[^"]*)" element$/')]
* Checks, that element with specified CSS exists on page
* Example: Then I should see a "body" element
* Example: And I should see a "body" element
*
* @Then /^(?:|I )should see an? "(?P<element>[^"]*)" element$/
*/
public function assertElementOnPage($element) public function assertElementOnPage($element)
{ {
$this->assertSession()->elementExists('css', $element); $this->assertSession()->elementExists('css', $element);
} }
/** #[\Behat\Step\Then('/^(?:|I )should not see an? "(?P<element>[^"]*)" element$/')]
* Checks, that element with specified CSS doesn't exist on page
* Example: Then I should not see a "canvas" element
* Example: And I should not see a "canvas" element
*
* @Then /^(?:|I )should not see an? "(?P<element>[^"]*)" element$/
*/
public function assertElementNotOnPage($element) public function assertElementNotOnPage($element)
{ {
$this->assertSession()->elementNotExists('css', $element); $this->assertSession()->elementNotExists('css', $element);
} }
/** #[\Behat\Step\Then('/^the "(?P<field>(?:[^"]|\\")*)" field should contain "(?P<value>(?:[^"]|\\")*)"$/')]
* Checks, that form field with specified id|name|label|value has specified value
* Example: Then the "username" field should contain "bwayne"
* Example: And the "username" field should contain "bwayne"
*
* @Then /^the "(?P<field>(?:[^"]|\\")*)" field should contain "(?P<value>(?:[^"]|\\")*)"$/
*/
public function assertFieldContains($field, $value) public function assertFieldContains($field, $value)
{ {
$field = $this->fixStepArgument($field); $field = $this->fixStepArgument($field);
@@ -438,13 +240,7 @@ class MinkContext extends RawMinkContext implements TranslatableContext
$this->assertSession()->fieldValueEquals($field, $value); $this->assertSession()->fieldValueEquals($field, $value);
} }
/** #[\Behat\Step\Then('/^the "(?P<field>(?:[^"]|\\")*)" field should not contain "(?P<value>(?:[^"]|\\")*)"$/')]
* Checks, that form field with specified id|name|label|value doesn't have specified value
* Example: Then the "username" field should not contain "batman"
* Example: And the "username" field should not contain "batman"
*
* @Then /^the "(?P<field>(?:[^"]|\\")*)" field should not contain "(?P<value>(?:[^"]|\\")*)"$/
*/
public function assertFieldNotContains($field, $value) public function assertFieldNotContains($field, $value)
{ {
$field = $this->fixStepArgument($field); $field = $this->fixStepArgument($field);
@@ -452,67 +248,36 @@ class MinkContext extends RawMinkContext implements TranslatableContext
$this->assertSession()->fieldValueNotEquals($field, $value); $this->assertSession()->fieldValueNotEquals($field, $value);
} }
/** #[\Behat\Step\Then('/^(?:|I )should see (?P<num>\d+) "(?P<element>[^"]*)" elements?$/')]
* Checks, that (?P<num>\d+) CSS elements exist on the page
* Example: Then I should see 5 "div" elements
* Example: And I should see 5 "div" elements
*
* @Then /^(?:|I )should see (?P<num>\d+) "(?P<element>[^"]*)" elements?$/
*/
public function assertNumElements($num, $element) public function assertNumElements($num, $element)
{ {
$this->assertSession()->elementsCount('css', $element, intval($num)); $this->assertSession()->elementsCount('css', $element, intval($num));
} }
/** #[\Behat\Step\Then('/^the "(?P<checkbox>(?:[^"]|\\")*)" checkbox should be checked$/')]
* Checks, that checkbox with specified id|name|label|value is checked #[\Behat\Step\Then('/^the "(?P<checkbox>(?:[^"]|\\")*)" checkbox is checked$/')]
* Example: Then the "remember_me" checkbox should be checked #[\Behat\Step\Then('/^the checkbox "(?P<checkbox>(?:[^"]|\\")*)" (?:is|should be) checked$/')]
* Example: And the "remember_me" checkbox is checked
*
* @Then /^the "(?P<checkbox>(?:[^"]|\\")*)" checkbox should be checked$/
* @Then /^the "(?P<checkbox>(?:[^"]|\\")*)" checkbox is checked$/
* @Then /^the checkbox "(?P<checkbox>(?:[^"]|\\")*)" (?:is|should be) checked$/
*/
public function assertCheckboxChecked($checkbox) public function assertCheckboxChecked($checkbox)
{ {
$this->assertSession()->checkboxChecked($this->fixStepArgument($checkbox)); $this->assertSession()->checkboxChecked($this->fixStepArgument($checkbox));
} }
/** #[\Behat\Step\Then('/^the "(?P<checkbox>(?:[^"]|\\")*)" checkbox should (?:be unchecked|not be checked)$/')]
* Checks, that checkbox with specified id|name|label|value is unchecked #[\Behat\Step\Then('/^the "(?P<checkbox>(?:[^"]|\\")*)" checkbox is (?:unchecked|not checked)$/')]
* Example: Then the "newsletter" checkbox should be unchecked #[\Behat\Step\Then('/^the checkbox "(?P<checkbox>(?:[^"]|\\")*)" should (?:be unchecked|not be checked)$/')]
* Example: Then the "newsletter" checkbox should not be checked #[\Behat\Step\Then('/^the checkbox "(?P<checkbox>(?:[^"]|\\")*)" is (?:unchecked|not checked)$/')]
* Example: And the "newsletter" checkbox is unchecked
*
* @Then /^the "(?P<checkbox>(?:[^"]|\\")*)" checkbox should (?:be unchecked|not be checked)$/
* @Then /^the "(?P<checkbox>(?:[^"]|\\")*)" checkbox is (?:unchecked|not checked)$/
* @Then /^the checkbox "(?P<checkbox>(?:[^"]|\\")*)" should (?:be unchecked|not be checked)$/
* @Then /^the checkbox "(?P<checkbox>(?:[^"]|\\")*)" is (?:unchecked|not checked)$/
*/
public function assertCheckboxNotChecked($checkbox) public function assertCheckboxNotChecked($checkbox)
{ {
$this->assertSession()->checkboxNotChecked($this->fixStepArgument($checkbox)); $this->assertSession()->checkboxNotChecked($this->fixStepArgument($checkbox));
} }
/** #[\Behat\Step\Then('/^print current URL$/')]
* Prints current URL to console.
* Example: Then print current URL
* Example: And print current URL
*
* @Then /^print current URL$/
*/
public function printCurrentUrl() public function printCurrentUrl()
{ {
echo $this->getSession()->getCurrentUrl(); echo $this->getSession()->getCurrentUrl();
} }
/** #[\Behat\Step\Then('/^print last response$/')]
* Prints last response to console
* Example: Then print last response
* Example: And print last response
*
* @Then /^print last response$/
*/
public function printLastResponse() public function printLastResponse()
{ {
echo ( echo (
@@ -521,13 +286,7 @@ class MinkContext extends RawMinkContext implements TranslatableContext
); );
} }
/** #[\Behat\Step\Then('/^show last response$/')]
* Opens last response content in browser
* Example: Then show last response
* Example: And show last response
*
* @Then /^show last response$/
*/
public function showLastResponse() public function showLastResponse()
{ {
if (null === $this->getMinkParameter('show_cmd')) { if (null === $this->getMinkParameter('show_cmd')) {
@@ -539,33 +298,16 @@ class MinkContext extends RawMinkContext implements TranslatableContext
system(sprintf($this->getMinkParameter('show_cmd'), escapeshellarg($filename))); system(sprintf($this->getMinkParameter('show_cmd'), escapeshellarg($filename)));
} }
/** public static function getTranslationResources(): array
* Returns list of definition translation resources paths
*
* @return array
*/
public static function getTranslationResources()
{ {
return self::getMinkTranslationResources(); return self::getMinkTranslationResources();
} }
/** public static function getMinkTranslationResources(): array
* Returns list of definition translation resources paths for this dictionary
*
* @return array
*/
public static function getMinkTranslationResources()
{ {
return glob(__DIR__.'/../../../../i18n/*.xliff'); return glob(__DIR__.'/../../../../i18n/*.xliff') ?: [];
} }
/**
* Returns fixed step argument (with \\" replaced back to ")
*
* @param string $argument
*
* @return string
*/
protected function fixStepArgument($argument) protected function fixStepArgument($argument)
{ {
return str_replace('\\"', '"', $argument); return str_replace('\\"', '"', $argument);

View File

@@ -11,7 +11,6 @@
namespace Behat\MinkExtension\Listener; namespace Behat\MinkExtension\Listener;
use Behat\Behat\EventDispatcher\Event\ExampleTested; use Behat\Behat\EventDispatcher\Event\ExampleTested;
use Behat\Behat\EventDispatcher\Event\ScenarioLikeTested;
use Behat\Behat\EventDispatcher\Event\ScenarioTested; use Behat\Behat\EventDispatcher\Event\ScenarioTested;
use Behat\Mink\Mink; use Behat\Mink\Mink;
use Behat\Testwork\EventDispatcher\Event\ExerciseCompleted; use Behat\Testwork\EventDispatcher\Event\ExerciseCompleted;
@@ -59,7 +58,7 @@ class SessionsListener implements EventSubscriberInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function getSubscribedEvents() public static function getSubscribedEvents(): array
{ {
return array( return array(
ScenarioTested::BEFORE => array('prepareDefaultMinkSession', 10), ScenarioTested::BEFORE => array('prepareDefaultMinkSession', 10),
@@ -79,11 +78,11 @@ class SessionsListener implements EventSubscriberInterface
* `@insulated` tag will cause Mink to stop current sessions before scenario * `@insulated` tag will cause Mink to stop current sessions before scenario
* instead of just soft-resetting them * instead of just soft-resetting them
* *
* @param ScenarioLikeTested $event * @param ScenarioTested $event
* *
* @throws ProcessingException when the @javascript tag is used without a javascript session * @throws ProcessingException when the @javascript tag is used without a javascript session
*/ */
public function prepareDefaultMinkSession(ScenarioLikeTested $event) public function prepareDefaultMinkSession(ScenarioTested $event)
{ {
$scenario = $event->getScenario(); $scenario = $event->getScenario();
$feature = $event->getFeature(); $feature = $event->getFeature();

View File

@@ -68,7 +68,7 @@ class MinkExtension implements ExtensionInterface
$this->registerDriverFactory(new WebdriverClassicFactory()); $this->registerDriverFactory(new WebdriverClassicFactory());
} }
public function registerDriverFactory(DriverFactory $driverFactory) public function registerDriverFactory(DriverFactory $driverFactory): void
{ {
$this->driverFactories[$driverFactory->getDriverName()] = $driverFactory; $this->driverFactories[$driverFactory->getDriverName()] = $driverFactory;
} }
@@ -76,7 +76,7 @@ class MinkExtension implements ExtensionInterface
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function load(ContainerBuilder $container, array $config) public function load(ContainerBuilder $container, array $config): void
{ {
if (isset($config['mink_loader'])) { if (isset($config['mink_loader'])) {
$basePath = $container->getParameter('paths.base'); $basePath = $container->getParameter('paths.base');
@@ -108,7 +108,7 @@ class MinkExtension implements ExtensionInterface
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function configure(ArrayNodeDefinition $builder) public function configure(ArrayNodeDefinition $builder): void
{ {
// Rewrite keys to define a shortcut way without allowing conflicts with real keys // Rewrite keys to define a shortcut way without allowing conflicts with real keys
$renamedKeys = array_diff( $renamedKeys = array_diff(
@@ -177,7 +177,7 @@ class MinkExtension implements ExtensionInterface
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function getConfigKey() public function getConfigKey(): string
{ {
return 'mink'; return 'mink';
} }
@@ -185,14 +185,14 @@ class MinkExtension implements ExtensionInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function initialize(ExtensionManager $extensionManager) public function initialize(ExtensionManager $extensionManager): void
{ {
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function process(ContainerBuilder $container) public function process(ContainerBuilder $container): void
{ {
$this->processSelectors($container); $this->processSelectors($container);
} }