-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Cast field name to match parameter requirements #7983
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,27 +16,26 @@ | |
use PHPUnit\Framework\TestCase; | ||
use Sonata\AdminBundle\Util\FormBuilderIterator; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilder; | ||
use Symfony\Component\Form\FormFactoryInterface; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Form\FormFactory; | ||
use Symfony\Component\Form\FormRegistryInterface; | ||
|
||
/** | ||
* @author Mike Meier <mike.meier@ibrows.ch> | ||
*/ | ||
final class FormBuilderIteratorTest extends TestCase | ||
{ | ||
private EventDispatcherInterface $dispatcher; | ||
|
||
private FormFactoryInterface $factory; | ||
|
||
private FormBuilder $builder; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->dispatcher = $this->createStub(EventDispatcherInterface::class); | ||
$this->factory = $this->createStub(FormFactoryInterface::class); | ||
$this->builder = new FormBuilder('name', null, $this->dispatcher, $this->factory); | ||
$this->factory->method('createNamedBuilder')->willReturn($this->builder); | ||
$dispatcher = $this->createStub(EventDispatcherInterface::class); | ||
$registry = $this->createStub(FormRegistryInterface::class); | ||
$factory = new FormFactory($registry); | ||
$this->builder = new FormBuilder('name', null, $dispatcher, $factory); | ||
} | ||
|
||
public function testGetChildren(): void | ||
|
@@ -51,6 +50,22 @@ public function testHasChildren(): void | |
{ | ||
$this->builder->add('name', TextType::class); | ||
$iterator = new FormBuilderIterator($this->builder); | ||
static::assertTrue($iterator->hasChildren()); | ||
static::assertFalse($iterator->hasChildren()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed from using a stub of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then can you add a hasChildren test when we have the true response too ? |
||
} | ||
|
||
public function testCurrentCasting(): void | ||
{ | ||
$this->builder->add('hungry', ChoiceType::class, [ | ||
'multiple' => true, | ||
'expanded' => true, | ||
'choices' => [ | ||
'Maybe' => null, | ||
'Yes' => true, | ||
'No' => false, | ||
], | ||
]); | ||
|
||
$iterator = new FormBuilderIterator($this->builder->get('hungry')); | ||
static::assertInstanceOf(FormBuilderInterface::class, $iterator->current()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed
dispatcher
andfactory
properties from the class and replaced them with vars insidesetUp
since they are not used anywhere else.