function MockBuilder::onlyMethods
Specifies the subset of methods to mock, requiring each to exist in the class.
@psalm-param list<non-empty-string> $methods
Return value
$this
Throws
File
-
vendor/
phpunit/ phpunit/ src/ Framework/ MockObject/ MockBuilder.php, line 194
Class
- MockBuilder
- @psalm-template MockedType
Namespace
PHPUnit\Framework\MockObjectCode
public function onlyMethods(array $methods) : self {
if (empty($methods)) {
$this->emptyMethodsArray = true;
return $this;
}
try {
$reflector = new ReflectionClass($this->type);
// @codeCoverageIgnoreStart
} catch (\ReflectionException $e) {
throw new ReflectionException($e->getMessage(), $e->getCode(), $e);
// @codeCoverageIgnoreEnd
}
foreach ($methods as $method) {
if (!$reflector->hasMethod($method)) {
throw new CannotUseOnlyMethodsException($this->type, $method);
}
}
$this->methods = array_merge($this->methods, $methods);
return $this;
}