Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. MockBuilder.php

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

CannotUseOnlyMethodsException

ReflectionException

File

vendor/phpunit/phpunit/src/Framework/MockObject/MockBuilder.php, line 194

Class

MockBuilder
@psalm-template MockedType

Namespace

PHPUnit\Framework\MockObject

Code

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;
}
RSS feed
Powered by Drupal