mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
implements multiple needles in expect()->toContain()
This commit is contained in:
@ -266,15 +266,17 @@ final class Expectation
|
||||
/**
|
||||
* Asserts that $needle is an element of the value.
|
||||
*
|
||||
* @param mixed $needle
|
||||
* @param mixed $needles
|
||||
*/
|
||||
public function toContain($needle): Expectation
|
||||
public function toContain(...$needles): Expectation
|
||||
{
|
||||
foreach ($needles as $needle) {
|
||||
if (is_string($this->value)) {
|
||||
Assert::assertStringContainsString($needle, $this->value);
|
||||
} else {
|
||||
Assert::assertContains($needle, $this->value);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -325,9 +325,16 @@
|
||||
|
||||
PASS Tests\Features\Expect\toContain
|
||||
✓ passes strings
|
||||
✓ passes strings with multiple needles
|
||||
✓ passes arrays
|
||||
✓ passes arrays with multiple needles
|
||||
✓ passes with array needles
|
||||
✓ failures
|
||||
✓ failures with multiple needles (all failing)
|
||||
✓ failures with multiple needles (some failing)
|
||||
✓ not failures
|
||||
✓ not failures with multiple needles (all failing)
|
||||
✓ not failures with multiple needles (some failing)
|
||||
|
||||
PASS Tests\Features\Expect\toEndWith
|
||||
✓ pass
|
||||
@ -601,5 +608,5 @@
|
||||
✓ it is a test
|
||||
✓ it uses correct parent class
|
||||
|
||||
Tests: 4 incompleted, 9 skipped, 381 passed
|
||||
Tests: 4 incompleted, 9 skipped, 388 passed
|
||||
|
||||
@ -3,17 +3,45 @@
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('passes strings', function () {
|
||||
expect([1, 2, 42])->toContain(42);
|
||||
expect('Nuno')->toContain('Nu');
|
||||
});
|
||||
|
||||
test('passes strings with multiple needles', function () {
|
||||
expect('Nuno')->toContain('Nu', 'no');
|
||||
});
|
||||
|
||||
test('passes arrays', function () {
|
||||
expect('Nuno')->toContain('Nu');
|
||||
expect([1, 2, 42])->toContain(42);
|
||||
});
|
||||
|
||||
test('passes arrays with multiple needles', function () {
|
||||
expect([1, 2, 42])->toContain(42, 2);
|
||||
});
|
||||
|
||||
test('passes with array needles', function () {
|
||||
expect([[1, 2, 3], 2, 42])->toContain(42, [1, 2, 3]);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect([1, 2, 42])->toContain(3);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with multiple needles (all failing)', function () {
|
||||
expect([1, 2, 42])->toContain(3, 4);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with multiple needles (some failing)', function () {
|
||||
expect([1, 2, 42])->toContain(1, 3, 4);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () {
|
||||
expect([1, 2, 42])->not->toContain(42);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures with multiple needles (all failing)', function () {
|
||||
expect([1, 2, 42])->not->toContain(42, 2);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures with multiple needles (some failing)', function () {
|
||||
expect([1, 2, 42])->not->toContain(42, 1);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
Reference in New Issue
Block a user