spatie / pest-expectations

A collection of handy custom Pest customisations
https://spatie.be/open-source
MIT License
68 stars 3 forks source link

feat: add `toBeArrayOf` expectation #22

Closed innocenzi closed 5 months ago

innocenzi commented 5 months ago

This pull request adds the toBeArrayOf expectation, which asserts a specific value is an array of the specified type.

expect(User::all())->toBeArrayOf(User::class);

I very often have to deal with arrays of data objects and I copy-paste this expectation in a lot of projects:

expect(FlightData::collectFromFl3xxFlights($response))
        ->toBeArrayOf(FlightData::class)
        ->toHaveCount(8);

I'm also thinking of either adding toBeCollectionOf, or supporting collections in toBeArrayOf. What do you think?

freekmurze commented 5 months ago

I'm also thinking of either adding toBeCollectionOf, or supporting collections in toBeArrayOf. What do you think?

I would be open for that as well.

Thanks for your work on this!