Skip to content

Stabilize regex error Behat assertions across PHP/PCRE versions#239

Merged
swissspidy merged 3 commits into
mainfrom
copilot/fix-behat-job-failure
Jun 20, 2026
Merged

Stabilize regex error Behat assertions across PHP/PCRE versions#239
swissspidy merged 3 commits into
mainfrom
copilot/fix-behat-job-failure

Conversation

Copilot AI commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

The failing test / Behat (8.3, trunk, mysql-8.0) job was caused by a brittle Behat expectation for invalid regex errors. The command output remained correct, but the asserted PCRE offset changed in newer PHP/PCRE builds.

  • Problem

    • The regex delimiter scenario in features/search-replace.feature hard-coded at offset 11.
    • In the failing CI environment, the same invalid pattern now reports unmatched closing parenthesis at offset 12.
  • Change

    • Updated the four invalid-regex assertions to match the stable part of the error message instead of an exact offset value.
    • This keeps coverage on the actual failure mode while avoiding false negatives from PHP/PCRE-specific offset differences.
  • Result

    • The Behat scenario continues to verify that invalid regex input is rejected with the expected compilation error.
    • The CI check no longer depends on a version-sensitive byte offset.
And STDERR should contain:
  """
  unmatched closing parenthesis at offset 1
  """

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix failing GitHub Actions job for Behat Stabilize regex error Behat assertions across PHP/PCRE versions Jun 20, 2026
Copilot AI requested a review from swissspidy June 20, 2026 11:50
@github-actions github-actions Bot added command:search-replace Related to 'search-replace' command scope:testing Related to testing state:unconfirmed labels Jun 20, 2026
@swissspidy swissspidy added this to the 2.1.14 milestone Jun 20, 2026
@codecov

codecov Bot commented Jun 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy

Copy link
Copy Markdown
Member

@copilot the modification helps make some tests pass, but they still fail on php 7.2:


001 Scenario: Search replace with a regex delimiter # features/search-replace.feature:463
      And STDERR should contain:                    # features/search-replace.feature:510
        $ wp search-replace 'regex error)' '' --regex
        
        Error: The regex pattern 'regex error)' with default delimiter 'chr(1)' and no flags fails.
        preg_match(): Compilation failed: unmatched parentheses at offset 11.
        cwd: /tmp/wp-cli-test-run--6a367f7e281a49.09614259/
        run time: 0.24805402755737
        exit status: 1
        
        Output does not contain expected string:
        unmatched closing parenthesis at offset 1
        
        --- Expected
        +++ Actual
        @@ @@
        -unmatched closing parenthesis at offset 1
        +Error: The regex pattern 'regex error)' with default delimiter 'chr(1)' and no flags fails.
        +preg_match(): Compilation failed: unmatched parentheses at offset 11.
         (Exception)

The assertion could use regex, e.g.

Then STDERR should match /.../

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

Copilot AI commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

@copilot the modification helps make some tests pass, but they still fail on php 7.2:

...

Addressed in ad8e0e0. I switched the four invalid-regex checks to STDERR should match /.../ with a pattern that accepts both unmatched parentheses and unmatched closing parenthesis, and no longer depends on a specific offset.

@swissspidy swissspidy marked this pull request as ready for review June 20, 2026 18:23
@swissspidy swissspidy requested a review from a team as a code owner June 20, 2026 18:23
Copilot AI review requested due to automatic review settings June 20, 2026 18:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR stabilizes the Behat coverage around invalid-regex handling for wp search-replace by removing reliance on a PCRE-reported byte offset that can vary across PHP/PCRE versions.

Changes:

  • Replaced four brittle STDERR should contain assertions (hard-coded at offset 11) with a regex-based assertion that accepts any numeric offset while still validating the underlying compilation failure.
  • Kept the scenario focused on the specific failure mode (“unmatched closing parenthesis…”) while avoiding false negatives across environments.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@swissspidy swissspidy merged commit e1c42e4 into main Jun 20, 2026
63 checks passed
@swissspidy swissspidy deleted the copilot/fix-behat-job-failure branch June 20, 2026 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:search-replace Related to 'search-replace' command scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants