mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
add generic covers method to accept both classes and functions
This commit is contained in:
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Pest\PendingCalls;
|
||||
|
||||
use Closure;
|
||||
use InvalidArgumentException;
|
||||
use Pest\Factories\Covers\CoversClass;
|
||||
use Pest\Factories\Covers\CoversFunction;
|
||||
use Pest\Factories\Covers\CoversNothing;
|
||||
@ -171,6 +172,31 @@ final class TestCall
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the covered classes or methods.
|
||||
*/
|
||||
public function covers(string ...$classesOrFunctions): TestCall
|
||||
{
|
||||
foreach ($classesOrFunctions as $classOrFunction) {
|
||||
$isClass = class_exists($classOrFunction);
|
||||
$isMethod = function_exists($classOrFunction);
|
||||
|
||||
if (!$isClass && !$isMethod) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('No class or method named "%s" has been found.', $classOrFunction)
|
||||
);
|
||||
}
|
||||
|
||||
if ($isClass) {
|
||||
$this->coversClass($classOrFunction);
|
||||
} else {
|
||||
$this->coversFunction($classOrFunction);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the covered classes.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user