From 5f574ded814525931c6adc71448437581cdf07b5 Mon Sep 17 00:00:00 2001 From: freek Date: Wed, 28 Jul 2021 00:36:43 +0200 Subject: [PATCH 1/3] add toBeIn --- src/Expectation.php | 10 ++++++++++ tests/Features/Expect/toBeIn.php | 11 +++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/Features/Expect/toBeIn.php diff --git a/src/Expectation.php b/src/Expectation.php index e41f21d0..2e92434e 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -371,6 +371,16 @@ final class Expectation return $this; } + /** + * Asserts that the value is one of the given values. + */ + public function toBeIn(array $possibleValues): Expectation + { + Assert::assertContains($this->value, $possibleValues); + + 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..3d34f46a --- /dev/null +++ b/tests/Features/Expect/toBeIn.php @@ -0,0 +1,11 @@ +toBeIn(['a', 'b', 'c']); +}); + +test('failures', function () { + expect('d')->toBeIn(['a', 'b', 'c']); +})->throws(ExpectationFailedException::class); From 2dd77001b7cc8f2824a5ee2b5d754831212e440b Mon Sep 17 00:00:00 2001 From: freek Date: Wed, 28 Jul 2021 00:42:54 +0200 Subject: [PATCH 2/3] static analysis fix --- src/Expectation.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Expectation.php b/src/Expectation.php index 2e92434e..e32a8683 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -373,6 +373,8 @@ final class Expectation /** * Asserts that the value is one of the given values. + * + * @param array $possibleValues */ public function toBeIn(array $possibleValues): Expectation { From 671f3df115bcf5bcba67c59ed3a635abe0ebf755 Mon Sep 17 00:00:00 2001 From: freek Date: Wed, 28 Jul 2021 01:00:19 +0200 Subject: [PATCH 3/3] fix tests --- src/Expectation.php | 6 +++--- tests/Features/Expect/toBeIn.php | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Expectation.php b/src/Expectation.php index e32a8683..e76a30bd 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -374,11 +374,11 @@ final class Expectation /** * Asserts that the value is one of the given values. * - * @param array $possibleValues + * @param iterable $values */ - public function toBeIn(array $possibleValues): Expectation + public function toBeIn(iterable $values): Expectation { - Assert::assertContains($this->value, $possibleValues); + Assert::assertContains($this->value, $values); return $this; } diff --git a/tests/Features/Expect/toBeIn.php b/tests/Features/Expect/toBeIn.php index 3d34f46a..6636a51b 100644 --- a/tests/Features/Expect/toBeIn.php +++ b/tests/Features/Expect/toBeIn.php @@ -4,8 +4,13 @@ use PHPUnit\Framework\ExpectationFailedException; test('passes', function () { expect('a')->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);