Skip to content

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

Merged
ciaranmcnulty merged 3 commits intophpspec:masterfrom
viniciusalonso:is-in-array
Sep 26, 2020
Merged

Add Argument::in() and Argument::notIn()#462
ciaranmcnulty merged 3 commits intophpspec:masterfrom
viniciusalonso:is-in-array

Conversation

@viniciusalonso
Copy link
Contributor

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 ciaranmcnulty merged commit d66a590 into phpspec:master Sep 26, 2020
@ciaranmcnulty
Copy link
Member

Thanks @viniciusalonso - looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments