diff --git a/src/Expectation.php b/src/Expectation.php index 61ac5795..67d5aa9e 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -147,7 +147,7 @@ final class Expectation */ public function toContain($value): Expectation { - if (is_string($value)) { + if (is_string($this->value)) { Assert::assertStringContainsString($value, $this->value); } else { Assert::assertContains($value, $this->value); diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index f06d1d9f..9b6e5b25 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -119,7 +119,8 @@ ✓ not failures PASS Tests\Expect\toContain - ✓ passes + ✓ passes strings + ✓ passes arrays ✓ failures ✓ not failures @@ -308,5 +309,5 @@ WARN Tests\Visual\Success - visual snapshot of test suite on success - Tests: 6 skipped, 181 passed - Time: 5.70s + Tests: 6 skipped, 182 passed + Time: 5.72s diff --git a/tests/Expect/toContain.php b/tests/Expect/toContain.php index ce477fbf..04d586ff 100644 --- a/tests/Expect/toContain.php +++ b/tests/Expect/toContain.php @@ -2,10 +2,14 @@ use PHPUnit\Framework\ExpectationFailedException; -test('passes', function () { +test('passes strings', function () { expect([1, 2, 42])->toContain(42); }); +test('passes arrays', function () { + expect('Nuno')->toContain('Nu'); +}); + test('failures', function () { expect([1, 2, 42])->toContain(3); })->throws(ExpectationFailedException::class);