mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
feat: add toBeCamelCase
This commit is contained in:
@ -1033,4 +1033,16 @@ final class Expectation
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the value is camelCase.
|
||||||
|
*
|
||||||
|
* @return self<TValue>
|
||||||
|
*/
|
||||||
|
public function toBeCamelCase(string $message = ''): self
|
||||||
|
{
|
||||||
|
Assert::assertTrue((bool) preg_match('/^\p{Ll}[\p{Ll}\p{Lu}]+$/u', (string) $this->value), $message);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
23
tests/Features/Expect/toBeCamelCase.php
Normal file
23
tests/Features/Expect/toBeCamelCase.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
test('pass', function () {
|
||||||
|
expect('abc')->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);
|
||||||
Reference in New Issue
Block a user