mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
refacto: toHaveMethod and toHaveMethods
This commit is contained in:
@ -214,17 +214,34 @@ final class OppositeExpectation
|
||||
|
||||
/**
|
||||
* Asserts that the given expectation target does not have a specific method.
|
||||
*
|
||||
* @param array<int, string>|string $method
|
||||
*/
|
||||
public function toHaveMethod(string $method): ArchExpectation
|
||||
public function toHaveMethod(array|string $method): ArchExpectation
|
||||
{
|
||||
$methods = is_array($method) ? $method : [$method];
|
||||
|
||||
return Targeted::make(
|
||||
$this->original,
|
||||
fn (ObjectDescription $object): bool => ! $object->reflectionClass->hasMethod($method),
|
||||
'to not have method',
|
||||
fn (ObjectDescription $object): bool => array_filter(
|
||||
$methods,
|
||||
fn (string $method): bool => $object->reflectionClass->hasMethod($method),
|
||||
) === [],
|
||||
'to not have methods: '.implode(', ', $methods),
|
||||
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given expectation target does not have the given methods.
|
||||
*
|
||||
* @param array<int, string> $methods
|
||||
*/
|
||||
public function toHaveMethods(array $methods): ArchExpectation
|
||||
{
|
||||
return $this->toHaveMethod($methods);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given expectation target not to have the public methods besides the given methods.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user