In PHPUnit it quite easy to assert that two arrays contain the same value:
$this->assertEquals( [1, 2, 3], [1, 2, 3] );
Recent versions of PHP made usage of Iterators and Generators a lot more attractive, and PHP 7.1 introduced the iterable pseudo-type. That means I can write functions to take and return iterable
without binding to the fact I am using a plain old array
or using a lazy Generator
.
How do I assert the return value of functions returning an iterable
? Ideally I could do something like
$this->assertIterablesEqual( ['expected', 'values'], $iterable );
Is there such a function? Alternatively, is there a sane way of testing this that does not involve adding a pile of besides-the-point imperative code to my tests?