-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Allow using a \Traversable as data provider, not only \Iterater #2666
Allow using a \Traversable as data provider, not only \Iterater #2666
Conversation
Codecov Report
@@ Coverage Diff @@
## 6.1 #2666 +/- ##
============================================
+ Coverage 53.83% 53.86% +0.02%
Complexity 2740 2740
============================================
Files 102 102
Lines 7179 7179
============================================
+ Hits 3865 3867 +2
+ Misses 3314 3312 -2
Continue to review full report at Codecov.
|
please add a test for that |
+1 It is a bug, because function
So IMO it should be applied also for older versions. |
@@ -517,7 +518,7 @@ private static function getDataFromDataProviderAnnotation($docComment, $classNam | |||
$data = $dataProviderMethod->invoke($object, $methodName); | |||
} | |||
|
|||
if ($data instanceof Iterator) { | |||
if ($data instanceof Traversable) { | |||
$data = \iterator_to_array($data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not go even forward and use iterable
instead ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't do that because iterator_to_array
cannot be passed an array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@keradus Iterable
is not not class or interface, it is pseudo-type, is_iterable
function was introduced in PHP 7.1 and phpunit supports also older versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's why I lowercased it, didn't I?
is_iterable is polyfilled even in 5.x
https://github.com/symfony/polyfill/tree/master/src/Php71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I referred to main change of this PR.
And my proposal is deeper - to allow dataProvider not only work properly with Traversable, but all iterable.
whith this change, it will probably be like that, good to prove by utests, which are already there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And my proposal is deeper - to allow dataProvider not only work properly with Traversable, but all iterable.
I think I don't understand. Traversable
and array
are all iterable
possibilities, so IMO this change is good enough. Is there something what is skipped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah, I asked for tests proving that, which @issei-m done later ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@keradus I also don't figure it out. Could you tell me your perspective in more detail, and what should I specifically do here?
@keradus Test has been added! |
yield [null, 'ok', null]; | ||
yield [null, 'ok', null]; | ||
yield [null, 'ok', null]; | ||
return new WrapperIteratorAggregate([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please don't modify existing tests. add new one instead.
@keradus Sorry for the late response. I've fixed test you mentioned. |
Merged manually into |
I'm not sure whether it's a bug or not, so I'm targeting
6.1
the current stable branch.