From d25a1477b388e06cc55c38965b7e65c891892f12 Mon Sep 17 00:00:00 2001 From: Alex Martin Date: Wed, 29 Jul 2020 11:33:21 +0200 Subject: [PATCH] New expectation: `toContainAll()` toContainAll(array $needles): Checks for multiple needles at once in the value. Will only pass if all of the provided needles are present. --- src/Expectation.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Expectation.php b/src/Expectation.php index afa9adcd..5b7f11aa 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -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. */