Skip to content
Snippets Groups Projects
Commit d9f9fdd9 authored by Kévin Le lostec's avatar Kévin Le lostec Committed by Frédéric G. Marand
Browse files

Issue #3364256 by klelostec: PHP Fatal error due to FormStateValueResolver

parent f62cf78b
No related branches found
No related tags found
1 merge request!3Fix FormStateValueResolver which dont need to resolve argument types other...
......@@ -23,7 +23,7 @@ class FormStateValueResolver implements ArgumentValueResolverInterface {
public function supports(Request $request, ArgumentMetadata $argument): bool {
$argumentInterfaceMatches = $argument->getType() === FormStateInterface::class;
$requestAttributeExists = $request->attributes->has(static::NAME_LEGACY);
return $argumentInterfaceMatches || $requestAttributeExists;
return $argumentInterfaceMatches && $requestAttributeExists;
}
/**
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\mongodb_watchdog\Unit;
use Drupal\Core\Form\FormState;
use Drupal\Core\Form\FormStateInterface;
use Drupal\mongodb_watchdog\Controller\ArgumentResolver\FormStateValueResolver;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
/**
* Test the FormStateValueResolver mechanisms.
*
* @coversDefaultClass \Drupal\mongodb_watchdog\Controller\ArgumentResolver\FormStateValueResolver
*
* @group mongodb
*/
class FormStateValueResolverTest extends UnitTestCase {
/**
* Test formState argument resolution.
*
* @covers ::supports
*/
public function testFormStateArgumentResolver() {
$resolver = new FormStateValueResolver();
$request = new Request();
$request->attributes->add([FormStateValueResolver::NAME_LEGACY => new FormState()]);
$argument = new ArgumentMetadata('formState', FormStateInterface::class, FALSE, FALSE, NULL, FALSE);
$this->assertEquals(TRUE, $resolver->supports($request, $argument));
}
/**
* Test extra optionnal argument resolution.
*
* @covers ::supports
*/
public function testOptionnalExtraArgumentResolver() {
$resolver = new FormStateValueResolver();
$request = new Request();
$request->attributes->add([FormStateValueResolver::NAME_LEGACY => new FormState()]);
$argument = new ArgumentMetadata('extra', NULL, FALSE, TRUE, '', TRUE);
$this->assertEquals(FALSE, $resolver->supports($request, $argument));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment