diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e8df237..ba038c5 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -17,3 +17,33 @@ parameters: identifier: missingType.generics count: 1 path: src/Symfony/Helper/FormAssertion.php + + - + message: '#^Method PHPUnit\\Framework\\MockObject\\Generator\\Generator\:\:testDouble\(\) invoked with named argument \$allowMockingUnknownTypes, but it''s not allowed because of @no\-named\-arguments\.$#' + identifier: argument.named + count: 2 + path: src/Symfony/Helper/FormAssertion.php + + - + message: '#^Method PHPUnit\\Framework\\MockObject\\Generator\\Generator\:\:testDouble\(\) invoked with named argument \$callOriginalClone, but it''s not allowed because of @no\-named\-arguments\.$#' + identifier: argument.named + count: 3 + path: src/Symfony/Helper/FormAssertion.php + + - + message: '#^Method PHPUnit\\Framework\\MockObject\\Generator\\Generator\:\:testDouble\(\) invoked with named argument \$callOriginalConstructor, but it''s not allowed because of @no\-named\-arguments\.$#' + identifier: argument.named + count: 3 + path: src/Symfony/Helper/FormAssertion.php + + - + message: '#^Method PHPUnit\\Framework\\MockObject\\Generator\\Generator\:\:testDouble\(\) invoked with named argument \$cloneArguments, but it''s not allowed because of @no\-named\-arguments\.$#' + identifier: argument.named + count: 2 + path: src/Symfony/Helper/FormAssertion.php + + - + message: '#^Parameter \#3 \$methods of method PHPUnit\\Framework\\MockObject\\Generator\\Generator\:\:testDouble\(\) expects array\|null, false given\.$#' + identifier: argument.type + count: 1 + path: src/Symfony/Helper/FormAssertion.php diff --git a/src/Symfony/AbstractControllerTestCase.php b/src/Symfony/AbstractControllerTestCase.php index 249f928..a9fc82b 100644 --- a/src/Symfony/AbstractControllerTestCase.php +++ b/src/Symfony/AbstractControllerTestCase.php @@ -86,7 +86,7 @@ public function expectCreateForm(string $type, mixed $data = null, array $option $this->container->set('form.factory', $factory); - return new FormAssertion($form, $this); + return new FormAssertion($form); } public function expectAddFlash(string $type, mixed $message): void diff --git a/src/Symfony/Helper/FormAssertion.php b/src/Symfony/Helper/FormAssertion.php index 7290873..2d975a9 100644 --- a/src/Symfony/Helper/FormAssertion.php +++ b/src/Symfony/Helper/FormAssertion.php @@ -4,9 +4,9 @@ namespace DR\PHPUnitExtensions\Symfony\Helper; -use PHPUnit\Framework\MockObject\MockBuilder; +use PHPUnit\Framework\MockObject\Generator\Generator as MockGenerator; use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase; +use PHPUnit\Runner\Version; use RuntimeException; use Symfony\Component\Form\FormConfigInterface; use Symfony\Component\Form\FormError; @@ -21,10 +21,9 @@ class FormAssertion { /** * @internal Instance should not be made directly, use AbstractControllerTestCase::expectCreateForm - * - * @see AbstractControllerTestCase::expectCreateForm + * @see AbstractControllerTestCase::expectCreateForm */ - public function __construct(public readonly FormInterface&MockObject $form, private readonly TestCase $testCase) + public function __construct(public readonly FormInterface&MockObject $form) { } @@ -60,10 +59,34 @@ function (string $key) use ($keyValueData) { // @codeCoverageIgnoreEnd } - $mock = (new MockBuilder($this->testCase, FormInterface::class))->getMock(); - $mock->method('getData')->willReturn($keyValueData[$key]); + // @codeCoverageIgnoreStart + $generator = new MockGenerator(); + if (Version::majorVersionNumber() === 10) { + $stub = $generator->testDouble( + FormInterface::class, + true, + callOriginalConstructor: false, + callOriginalClone: false, + cloneArguments: false, + allowMockingUnknownTypes: false, + ); + } elseif (Version::majorVersionNumber() === 11) { + $stub = $generator->testDouble( + FormInterface::class, + true, + false, + callOriginalConstructor: false, + callOriginalClone: false, + cloneArguments: false, + allowMockingUnknownTypes: false, + ); + } else { + $stub = $generator->testDouble(FormInterface::class, false, callOriginalConstructor: false, callOriginalClone: false); + } + // @codeCoverageIgnoreEnd + $stub->method('getData')->willReturn($keyValueData[$key]); - return $mock; + return $stub; } );