Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Feature request: Array matcher #13

Open
bitwombat opened this issue Jan 14, 2019 · 2 comments
Open

Feature request: Array matcher #13

bitwombat opened this issue Jan 14, 2019 · 2 comments

Comments

@bitwombat
Copy link

bitwombat commented Jan 14, 2019

Any plans to add array matchers (someOf, only)?

I've poked around a bit and see that Sebastian Bergmann's comparator package has a slick ArrayComparator that could be employed. And, this guy made a go of it, but it's not quite right https://github.com/jameshalsall/phpspec-array-contains-matchers

@fetzi
Copy link
Contributor

fetzi commented Jan 15, 2019

The someOf matcher is already implemented. Please see the documentation.

The only matcher should be the same as the normal shouldBe matcher?

@bitwombat
Copy link
Author

bitwombat commented Jan 15, 2019

The someOf matcher is already implemented. Please see the documentation

Oops, missed that, sorry. Yep, that's one of them, but doesn't look like it supports associative arrays?

The only matcher should be the same as the normal shouldBe matcher?

I'm not sure. Maybe I'm being fooled by the functionality implemented here:
https://github.com/sebastianbergmann/comparator/blob/master/src/ArrayComparator.php

What I'm ultimately after is a more useful error message than "[array:2]"... like which key/value pair didn't match. Something like:

Array (
        'a' => 'b'
    --->'c' => 'e'
)

I may be bumping up against a PHPSpec architectural issue, since the presenters only take in one value at a time - no way to cross-compare and display two arrays, for example.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants