Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue with integer indexed form children #7985

Merged
merged 2 commits into from
Dec 8, 2022
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
6 changes: 3 additions & 3 deletions src/Util/FormBuilderIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class FormBuilderIterator extends \RecursiveArrayIterator
private string $prefix;

/**
* @var \ArrayIterator<string|int, string>
* @var \ArrayIterator<string|int, string|int>
*/
private \ArrayIterator $iterator;

Expand Down Expand Up @@ -64,7 +64,7 @@ public function next(): void

public function current(): FormBuilderInterface
{
return $this->formBuilder->get($this->iterator->current());
return $this->formBuilder->get((string) $this->iterator->current());
}

public function getChildren(): self
Expand All @@ -78,7 +78,7 @@ public function hasChildren(): bool
}

/**
* @return array<string|int, string>
* @return array<string|int, string|int>
*/
private static function getKeys(FormBuilderInterface $formBuilder): array
{
Expand Down
11 changes: 10 additions & 1 deletion tests/Functional/Translator/Extractor/AdminExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ final class AdminExtractorTest extends KernelTestCase
public function testDebugMissingMessages(): void
{
$tester = $this->createCommandTester();
$tester->execute(['locale' => 'en']);
try {
$tester->execute(['locale' => 'en']);
} catch (\Throwable $t) {
// until https://github.com/symfony/symfony/issues/48422 is fixed
if (false !== strpos($t->getMessage(), 'Undefined property: PhpParser\Node\VariadicPlaceholder')) {
static::markTestSkipped();
}

throw $t;
}

static::assertMatchesRegularExpression('/group_label/', $tester->getDisplay());
static::assertMatchesRegularExpression('/admin_label/', $tester->getDisplay());
Expand Down
2 changes: 1 addition & 1 deletion tests/Twig/Extension/XEditableExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class XEditableExtensionTest extends TestCase
* @param array<string, mixed> $options
* @param array<array<string, string>> $expectedChoices
*
* @dataProvider xEditablechoicesProvider
* @dataProvider xEditableChoicesProvider
*/
public function testGetXEditableChoicesIsIdempotent(array $options, array $expectedChoices): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Twig/XEditableRuntimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class XEditableRuntimeTest extends TestCase
* @param array<string, mixed> $options
* @param array<array<string, string>> $expectedChoices
*
* @dataProvider xEditablechoicesProvider
* @dataProvider xEditableChoicesProvider
*/
public function testGetXEditableChoicesIsIdempotent(array $options, array $expectedChoices): void
{
Expand Down
8 changes: 8 additions & 0 deletions tests/Util/FormBuilderIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormFactoryInterface;

/**
Expand Down Expand Up @@ -53,4 +54,11 @@ public function testHasChildren(): void
$iterator = new FormBuilderIterator($this->builder);
static::assertTrue($iterator->hasChildren());
}

public function testCurrentWithIntegerIndexedChildren(): void
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fails without the fix

There was 1 error:

1) Sonata\AdminBundle\Tests\Util\FormBuilderIteratorTest::testCurrentWithIntegerIndexedChildren
TypeError: Symfony\Component\Form\FormBuilder::get(): Argument #1 ($name) must be of type string, int given, called in /var/www/SonataAdminBundle/src/Util/FormBuilderIterator.php on line 67

/var/www/SonataAdminBundle/vendor/symfony/form/FormBuilder.php:91
/var/www/SonataAdminBundle/src/Util/FormBuilderIterator.php:67
/var/www/SonataAdminBundle/tests/Util/FormBuilderIteratorTest.php:62
/var/www/SonataAdminBundle/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
/var/www/SonataAdminBundle/vendor/phpunit/phpunit/src/Framework/TestSuite.php:673
/var/www/SonataAdminBundle/vendor/phpunit/phpunit/src/Framework/TestSuite.php:673
/var/www/SonataAdminBundle/vendor/phpunit/phpunit/src/Framework/TestSuite.php:673

{
$this->builder->add('0', TextType::class);
$iterator = new FormBuilderIterator($this->builder);
static::assertInstanceOf(FormBuilderInterface::class, $iterator->current());
}
}