Skip to content

Conversation

@jdeniau
Copy link
Contributor

@jdeniau jdeniau commented Apr 2, 2025

Fixes #1609 according to @acoulton comment

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.

@jdeniau this looks great, thanks, just a couple of small comments on the implementation.

One thing this highlights though is that you won't now be able to define a step to throw a PendingException with no arguments if the feature file includes a TableNode / PyString.

For example like this in the test that's failing:

#[Given('/^.*$/')]
public function anything() {
throw new PendingException();
}

We can obviously fix that test (I see why it was trying to keep the context file small, but I think it'd be clearer to make the step definitions explicit anyway).

And I think it's also OK to enforce this on end users:

  • if they're using our snippets or an IDE to generate pending steps from an existing feature then the TableNode / PyString argument would usually be included in the snippet anyway so it won't affect them.
  • if they've added function themselves without arguments, it will now generate an error instead of being marked as pending - but it's unlikely they've committed / pushed that to a main branch so at worst they'll need to update some existing work-in-progress.

That seems like a reasonable trade-off for making the behaviour stricter and reducing the risk of false positives in future.

@carlos-granados @stof what do you think?

@carlos-granados
Copy link
Contributor

That seems like a reasonable trade-off for making the behaviour stricter and reducing the risk of false positives in future.

@carlos-granados @stof what do you think?

Agree that this sounds reasonable and I think this is OK to go forward as soon as @jdeniau makes these small adjustments

@stof
Copy link
Member

stof commented May 21, 2025

I also agree it is a reasonable tradeoff

@acoulton
Copy link
Contributor

@jdeniau I think this one is actually very close to being finished, do you have time to resolve the small naming / wording changes? If not I can pick this up. Thanks :)

@jdeniau
Copy link
Contributor Author

jdeniau commented Sep 10, 2025

You are right, I will finish this in the next days 👍

@jdeniau jdeniau force-pushed the throw-if-knowned-paramer-is-not-defined branch 2 times, most recently from ff273e7 to 3de061c Compare September 10, 2025 11:47
@jdeniau jdeniau force-pushed the throw-if-knowned-paramer-is-not-defined branch from 3de061c to 8712b75 Compare September 10, 2025 11:50
@jdeniau
Copy link
Contributor Author

jdeniau commented Sep 10, 2025

@acoulton I made the changes, and fix the tests.
Everythink should be good now. Sorry for the long implementation !

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.

Brilliant, thanks @jdeniau - no need to apologise, we appreciate the contribution :-)

Copy link
Contributor

@carlos-granados carlos-granados left a comment

Choose a reason for hiding this comment

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

Thanks @jdeniau great job

@acoulton acoulton changed the title Throw an exception if a given parameter is a PyStringNode or a TableNode, but this argument is not expected in the context feat: throw if a step provides an unexpected PyString or Table argument Sep 11, 2025
@acoulton acoulton merged commit 511793e into Behat:master Sep 11, 2025
19 checks passed
@jdeniau jdeniau deleted the throw-if-knowned-paramer-is-not-defined branch September 29, 2025 13:56
@jdeniau
Copy link
Contributor Author

jdeniau commented Sep 29, 2025

Hi,

For the record, I added this change in our codebase and found 10 issues reported by this change on 440 tests files ! 😲

@AlexSkrypnyk
Copy link
Contributor

AlexSkrypnyk commented Sep 30, 2025

@carlos-granados
This broke a test suite after an upgrade and blocked some work as it was not easy to find what caused the issue.

The message does not include any contextual information. It took some time to debug in which file the problem resides.
Can more contextual information be added to exceptions like this in the future please.

Thank you

image

@acoulton
Copy link
Contributor

acoulton commented Oct 2, 2025

@AlexSkrypnyk apologies for this - I'd only looked at the feature file assertions in this branch (rather than the actual output) and I'd assumed we'd be showing that error message in the context of the feature & step (e.g. similar to a failed / pending step).

I see now that is incorrect and at this stage of execution there is indeed no context. I've got a fix for that in #1668 and we'll try to be more careful in future.

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.

Proposition: throw exception if a step as an unexpected TableNode

5 participants