mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
Merge pull request #363 from freekmurze/add-to-be-in
Add `toBeIn` expectation
This commit is contained in:
@ -371,6 +371,18 @@ final class Expectation
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the value is one of the given values.
|
||||
*
|
||||
* @param iterable<int|string, mixed> $values
|
||||
*/
|
||||
public function toBeIn(iterable $values): Expectation
|
||||
{
|
||||
Assert::assertContains($this->value, $values);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the value is infinite.
|
||||
*/
|
||||
|
||||
16
tests/Features/Expect/toBeIn.php
Normal file
16
tests/Features/Expect/toBeIn.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
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);
|
||||
Reference in New Issue
Block a user