From 16b9f54dc37f4389759b71fbe48852f959ba1f30 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Wed, 16 Sep 2020 18:56:16 +0100 Subject: [PATCH 1/3] feat(expectations): add toMatchRegEx --- src/Expectation.php | 10 ++++++++++ tests/Expect/toMatchRegEx.php | 15 +++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/Expect/toMatchRegEx.php diff --git a/src/Expectation.php b/src/Expectation.php index fcd54a75..98a743f2 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -505,6 +505,16 @@ final class Expectation return $this; } + /** + * Asserts that the value matches a regular expression. + */ + public function toMatchRegEx(string $expression): Expectation + { + Assert::assertMatchesRegularExpression($expression, $this->value); + + return $this; + } + /** * Asserts that the value matches a constraint. */ diff --git a/tests/Expect/toMatchRegEx.php b/tests/Expect/toMatchRegEx.php new file mode 100644 index 00000000..1bc98667 --- /dev/null +++ b/tests/Expect/toMatchRegEx.php @@ -0,0 +1,15 @@ +toMatchRegEx('/^hello wo.*$/i'); +}); + +test('failures', function () { + expect('Hello World')->toMatchRegEx('/^hello$/i'); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect('Hello World')->not->toMatchRegEx('/^hello wo.*$/i'); +})->throws(ExpectationFailedException::class); From f76f353c3245ff420f16e6ec7c212fff6f1b9501 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Wed, 16 Sep 2020 19:03:56 +0100 Subject: [PATCH 2/3] chore: update snapshots --- tests/.snapshots/success.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 1a605a1b..ceccdcb0 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -205,6 +205,11 @@ PASS Tests\Expect\toMatchObject ✓ pass ✓ failures + ✓ not failures + + PASS Tests\Expect\toMatchRegEx + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toStartWith From e3e4815b55e77fabd6044ed7dff1e47ee0f1ca74 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Mon, 21 Sep 2020 16:02:08 +0100 Subject: [PATCH 3/3] chore(expectations): rename 'toMatchRegEx' to 'toMatch' --- src/Expectation.php | 2 +- tests/.snapshots/success.txt | 12 ++++++------ tests/Expect/{toMatchRegEx.php => toMatch.php} | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) rename tests/Expect/{toMatchRegEx.php => toMatch.php} (58%) diff --git a/src/Expectation.php b/src/Expectation.php index 98a743f2..3b60d52d 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -508,7 +508,7 @@ final class Expectation /** * Asserts that the value matches a regular expression. */ - public function toMatchRegEx(string $expression): Expectation + public function toMatch(string $expression): Expectation { Assert::assertMatchesRegularExpression($expression, $this->value); diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index ceccdcb0..fe192a07 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -195,6 +195,11 @@ PASS Tests\Expect\toHaveProperty ✓ pass ✓ failures + ✓ not failures + + PASS Tests\Expect\toMatch + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toMatchConstraint @@ -205,11 +210,6 @@ PASS Tests\Expect\toMatchObject ✓ pass ✓ failures - ✓ not failures - - PASS Tests\Expect\toMatchRegEx - ✓ pass - ✓ failures ✓ not failures PASS Tests\Expect\toStartWith @@ -383,5 +383,5 @@ ✓ depends with defined arguments ✓ depends run test only once - Tests: 6 skipped, 223 passed + Tests: 6 skipped, 226 passed \ No newline at end of file diff --git a/tests/Expect/toMatchRegEx.php b/tests/Expect/toMatch.php similarity index 58% rename from tests/Expect/toMatchRegEx.php rename to tests/Expect/toMatch.php index 1bc98667..9088a3c4 100644 --- a/tests/Expect/toMatchRegEx.php +++ b/tests/Expect/toMatch.php @@ -3,13 +3,13 @@ use PHPUnit\Framework\ExpectationFailedException; test('pass', function () { - expect('Hello World')->toMatchRegEx('/^hello wo.*$/i'); + expect('Hello World')->toMatch('/^hello wo.*$/i'); }); test('failures', function () { - expect('Hello World')->toMatchRegEx('/^hello$/i'); + expect('Hello World')->toMatch('/^hello$/i'); })->throws(ExpectationFailedException::class); test('not failures', function () { - expect('Hello World')->not->toMatchRegEx('/^hello wo.*$/i'); + expect('Hello World')->not->toMatch('/^hello wo.*$/i'); })->throws(ExpectationFailedException::class);