Skip to content
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

PHPLIB-1184: Improve CallbackIterator #1126

Merged
merged 6 commits into from
Jul 10, 2023

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Jul 7, 2023

PHPLIB-1184

#1059 contained some improvements to the CallbackIterator. These have been extracted here:

  • Pass element key to the callback
  • Define template for types in CallbackIterator
  • Declare the expected type for the callback
  • Accept any callable as callback instead of only accepting a Closure instance

@alcaeus alcaeus requested review from jmikola and GromNaN July 7, 2023 11:53
@alcaeus alcaeus self-assigned this Jul 7, 2023
@alcaeus alcaeus force-pushed the phplib-1184_improve-callback-iterator branch from 4d9a002 to 56a33c1 Compare July 7, 2023 12:08
src/Model/CallbackIterator.php Outdated Show resolved Hide resolved
tests/Model/CallbackIteratorTest.php Outdated Show resolved Hide resolved

class CallbackIteratorTest extends TestCase
{
public function testArrayIteration(): void
Copy link
Member

Choose a reason for hiding this comment

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

I'd propose rewriting all of these tests to use the following matrix:

  • Callbacks in various forms that apply the same transformation (*= 2 seems fine)
    • Closure
    • Object method (e.g. static method on this class)
  • Iterables
    • ArrayIterator constructed from an indexed array
    • ArrayIterator constructed from an associative array (to show that keys are preserved)
    • IteratorAggregate for both of the above (per @GromNaN's suggestion below)

Using a data provider for iterables and expected arrays would probably be most efficient.

Copy link
Member

Choose a reason for hiding this comment

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

@alcaeus I can make the changes if it frees you up.

@alcaeus alcaeus force-pushed the phplib-1184_improve-callback-iterator branch from 926726f to 4818124 Compare July 10, 2023 07:51
@alcaeus alcaeus requested a review from GromNaN July 10, 2023 07:51
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

LGTM

@alcaeus alcaeus merged commit c1e3a33 into mongodb:master Jul 10, 2023
11 checks passed
@alcaeus alcaeus deleted the phplib-1184_improve-callback-iterator branch July 10, 2023 10:45
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.

3 participants