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

Breadcrumb

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

class Invocation

@no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit

@internal This class is not covered by the backward compatibility promise for PHPUnit

Hierarchy

  • class \PHPUnit\Framework\MockObject\Invocation implements \PHPUnit\Framework\SelfDescribing

Expanded class hierarchy of Invocation

19 files declare their use of Invocation
AnyInvokedCount.php in vendor/phpunit/phpunit/src/Framework/MockObject/Runtime/Rule/AnyInvokedCount.php
AnyParameters.php in vendor/phpunit/phpunit/src/Framework/MockObject/Runtime/Rule/AnyParameters.php
ConsecutiveCalls.php in vendor/phpunit/phpunit/src/Framework/MockObject/Runtime/Stub/ConsecutiveCalls.php
Exception.php in vendor/phpunit/phpunit/src/Framework/MockObject/Runtime/Stub/Exception.php
InvocationOrder.php in vendor/phpunit/phpunit/src/Framework/MockObject/Runtime/Rule/InvocationOrder.php

... See full list

File

vendor/phpunit/phpunit/src/Framework/MockObject/Runtime/Invocation.php, line 28

Namespace

PHPUnit\Framework\MockObject
View source
final class Invocation implements SelfDescribing {
    
    /**
     * @psalm-var class-string
     */
    private readonly string $className;
    
    /**
     * @psalm-var non-empty-string
     */
    private readonly string $methodName;
    private readonly array $parameters;
    private readonly string $returnType;
    private readonly bool $isReturnTypeNullable;
    private readonly bool $proxiedCall;
    private readonly MockObjectInternal|StubInternal $object;
    
    /**
     * @psalm-param class-string $className
     * @psalm-param non-empty-string $methodName
     */
    public function __construct(string $className, string $methodName, array $parameters, string $returnType, MockObjectInternal|StubInternal $object, bool $cloneObjects = false, bool $proxiedCall = false) {
        $this->className = $className;
        $this->methodName = $methodName;
        $this->object = $object;
        $this->proxiedCall = $proxiedCall;
        if (strtolower($methodName) === '__tostring') {
            $returnType = 'string';
        }
        if (str_starts_with($returnType, '?')) {
            $returnType = substr($returnType, 1);
            $this->isReturnTypeNullable = true;
        }
        else {
            $this->isReturnTypeNullable = false;
        }
        $this->returnType = $returnType;
        if (!$cloneObjects) {
            $this->parameters = $parameters;
            return;
        }
        foreach ($parameters as $key => $value) {
            if (is_object($value)) {
                $parameters[$key] = Cloner::clone($value);
            }
        }
        $this->parameters = $parameters;
    }
    
    /**
     * @psalm-return class-string
     */
    public function className() : string {
        return $this->className;
    }
    
    /**
     * @psalm-return non-empty-string
     */
    public function methodName() : string {
        return $this->methodName;
    }
    public function parameters() : array {
        return $this->parameters;
    }
    
    /**
     * @throws Exception
     */
    public function generateReturnValue() : mixed {
        if ($this->returnType === 'never') {
            throw new NeverReturningMethodException($this->className, $this->methodName);
        }
        if ($this->isReturnTypeNullable || $this->proxiedCall) {
            return null;
        }
        return (new ReturnValueGenerator())->generate($this->className, $this->methodName, $this->object::class, $this->returnType);
    }
    public function toString() : string {
        $exporter = new Exporter();
        return sprintf('%s::%s(%s)%s', $this->className, $this->methodName, implode(', ', array_map([
            $exporter,
            'shortenedExport',
        ], $this->parameters)), $this->returnType ? sprintf(': %s', $this->returnType) : '');
    }
    public function object() : MockObjectInternal|StubInternal {
        return $this->object;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
Invocation::$className private property @psalm-var class-string
Invocation::$isReturnTypeNullable private property
Invocation::$methodName private property @psalm-var non-empty-string
Invocation::$object private property
Invocation::$parameters private property
Invocation::$proxiedCall private property
Invocation::$returnType private property
Invocation::className public function @psalm-return class-string
Invocation::generateReturnValue public function
Invocation::methodName public function @psalm-return non-empty-string
Invocation::object public function
Invocation::parameters public function
Invocation::toString public function Returns a string representation of the object. Overrides SelfDescribing::toString
Invocation::__construct public function @psalm-param class-string $className
@psalm-param non-empty-string $methodName

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal