From 997b0e936854c9cad887cc9b3c809bd9c3437ed6 Mon Sep 17 00:00:00 2001 From: Maurizio Date: Thu, 17 Aug 2023 20:49:40 +0200 Subject: [PATCH] feat: add `toBeStudlyCase` --- src/Mixins/Expectation.php | 12 ++++++++++++ tests/Features/Expect/toBeStudlyCase.php | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 tests/Features/Expect/toBeStudlyCase.php diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index d667f854..a51718a0 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -1045,4 +1045,16 @@ final class Expectation return $this; } + + /** + * Asserts that the value is StudlyCase. + * + * @return self + */ + public function toBeStudlyCase(string $message = ''): self + { + Assert::assertTrue((bool) preg_match('/^\p{Lu}+\p{Ll}[\p{Ll}\p{Lu}]+$/u', (string) $this->value), $message); + + return $this; + } } diff --git a/tests/Features/Expect/toBeStudlyCase.php b/tests/Features/Expect/toBeStudlyCase.php new file mode 100644 index 00000000..af6391dc --- /dev/null +++ b/tests/Features/Expect/toBeStudlyCase.php @@ -0,0 +1,23 @@ +toBeStudlyCase(); + expect('AbcDef')->toBeStudlyCase(); + expect('abc-def')->not->toBeStudlyCase(); + expect('abc-def')->not->toBeStudlyCase(); + expect('abc')->not->toBeStudlyCase(); +}); + +test('failures', function () { + expect('abc')->toBeStudlyCase(); +})->throws(ExpectationFailedException::class); + +test('failures with custom message', function () { + expect('abc')->toBeStudlyCase('oh no!'); +})->throws(ExpectationFailedException::class, 'oh no!'); + +test('not failures', function () { + expect('AbcDef')->not->toBeStudlyCase(); +})->throws(ExpectationFailedException::class);