-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can table nodes really contain scalar cell values? #285
Comments
So I think this depends on how you view the
I don't think the project has ever marked TableNode as an internal / consume-only class, so I think we have to keep supporting the second case. I know that in our projects we do create TableNode - for example because we have a library for comparing two TableNodes (e.g. one from a scenario, one built in our contexts from the actual result). That lets us do things like ignore column sequence / columns that aren't specified in the expectation for that specific step / etc, and it outputs any failures in a table format. I realise we could do that with plain arrays, but that's not the way we went back in 2015... For these, we generally have to cast to string before building the table to pass the assertions, so the impact of the BC break would be small (there are doubtless some columns we've missed). We also sometimes create TableNode as an efficient/effective way to render tabular data for failure / debug messages. This would be more of a BC issue for us (we're fine with the current behaviour where false becomes a zero-width string). I think from bug reports / comments I've seen over the years, there are other people creating tables themselves too. However I would actually be in favour of loosening the requirement to |
I would be in favor of deprecating passing non-string values in TableNode (deprecating only, so that it is not a BC break yet) and casting them to string early, so that the implementation after that only deals with strings. |
I guess I just feel there are valid cases for using However I recognise using it as a general data structure is beyond the scope of it purely being a representation of a Gherkin table, which is always strings. So I'm happy to be outvoted. Bear in mind that adding a runtime deprecation (e.g. |
Sorry, I forgot to link that, here's how:
I'm fine either way. I've been thinking maybe I could use phpstan generics, I'll see if I can set up an example in the next few days. |
Ah OK. So IMO the usage by ExampleNode is specific to a table that came from Gherkin, and therefore we know it will definitely only be strings in that I appreciate that knowledge may be too complex to represent for phpstan, and maybe having the strict type safety for ourselves is more important than supporting the generic usecase for other users. But if it was possible to do both, personally I think that'd be good. |
Here's how that can be determined by the class type - I would need to change the class hierarchy a bit though, but it should be fine in terms of BC: Alternatively, something similar can be done purely in PHPDoc - this approach might make it more complicated to actually check cell values as we do now: |
If we look at the following code:
Gherkin/src/Behat/Gherkin/Node/TableNode.php
Line 64 in 3d7bfdd
Why is this significant? While implementing PHPStan, I started with scalar cell values, but later on this becomes more and more ambiguous.
For example:
Gherkin/src/Behat/Gherkin/Node/TableNode.php
Line 68 in 3d7bfdd
false
is 0, because PHP casts it to an empty string (instead of'0'
).str_replace()
- which produces some odd results: https://3v4l.org/QTtAKGherkin/src/Behat/Gherkin/Node/ExampleNode.php
Line 259 in e016902
So, should I...
is_scalar
withis_string
?In any case, how much of a BC break is it?
The text was updated successfully, but these errors were encountered: