Skip to content

Commit

Permalink
New expectation: toContainAll()
Browse files Browse the repository at this point in the history
toContainAll(array $needles):

Checks for multiple needles at once in the value.
Will only pass if all of the provided needles are present.
  • Loading branch information
alexmartinfr committed Jul 29, 2020
1 parent 3b2af5d commit d25a147
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Expectation.php
Expand Up @@ -156,6 +156,26 @@ public function toContain($needle): Expectation
return $this;
}

/**
* Asserts that all of the provided $needles are elements of the value.
*
* @param array $needles
*/
public function toContainAll(array $needles): Expectation
{
if (is_string($this->value)) {
foreach ($needles as $needle) {
Assert::assertStringContainsString($needle, $this->value);
}
} else {
foreach ($needles as $needle) {
Assert::assertContains($needle, $this->value);
}
}

return $this;
}

/**
* Asserts that $count matches the number of elements of the value.
*/
Expand Down

0 comments on commit d25a147

Please sign in to comment.