start covers attribute implementation

This commit is contained in:
danilopolani
2022-03-04 22:28:37 +01:00
parent 74470ec96d
commit 7660517f7c
3 changed files with 74 additions and 1 deletions

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Pest\PendingCalls;
use Closure;
use InvalidArgumentException;
use Pest\Factories\TestCaseMethodFactory;
use Pest\Support\Backtrace;
use Pest\Support\HigherOrderCallables;
@ -168,6 +169,25 @@ final class TestCall
return $this;
}
/**
* Sets the covered class and method.
*/
public function covers(string|array ...$classes): TestCall
{
foreach ($classes as $i => $class) {
if (is_array($class) && count($class) !== 2) {
throw new InvalidArgumentException(sprintf(
'The #%s covered class must be an array with exactly 2 items: class and method name.',
$i
));
}
$this->testCaseMethod->covers[] = $class;
}
return $this;
}
/**
* Saves the property accessors to be used on the target.
*/