mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
feat: add toBeKebabCase
This commit is contained in:
@ -1021,4 +1021,16 @@ final class Expectation
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the value is kebab-case.
|
||||
*
|
||||
* @return self<TValue>
|
||||
*/
|
||||
public function toBeKebabCase(string $message = ''): self
|
||||
{
|
||||
Assert::assertTrue((bool) preg_match('/^[\p{Ll}-]+$/u', (string) $this->value), $message);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
23
tests/Features/Expect/toBeKebabCase.php
Normal file
23
tests/Features/Expect/toBeKebabCase.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('abc')->toBeKebabCase();
|
||||
expect('abc-def')->toBeKebabCase();
|
||||
expect('abc_def')->not->toBeKebabCase();
|
||||
expect('abcDef')->not->toBeKebabCase();
|
||||
expect('AbcDef')->not->toBeKebabCase();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect('Abc')->toBeKebabCase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect('Abc')->toBeKebabCase('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
expect('abc-def')->not->toBeKebabCase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
Reference in New Issue
Block a user