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

[2.x] Intercept toContain to handle callables on collections #49

Conversation

gehrisandro
Copy link

Q A
Bug fix? no
New feature? yes

This PR intercepts the toContain for \Illuminate\Support\Collection to handle callables.

With this PR the following gets simplified:

// Before
expect(collect(['foo', 'bar']))
    ->contains(fn ($value) => $value === 'foo')->toBeTrue()
    ->contains(fn ($value) => $value === 'baz')->toBeFalse();

// After
expect(collect(['foo', 'bar']))
    ->toContain(fn ($value) => $value === 'foo')
    ->not->toContain(fn ($value) => $value === 'baz');

Under the hood it uses the contains function on the \Illuminate\Support\Collection.

If the expected value is NOT a callable it defaults back to the original toContain expectation.

@gehrisandro gehrisandro changed the title intercept toContain to handle callables on collections [2.x] Intercept toContain to handle callables on collections Sep 19, 2023
@nunomaduro
Copy link
Member

No plans for this, thanks for your contribution!

@nunomaduro nunomaduro closed this Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants