beberlei / assert

Thin assertion library for use in libraries and business-model
Other
2.41k stars 188 forks source link

'Array Has At Least One Matching Entry' #242

Closed AndyGibsonProtectline closed 6 years ago

AndyGibsonProtectline commented 6 years ago

Hi!

Many apologies if I'm doing something really wrong.

I am trying to use Assert with Behat/MInk and I often end up trying to do something like the following: Given a parent with these properties When I add a child with name 'Jo' and age 21 And I view details of the parent Then I should see a child called 'Jo' aged 21

I then end up looping through a list of details and trying to see if any of the children entries match the given criteria.

I would find it really useful to have an assertion like AtLeastOneValueMatches( array, callback).

Should I...

Many thanks for a great library :)

rquadling commented 6 years ago

You can easily subclass the \Assert\Assertion and add your own assertions and/or exception class.

See https://github.com/beberlei/assert#your-own-assertion-class and https://github.com/beberlei/assert#exception--error-handling.

If you need more help or info, please ask.

For a value checker, \Assert\Assertion::choice() or \Assert\Assertion::inArray() both exist.

But I think \Assert\Assertion::satisfy() may be the assertion you are looking for.

AndyGibsonProtectline commented 6 years ago

OK, thank you. I'll do this myself, then. Thanks for your help!