From 2751bc9674f49e31f1abc0a35cc7ef9c0b367d6f Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Wed, 15 Jul 2020 00:57:31 +0200 Subject: [PATCH] feat(expect): fixes to contain with strings --- src/Expectation.php | 2 +- tests/.snapshots/success.txt | 7 ++++--- tests/Expect/toContain.php | 6 +++++- 3 files changed, 10 insertions(+), 5 deletions(-) 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);