diff --git a/src/Expectation.php b/src/Expectation.php index e41f21d0..e76a30bd 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -371,6 +371,18 @@ final class Expectation return $this; } + /** + * Asserts that the value is one of the given values. + * + * @param iterable $values + */ + public function toBeIn(iterable $values): Expectation + { + Assert::assertContains($this->value, $values); + + return $this; + } + /** * Asserts that the value is infinite. */ diff --git a/tests/Features/Expect/toBeIn.php b/tests/Features/Expect/toBeIn.php new file mode 100644 index 00000000..6636a51b --- /dev/null +++ b/tests/Features/Expect/toBeIn.php @@ -0,0 +1,16 @@ +toBeIn(['a', 'b', 'c']); + expect('d')->not->toBeIn(['a', 'b', 'c']); +}); + +test('failures', function () { + expect('d')->toBeIn(['a', 'b', 'c']); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect('a')->not->toBeIn(['a', 'b', 'c']); +})->throws(ExpectationFailedException::class);