phpspec / prophecy

Highly opinionated mocking framework for PHP 5.3+
MIT License
8.53k stars 241 forks source link

Add Argument::in() and Argument::notIn() #462

Closed viniciusalonso closed 4 years ago

viniciusalonso commented 4 years ago

I was working in some exercises using TDD and I needed to write an example like this:

$rule = $this->prophesize(MultipleThreeRule::class);

$rule->condition(Argument::that(function($arg) {
    return in_array($arg, [3, 6, 9, 12]);
}))->willReturn(true);

The idea is guarantee that a value is in array.

$rule->condition(12); // returns true

Then, I implemented an easier way to get to same result:

$rule = $this->prophesize(MultipleThreeRule::class);

$rule->condition(Argument::in([3, 6, 9, 12]))->willReturn(true);

And I also I implemented the opposite way, when value is not in array:

$rule = $this->prophesize(MultipleThreeRule::class);

$rule->condition(Argument::notIn([3, 6, 9, 12]))->willReturn(false);
ciaranmcnulty commented 4 years ago

Thanks @viniciusalonso - looks good