Skip to content

Conversation

@MizouziE
Copy link
Contributor

@MizouziE MizouziE commented Sep 26, 2025

TL;DR: If a user callback has 2 parameters, use the second as the index

Working recently with the each() function we've thought it could be handy to have access to the index of the foreach in the case that we're expecting the same element but with different attributes/content. By allowing for the integer index to be passed into the callback, a user can use that to compare against an array of expectations.

A rough example:

    public function test_foo(): void
    {
        $this->component(Foo::class)
            ->assertElementExists(function (AssertElement $element) {
                $element->each('span', function (AssertElement $span, int $index) {
                    dump('index: ' . $index);
                    dump('span: ' . $span->getParser()->getContent());
                });
            });
    }

@sinnbeck
Copy link
Owner

Sounds like a good idea.

@sinnbeck sinnbeck merged commit 8e6e1b0 into sinnbeck:main Sep 30, 2025
28 checks passed
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.

2 participants