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