Skip to content

Commit 6da5d99

Browse files
committed
Merge branch '2.8' into 3.2
* 2.8: [Form] backport DependencyInjectionExtension tests [Form] Fixed typo in a test after #21877
2 parents e01b6d0 + 8365cd6 commit 6da5d99

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public function testGetTypeExtensions()
3535
->willReturn('other');
3636

3737
$services = array(
38-
'extension1' => $typeExtension1,
39-
'extension2' => $typeExtension2,
40-
'extension3' => $typeExtension3,
38+
'extension1' => $typeExtension1 = $this->createFormTypeExtensionMock('test'),
39+
'extension2' => $typeExtension2 = $this->createFormTypeExtensionMock('test'),
40+
'extension3' => $typeExtension3 = $this->createFormTypeExtensionMock('other'),
4141
);
4242

4343
$container->expects($this->any())
@@ -78,4 +78,33 @@ public function testThrowExceptionForInvalidExtendedType()
7878

7979
$extension->getTypeExtensions('test');
8080
}
81+
82+
public function testGetTypeGuesser()
83+
{
84+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
85+
$container
86+
->expects($this->once())
87+
->method('get')
88+
->with('foo')
89+
->willReturn($this->getMockBuilder('Symfony\Component\Form\FormTypeGuesserInterface')->getMock());
90+
$extension = new DependencyInjectionExtension($container, array(), array(), array('foo'));
91+
92+
$this->assertInstanceOf('Symfony\Component\Form\FormTypeGuesserChain', $extension->getTypeGuesser());
93+
}
94+
95+
public function testGetTypeGuesserReturnsNullWhenNoTypeGuessersHaveBeenConfigured()
96+
{
97+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
98+
$extension = new DependencyInjectionExtension($container, array(), array(), array());
99+
100+
$this->assertNull($extension->getTypeGuesser());
101+
}
102+
103+
private function createFormTypeExtensionMock($extendedType)
104+
{
105+
$extension = $this->getMockBuilder('Symfony\Component\Form\FormTypeExtensionInterface')->getMock();
106+
$extension->expects($this->any())->method('getExtendedType')->willReturn($extendedType);
107+
108+
return $extension;
109+
}
81110
}

Tests/SimpleFormTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,22 +517,20 @@ public function testSetDataIsIgnoredIfDataIsLocked()
517517
$this->assertSame('default', $form->getData());
518518
}
519519

520-
public function testPresSetDataChangesDataIfDataIsLocked()
520+
public function testPreSetDataChangesDataIfDataIsLocked()
521521
{
522522
$config = new FormConfigBuilder('name', null, $this->dispatcher);
523523
$config
524524
->setData('default')
525525
->setDataLocked(true)
526-
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
526+
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
527527
$event->setData('foobar');
528528
});
529529
$form = new Form($config);
530530

531-
$form->submit(false);
532-
533-
$this->assertTrue($form->isValid());
534-
535531
$this->assertSame('foobar', $form->getData());
532+
$this->assertSame('foobar', $form->getNormData());
533+
$this->assertSame('foobar', $form->getViewData());
536534
}
537535

538536
public function testSubmitConvertsEmptyToNullIfNoTransformer()

0 commit comments

Comments
 (0)