Skip to content

Conversation

@carlos-granados
Copy link
Contributor

Updates the hook failures tests to use fixtures instead of files created on the fly. Uses a single fixture folder for all hook failures tests. Removes hook failure tests for annotations

Scenario: First scenario
When I have a simple step
"""
Given I initialise the working directory from the "HookFailures" fixtures folder
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use the fixtures from the "HookFailures" folder

And I provide the following options for all behat invocations:
| option | value |
| --no-colors | |
| --format | json |
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Define the output format for all tests

When I run "behat --no-colors --format=json --out=beforesuite.json"
When I run behat with the following additional options:
| option | value |
| --profile | beforeSuite |
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use the profile that matches what we want to test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Testing this with annotations does not provide any real value. We already test that hook annotations are processed in other tests and the hook failures tests are about the output when one of these failures happen

Scenario: First scenario
When I have a simple step
"""
Given I initialise the working directory from the "HookFailures" fixtures folder
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tests use the same fixture folder for all formatters

{
private static bool $thrown = false;

protected static function throwFailure(string $message): void
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We implement a function that only throws an exception the first time it is called, this allows us to use this with several suites, features, scenarios or steps

Copy link
Contributor

@acoulton acoulton left a comment

Choose a reason for hiding this comment

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

Much cleaner, thanks @carlos-granados

@carlos-granados carlos-granados merged commit 0d4162b into Behat:master Nov 5, 2025
19 checks passed
@carlos-granados carlos-granados deleted the refactor-tests-hook-failures branch November 5, 2025 12:17
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