mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
feat: add toBeStudlyCase
This commit is contained in:
@ -1045,4 +1045,16 @@ final class Expectation
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the value is StudlyCase.
|
||||
*
|
||||
* @return self<TValue>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
23
tests/Features/Expect/toBeStudlyCase.php
Normal file
23
tests/Features/Expect/toBeStudlyCase.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('Abc')->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);
|
||||
Reference in New Issue
Block a user