Skip to content

test: Initial coverage of PHPUnit assertions *WITHOUT* this extension - #2

Merged
acoulton merged 4 commits into
1.xfrom
test-without-extension
Sep 18, 2026
Merged

acoulton merged 4 commits into
1.xfrom
test-without-extension

Conversation

@acoulton

Copy link
Copy Markdown
Contributor

Before we can prove that this extension formats phpunit assertions as expected, we need to prove that they aren't formatted specially by Behat core.

At the moment, this means loading a hacky extension in the tests to remove the default Behat PHPUnit stringer. Once we have a 4.0 release without that, we can remove the hacky extension. It's probably still worth keeping the feature coverage so that we can see the difference this extension makes.

@acoulton
acoulton added this pull request to stack #3 September 16, 2026 16:54
@acoulton acoulton mentioned this pull request Sep 16, 2026
8 tasks done
@acoulton
acoulton force-pushed the test-without-extension branch from 40cd713 to 91029d7 Compare September 17, 2026 06:44
Comment on lines +12 to +27
Then it should fail with the following results:
"""
# FAILED Scenario: Compare mismatched array
Then an array {"value": "foo"} should equal {"value": "bar"}: Should get the right value
Failed asserting that two arrays are equal. (PHPUnit\Framework\ExpectationFailedException)

# PASSED Scenario: Compare matching array
(no failures)

# FAILED Scenario: Compare mismatched ints
Then an integer 1 should equal 2: check the ints
Failed asserting that 1 is identical to 2. (PHPUnit\Framework\ExpectationFailedException)

# PASSED Scenario: Compare matching ints
(no failures)
"""

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The string content here is a custom stringification of Behat's JSON report.

From 4.0 onwards, we've said that Behat's pretty and progress format outputs are intended to be human-readable and may change in minor releases - only the machine-readable formats are guaranteed stable.

Therefore we should not assert on the actual Behat command output, as that may change. Summarising the JSON gives a good balance between build stability and feature readability.

This does mean we're assuming that our stringer will be used by all formatters - but I think that's OK based on the contracts/interfaces Behat provides for exception stringers.

return (new Config())
->withProfile(
(new Profile('default'))
->withExtension(new Extension(OverrideBuiltinPhpunitStringerExtension::class)),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This extension will be removed after the next Behat 4.0 release

Comment thread composer.json
"phpstan/phpstan": "2.1.46",
"rector/rector": "2.3.9"
"rector/rector": "2.3.9",
"sebastian/diff": ">=3.0.6 <10",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It needs to be a very wide sebastian/diff supported range, to work with the range of PHPUnit versions that will be installed in the next PR.

Comment thread composer.json
"php": ">=8.2 <8.6",
"behat/behat": "^4.0@alpha"
"behat/behat": "^4.0@alpha",
"phpunit/phpunit": "^8.5"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The next PR widens the supported PHPUnit range - this one just gets it working.

@acoulton
acoulton marked this pull request as ready for review September 17, 2026 07:16
@acoulton
acoulton force-pushed the test-without-extension branch from afba5bb to 7567826 Compare September 17, 2026 08:52
Base automatically changed from bootstrap-repo to 1.x September 18, 2026 16:09
Before we can prove that this extension formats phpunit assertions as
expected, we need to prove that they *aren't* formatted specially by
Behat core.

At the moment, this means loading a hacky extension in the tests to
remove the default Behat PHPUnit stringer. Once we have a 4.0 release
without that, we can remove the hacky extension. It's probably still
worth keeping the feature coverage so that we can see the difference
this extension makes.
The older versions of symfony/filesystem we provide don't include the `->readFile` method. Use our own.
@acoulton
acoulton force-pushed the test-without-extension branch from 7567826 to 7fd3698 Compare September 18, 2026 16:10

@carlos-granados carlos-granados left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Having to use an override extension is a bit ugly but can't think of a better option, thanks @acoulton

@acoulton

Copy link
Copy Markdown
Contributor Author

Agreed - I'll remove it as soon as we get 4.0 released.

@acoulton
acoulton merged commit 187500a into 1.x Sep 18, 2026
13 checks passed
@acoulton
acoulton deleted the test-without-extension branch September 20, 2026 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants