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

Breadcrumb

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

class Parameters

@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\Rule\Parameters implements \PHPUnit\Framework\MockObject\Rule\ParametersRule

Expanded class hierarchy of Parameters

34 string references to 'Parameters'
ConfigEntityMapper::processRoute in core/modules/config_translation/src/ConfigEntityMapper.php
Allows to process all config translation routes.
ContentModerationRouteSubscriber::setLatestRevisionFlag in core/modules/content_moderation/src/Routing/ContentModerationRouteSubscriber.php
Ensure revisionable entities load the latest revision on entity forms.
ContentTranslationHooks::pageAttachments in core/modules/content_translation/src/Hook/ContentTranslationHooks.php
Implements hook_page_attachments().
d6_action.yml in core/modules/system/migrations/d6_action.yml
core/modules/system/migrations/d6_action.yml
d7_action.yml in core/modules/system/migrations/d7_action.yml
core/modules/system/migrations/d7_action.yml

... See full list

File

vendor/phpunit/phpunit/src/Framework/MockObject/Runtime/Rule/Parameters.php, line 27

Namespace

PHPUnit\Framework\MockObject\Rule
View source
final class Parameters implements ParametersRule {
    
    /**
     * @psalm-var list<Constraint>
     */
    private array $parameters = [];
    private ?BaseInvocation $invocation = null;
    private null|bool|ExpectationFailedException $parameterVerificationResult;
    
    /**
     * @throws \PHPUnit\Framework\Exception
     */
    public function __construct(array $parameters) {
        foreach ($parameters as $parameter) {
            if (!$parameter instanceof Constraint) {
                $parameter = new IsEqual($parameter);
            }
            $this->parameters[] = $parameter;
        }
    }
    
    /**
     * @throws Exception
     */
    public function apply(BaseInvocation $invocation) : void {
        $this->invocation = $invocation;
        $this->parameterVerificationResult = null;
        try {
            $this->parameterVerificationResult = $this->doVerify();
        } catch (ExpectationFailedException $e) {
            $this->parameterVerificationResult = $e;
            throw $this->parameterVerificationResult;
        }
    }
    
    /**
     * Checks if the invocation $invocation matches the current rules. If it
     * does the rule will get the invoked() method called which should check
     * if an expectation is met.
     *
     * @throws ExpectationFailedException
     */
    public function verify() : void {
        $this->doVerify();
    }
    
    /**
     * @throws ExpectationFailedException
     */
    private function doVerify() : bool {
        if (isset($this->parameterVerificationResult)) {
            return $this->guardAgainstDuplicateEvaluationOfParameterConstraints();
        }
        if ($this->invocation === null) {
            throw new ExpectationFailedException('Mocked method does not exist.');
        }
        if (count($this->invocation
            ->parameters()) < count($this->parameters)) {
            $message = 'Parameter count for invocation %s is too low.';
            // The user called `->with($this->anything())`, but may have meant
            // `->withAnyParameters()`.
            //
            // @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/199
            if (count($this->parameters) === 1 && $this->parameters[0]::class === IsAnything::class) {
                $message .= "\nTo allow 0 or more parameters with any value, omit ->with() or use ->withAnyParameters() instead.";
            }
            throw new ExpectationFailedException(sprintf($message, $this->invocation
                ->toString()));
        }
        foreach ($this->parameters as $i => $parameter) {
            if ($parameter instanceof Callback && $parameter->isVariadic()) {
                $other = $this->invocation
                    ->parameters();
            }
            else {
                $other = $this->invocation
                    ->parameters()[$i];
            }
            $parameter->evaluate($other, sprintf('Parameter %s for invocation %s does not match expected ' . 'value.', $i, $this->invocation
                ->toString()));
        }
        return true;
    }
    
    /**
     * @throws ExpectationFailedException
     */
    private function guardAgainstDuplicateEvaluationOfParameterConstraints() : bool {
        if ($this->parameterVerificationResult instanceof ExpectationFailedException) {
            throw $this->parameterVerificationResult;
        }
        return (bool) $this->parameterVerificationResult;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
Parameters::$invocation private property
Parameters::$parameters private property @psalm-var list&lt;Constraint&gt;
Parameters::$parameterVerificationResult private property
Parameters::apply public function Overrides ParametersRule::apply
Parameters::doVerify private function
Parameters::guardAgainstDuplicateEvaluationOfParameterConstraints private function
Parameters::verify public function Checks if the invocation $invocation matches the current rules. If it
does the rule will get the invoked() method called which should check
if an expectation is met.
Overrides ParametersRule::verify
Parameters::__construct public function

API Navigation

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