feat(arch): Adds support for opposite expectations of toHavePrefix and toHaveSuffix.

This commit is contained in:
Luke Downing
2023-07-31 11:28:53 +01:00
parent b795a92840
commit 6886558ed1
9 changed files with 96 additions and 7 deletions

View File

@ -595,12 +595,12 @@ final class Expectation
/**
* Asserts that the given expectation target to have the given suffix.
*/
public function toHavePrefix(string $suffix): ArchExpectation
public function toHavePrefix(string $prefix): ArchExpectation
{
return Targeted::make(
$this,
fn (ObjectDescription $object): bool => str_starts_with($object->reflectionClass->getName(), $suffix),
"to have prefix '{$suffix}'",
fn (ObjectDescription $object): bool => str_starts_with($object->reflectionClass->getShortName(), $prefix),
"to have prefix '{$prefix}'",
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')),
);
}