feat: toHaveAttribute expectation

This commit is contained in:
Thai Nguyen Hung
2023-08-24 14:26:54 +07:00
parent 14859a4c89
commit 678898efe7
6 changed files with 84 additions and 0 deletions

View File

@ -833,4 +833,19 @@ final class Expectation
return $this;
}
/**
* Asserts that the given expectation target to have the given attribute.
*
* @param class-string $attribute
*/
public function toHaveAttribute(string $attribute): ArchExpectation
{
return Targeted::make(
$this,
fn (ObjectDescription $object): bool => $object->reflectionClass->getAttributes($attribute) !== [],
"to have attribute '{$attribute}'",
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')),
);
}
}