feat: add toBeKebabCase

This commit is contained in:
Maurizio
2023-08-17 20:48:51 +02:00
parent 4951b1b0f9
commit d2096df82a
2 changed files with 35 additions and 0 deletions

View File

@ -1021,4 +1021,16 @@ final class Expectation
return $this; 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;
}
} }

View 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);