Merge branch 'master' into bound-datasets

# Conflicts:
#	tests/.snapshots/success.txt
This commit is contained in:
luke
2021-07-31 23:27:38 +01:00
4 changed files with 47 additions and 15 deletions

View File

@ -8,7 +8,7 @@ jobs:
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, macos-latest, windows-latest] os: [ubuntu-latest, macos-latest, windows-latest]
php: ['7.3', '7.4', '8.0'] php: ['7.3', '7.4', '8.0', '8.1']
dependency-version: [prefer-lowest, prefer-stable] dependency-version: [prefer-lowest, prefer-stable]
name: PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} name: PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}

View File

@ -266,15 +266,17 @@ final class Expectation
/** /**
* Asserts that $needle is an element of the value. * 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)) { if (is_string($this->value)) {
Assert::assertStringContainsString($needle, $this->value); Assert::assertStringContainsString($needle, $this->value);
} else { } else {
Assert::assertContains($needle, $this->value); Assert::assertContains($needle, $this->value);
} }
}
return $this; return $this;
} }

View File

@ -96,11 +96,6 @@
✓ more than two datasets with (2) / (4) / (5) ✓ more than two datasets with (2) / (4) / (5)
✓ more than two datasets with (2) / (4) / (6) ✓ more than two datasets with (2) / (4) / (6)
✓ more than two datasets did the job right ✓ more than two datasets did the job right
✓ it can resolve a dataset after the test case is available with (Closure Object (...))
✓ it can resolve a dataset after the test case is available with shared yield sets with (Closure Object (...)) #1
✓ it can resolve a dataset after the test case is available with shared yield sets with (Closure Object (...)) #2
✓ it can resolve a dataset after the test case is available with shared array sets with (Closure Object (...)) #1
✓ it can resolve a dataset after the test case is available with shared array sets with (Closure Object (...)) #2
PASS Tests\Features\Exceptions PASS Tests\Features\Exceptions
✓ it gives access the the underlying expectException ✓ it gives access the the underlying expectException
@ -330,9 +325,16 @@
PASS Tests\Features\Expect\toContain PASS Tests\Features\Expect\toContain
✓ passes strings ✓ passes strings
✓ passes strings with multiple needles
✓ passes arrays ✓ passes arrays
✓ passes arrays with multiple needles
✓ passes with array needles
✓ failures ✓ failures
✓ failures with multiple needles (all failing)
✓ failures with multiple needles (some failing)
✓ not failures ✓ not failures
✓ not failures with multiple needles (all failing)
✓ not failures with multiple needles (some failing)
PASS Tests\Features\Expect\toEndWith PASS Tests\Features\Expect\toEndWith
✓ pass ✓ pass
@ -606,5 +608,5 @@
✓ it is a test ✓ it is a test
✓ it uses correct parent class ✓ it uses correct parent class
Tests: 4 incompleted, 9 skipped, 386 passed Tests: 4 incompleted, 9 skipped, 388 passed

View File

@ -3,17 +3,45 @@
use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\ExpectationFailedException;
test('passes strings', function () { 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 () { 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 () { test('failures', function () {
expect([1, 2, 42])->toContain(3); expect([1, 2, 42])->toContain(3);
})->throws(ExpectationFailedException::class); })->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 () { test('not failures', function () {
expect([1, 2, 42])->not->toContain(42); expect([1, 2, 42])->not->toContain(42);
})->throws(ExpectationFailedException::class); })->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);