diff --git a/.github/workflows/lock-behat-version.sh b/.github/workflows/lock-behat-version.sh new file mode 100755 index 0000000..15ba49a --- /dev/null +++ b/.github/workflows/lock-behat-version.sh @@ -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 diff --git a/.github/workflows/lock-symfony-version.sh b/.github/workflows/lock-symfony-version.sh new file mode 100755 index 0000000..08cc742 --- /dev/null +++ b/.github/workflows/lock-symfony-version.sh @@ -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 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1cd6311..fd2664f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -2,36 +2,46 @@ name: Test on: push: + branches: + - master pull_request: - types: [opened, synchronize, edited, reopened] + schedule: + - + cron: "0 1 * * 6" # Run at 1am every Saturday jobs: 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 continue-on-error: false strategy: fail-fast: false matrix: php-version: - - '7.4' - - '8.0' - - '8.1' + - '8.3' + - '8.4' + - '8.5' symfony-version: - - '4.4.*' - - '5.4.*' - - '6.4.*' + - '7.4.*' + - '8.0.*' + - '8.1.*' + behat-version: + - stable + - 4.x-dev exclude: - - php-version: '7.4' - symfony-version: '6.4.*' - - php-version: '8.0' - symfony-version: '6.4.*' - include: - - php-version: '8.2' - symfony-version: '7.0.*' + # Symfony 8.x requires PHP >= 8.4 + - php-version: '8.3' + symfony-version: '8.0.*' + - php-version: '8.3' + symfony-version: '8.1.*' + # Behat 3.31 (stable) cannot install with Symfony 8.x + - behat-version: stable + symfony-version: '8.0.*' + - behat-version: stable + symfony-version: '8.1.*' steps: - name: Checkout - uses: actions/checkout@v6 + uses: actions/checkout@v5 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -42,10 +52,17 @@ jobs: tools: composer:v2 - name: Validate composer.json - run: composer validate --no-check-lock + run: composer validate --strict - - name: Configure Symfony version - run: composer require --no-update "symfony/config:${{ matrix.symfony-version }}" "symfony/dependency-injection:${{ matrix.symfony-version }}" + - name: Lock 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 run: composer install --prefer-dist --no-progress @@ -54,4 +71,4 @@ jobs: run: vendor/bin/phpspec run -f pretty - name: Behat - run: vendor/bin/behat -fprogress --strict + run: vendor/bin/behat --config behat.dist.php -fprogress --strict diff --git a/behat.dist.php b/behat.dist.php new file mode 100644 index 0000000..84f2185 --- /dev/null +++ b/behat.dist.php @@ -0,0 +1,28 @@ +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, + ], + ], + ]) + ) + ); diff --git a/behat.yml.dist b/behat.yml.dist deleted file mode 100644 index 5fab930..0000000 --- a/behat.yml.dist +++ /dev/null @@ -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: ~ diff --git a/composer.json b/composer.json index 242a885..9aec045 100644 --- a/composer.json +++ b/composer.json @@ -21,16 +21,16 @@ ], "homepage": "https://github.com/FriendsOfBehat/MinkExtension#readme", "require": { - "php": "^7.4 || ^8", - "behat/behat": "^3.0.5", + "php": "^8.3", + "behat/behat": "^3.31", "behat/mink": "^1.5", - "symfony/config": "^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/deprecation-contracts": "^1.0 || ^2.0 || ^3.0" + "symfony/config": "^7.4 || ^8.0" }, "require-dev": { - "behat/mink-goutte-driver": "^1.1 || ^2.0", - "phpspec/phpspec": "^6.0 || ^7.0 || 7.1.x-dev", - "mink/webdriver-classic-driver": "^1.0@dev" + "behat/mink-browserkit-driver": "^2.0", + "phpspec/phpspec": "^8.0", + "symfony/browser-kit": "^7.4 || ^8.0", + "symfony/http-client": "^7.4 || ^8.0" }, "replace": { "behat/mink-extension": "self.version" @@ -44,5 +44,11 @@ "branch-alias": { "dev-master": "2.x-dev" } + }, + "scripts": { + "test": [ + "vendor/bin/phpspec run -f pretty", + "vendor/bin/behat --config behat.dist.php -fprogress --strict" + ] } } diff --git a/src/Behat/MinkExtension/Context/Initializer/MinkAwareInitializer.php b/src/Behat/MinkExtension/Context/Initializer/MinkAwareInitializer.php index bbb45ab..74bfa66 100644 --- a/src/Behat/MinkExtension/Context/Initializer/MinkAwareInitializer.php +++ b/src/Behat/MinkExtension/Context/Initializer/MinkAwareInitializer.php @@ -24,27 +24,13 @@ use Behat\MinkExtension\Context\MinkAwareContext; */ class MinkAwareInitializer implements ContextInitializer { - private $mink; - private $parameters; - - /** - * Initializes initializer. - * - * @param Mink $mink - * @param array $parameters - */ - public function __construct(Mink $mink, array $parameters) - { - $this->mink = $mink; - $this->parameters = $parameters; + public function __construct( + private readonly Mink $mink, + private readonly array $parameters, + ) { } - /** - * Initializes provided context. - * - * @param Context $context - */ - public function initializeContext(Context $context) + public function initializeContext(Context $context): void { if (!$context instanceof MinkAwareContext) { return; diff --git a/src/Behat/MinkExtension/Context/MinkContext.php b/src/Behat/MinkExtension/Context/MinkContext.php index c6eeb0f..aa7c36d 100644 --- a/src/Behat/MinkExtension/Context/MinkContext.php +++ b/src/Behat/MinkExtension/Context/MinkContext.php @@ -21,103 +21,55 @@ use Behat\Gherkin\Node\TableNode; */ class MinkContext extends RawMinkContext implements TranslatableContext { - /** - * Opens 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$/ - */ + #[\Behat\Step\Given('/^(?:|I )am on (?:|the )homepage$/')] + #[\Behat\Step\When('/^(?:|I )go to (?:|the )homepage$/')] public function iAmOnHomepage() { $this->visitPath('/'); } - /** - * Opens specified 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[^"]+)"$/ - * @When /^(?:|I )go to "(?P[^"]+)"$/ - */ + #[\Behat\Step\Given('/^(?:|I )am on "(?P[^"]+)"$/')] + #[\Behat\Step\When('/^(?:|I )go to "(?P[^"]+)"$/')] public function visit($page) { $this->visitPath($page); } - /** - * Reloads current page - * Example: When I reload the page - * Example: And I reload the page - * - * @When /^(?:|I )reload the page$/ - */ + #[\Behat\Step\When('/^(?:|I )reload the page$/')] public function reload() { $this->getSession()->reload(); } - /** - * Moves backward one page in history - * Example: When I move backward one page - * - * @When /^(?:|I )move backward one page$/ - */ + #[\Behat\Step\When('/^(?:|I )move backward one page$/')] public function back() { $this->getSession()->back(); } - /** - * Moves forward one page in history - * Example: And I move forward one page - * - * @When /^(?:|I )move forward one page$/ - */ + #[\Behat\Step\When('/^(?:|I )move forward one page$/')] public function forward() { $this->getSession()->forward(); } - /** - * 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