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