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
Fix typehinted arguments not marking arguments as defined #993
Conversation
|
Hum, indeed, but with But with |
The fix is indeed wrong, the array_merge could pose problems in the future (e.g using an unordered list of arguments or something like that). Another solution (while leaving the Actually, in my context, I have the following ; default:
suites:
main:
...
services: "MyContainer"
contexts:
- MyContext:
- "@foo"
- "@bar"
- "@baz" with In the |
0877a55
to
7981c62
Compare
@stof I Think I found the solution, which isn't replacing array additions with <?php
// .. constructor of the context (note the `?Baz`, but I think
// it should work for `string`, no typehints, ... etc)
function __construct(Foo $foo, ?Baz $baz)
{
// ...
}
// in the mixed arg organizer
$typehinted = [0 => $foo];
// in the prepareNumberedArgument pass
return [0 => null]; // instead of expected [1 => null] Thus, in the I'll add some tests for that. |
Can you add a scenario covering this ? If it requires PHP 7.1+ nullable typehints, tag it as |
Actually this isn't using 7.1 or 7 actually. But I think that a fix for 7.1 should be done for nullable anyway, but I thought that this wasn't the scope. I'll add the tests (features and unit) |
Well, if the bug can be triggered on all PHP versions, then writing a scenario covering it is even easier |
@stof we could switch to https://github.com/ciaranmcnulty/version-based-test-skipper if needed |
7981c62
to
55cfca6
Compare
Scenario added. I added it in the And I also added a note for the feature, as the first parameter isn't properly detected as a typehinted args, thus the last "numbered arg" would be a match and thus not deleted, while if there is a typehinted argument, it failed as expected (just undo the fix I did and it will fail as expected). cf #992 and #990 Do I also need to add a unit test ? |
55cfca6
to
56530aa
Compare
this is done in order that the next prepare call (prepareNumberedArguments) have the right indexes for its arguments. E.g, if for 5 arguments, we had the 2 typehinted `[1 => Foo, 3 => Bar]`, before it would try to replace those with `[0 => 'foo', 1 => 'bar', 2 => 'baz']`, resulting in `[0 => 'foo', 1 => Foo, 2 => 'baz', 3 => Bar]` which is wrong, as we would expect it to be `[0 => 'foo', 1 => Foo, 2 => 'bar', 3 => Bar, 4 => 'baz']` To achieve that, we need to indicate that the typehinted args are defined... Thus they are indeed skipped when trying to match numbered args.
56530aa
to
e311acc
Compare
e311acc
to
0e832da
Compare
@Taluu thanks for a fix. Especially thank you for a scenario and update of the CHANGELOG - that does make my life much easier! |
Fixes #991
Basically, array additions do some stuff that are not really expected ; if
null
is giving as a context constructor, it is skipped because it is how array additions behave.Replacing it with a good old
array_merge
fixes that.I'll add some unit tests for that.