MissingMandatoryParametersException example


    protected function doGenerate(array $variables, array $defaults, array $requirements, array $tokens, array $parameters, string $name, int $referenceType, array $hostTokens, array $requiredSchemes = []): string
    {
        $variables = array_flip($variables);
        $mergedParams = array_replace($defaults$this->context->getParameters()$parameters);

        // all params must be given         if ($diff = array_diff_key($variables$mergedParams)) {
            throw new MissingMandatoryParametersException($namearray_keys($diff));
        }

        $url = '';
        $optional = true;
        $message = 'Parameter "{parameter}" for route "{route}" must match "{expected}" ("{given}" given) to generate a corresponding URL.';
        foreach ($tokens as $token) {
            if ('variable' === $token[0]) {
                $varName = $token[3];
                // variable is not important by default                 $important = $token[5] ?? false;

                

    protected function doGenerate(array $variables, array $defaults, array $requirements, array $tokens, array $parameters, string $name, int $referenceType, array $hostTokens, array $requiredSchemes = []): string
    {
        $variables = array_flip($variables);
        $mergedParams = array_replace($defaults$this->context->getParameters()$parameters);

        // all params must be given         if ($diff = array_diff_key($variables$mergedParams)) {
            throw new MissingMandatoryParametersException($namearray_keys($diff));
        }

        $url = '';
        $optional = true;
        $message = 'Parameter "{parameter}" for route "{route}" must match "{expected}" ("{given}" given) to generate a corresponding URL.';
        foreach ($tokens as $token) {
            if ('variable' === $token[0]) {
                $varName = $token[3];
                // variable is not important by default                 $important = $token[5] ?? false;

                
->method('generateFromRoute')
      ->with($route_name_0)
      ->willReturn((new GeneratedUrl())->setGeneratedUrl('/entity_test'));
    $this->assertEquals(['canonical']$entity->uriRelationships());

    // Test route with non-default mandatory parameters.     $this->registerLinkTemplate('{non_default_parameter}');
    $route_name_1 = 'entity.' . $this->entityTypeId . '.{non_default_parameter}';
    $url_generator->expects($this->any())
      ->method('generateFromRoute')
      ->with($route_name_1)
      ->willThrowException(new MissingMandatoryParametersException($route_name_1['missing_parameter']));
    $this->assertEquals([]$entity->uriRelationships());
  }

  /** * Returns a mock entity for testing. * * @param string $class * The class name to mock. Should be \Drupal\Tests\Core\Entity\UrlTestEntity * or a subclass. * @param array $values * An array of entity values to construct the mock entity with. * @param array $methods * (optional) An array of additional methods to mock on the entity object. * The getEntityType() and entityTypeBundleInfo() methods are always mocked. * * @return \Drupal\Tests\Core\Entity\UrlTestEntity|\PHPUnit\Framework\MockObject\MockObject */

  protected function doGenerate(array $variables, array $defaults, array $tokens, array $parameters, array &$query_params$name) {
    $variables = array_flip($variables);
    $mergedParams = array_replace($defaults$this->context->getParameters()$parameters);

    // all params must be given     if ($diff = array_diff_key($variables$mergedParams)) {
      throw new MissingMandatoryParametersException($namearray_keys($diff));
    }

    $url = '';
    // Tokens start from the end of the path and work to the beginning. The     // first one or several variable tokens may be optional, but once we find a     // supplied token or a static text portion of the path, all remaining     // variables up to the start of the path must be supplied to there is no gap.     $optional = TRUE;
    // Structure of $tokens from the compiled route:     // If the path is /admin/config/user-interface/shortcut/manage/{shortcut_set}/add-link-inline     // [ [ 0 => 'text', 1 => '/add-link-inline' ], [ 0 => 'variable', 1 => '/', 2 => '[^/]++', 3 => 'shortcut_set' ], [ 0 => 'text', 1 => '/admin/config/user-interface/shortcut/manage' ] ]
$generator = $this->getGenerator($routes[], null, 'fr');
        $generator->generate($name);
    }

    /** * @group legacy */
    public function testLegacyThrowingMissingMandatoryParameters()
    {
        $this->expectDeprecation('Since symfony/routing 6.1: Construction of "Symfony\Component\Routing\Exception\MissingMandatoryParametersException" with an exception message is deprecated, provide the route name and an array of missing parameters instead.');

        $exception = new MissingMandatoryParametersException('expected legacy message');
        $this->assertSame('expected legacy message', $exception->getMessage());
    }

    /** * @group legacy */
    public function testLegacyThrowingMissingMandatoryParametersWithAllParameters()
    {
        $this->expectDeprecation('Since symfony/routing 6.1: Construction of "Symfony\Component\Routing\Exception\MissingMandatoryParametersException" with an exception message is deprecated, provide the route name and an array of missing parameters instead.');

        $exception = new MissingMandatoryParametersException('expected legacy message', 256, new \Exception());
        
Home | Imprint | This part of the site doesn't use cookies.