Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/Symfony/AbstractControllerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 31 additions & 8 deletions src/Symfony/Helper/FormAssertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
}

Expand Down Expand Up @@ -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,
Comment thread
frankdekker marked this conversation as resolved.
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;
}
);

Expand Down