assertStringMatchesFormat()
should allow string
type (not non-empty-string
) for $actual
parameter
#5459
Labels
assertStringMatchesFormat()
should allow string
type (not non-empty-string
) for $actual
parameter
#5459
Summary
I encountered an issue that was introduced with the commit 9f7422c labeled "Narrow types". This change seems to have modified the expected type for certain arguments in the
assertStringMatchesFormat()
method, fromstring
tonon-empty-string
.This change has led to the issue where previously valid code now fails. An example of such a scenario is:
In this case, unless the
generate()
method explicitly returns anon-empty-string
, this piece of code will fail due to the newly implemented type restriction.While I understand the intention to ensure meaningful strings are passed into the method, requiring
non-empty-string
as the type for all$actual
parameters might be too restrictive. This could potentially break a significant amount of code that previously ran without issues.Could you please clarify whether this change was intentional and discuss the possibility of revisiting this requirement? The concept of a non-empty string being a subtype of a string suggests that this change could exclude valid use-cases, particularly when interfacing with methods that do not provide a non-empty-string guarantee but are nevertheless valid.
Current behavior
Fails
Expected behavior
Passes
The text was updated successfully, but these errors were encountered: