Skip to content

Commit 8365cd6

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [Form] backport DependencyInjectionExtension tests [Form] Fixed typo in a test after #21877
2 parents 6513e7f + 1a5790d commit 8365cd6

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
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
@@ -513,22 +513,20 @@ public function testSetDataIsIgnoredIfDataIsLocked()
513513
$this->assertSame('default', $form->getData());
514514
}
515515

516-
public function testPresSetDataChangesDataIfDataIsLocked()
516+
public function testPreSetDataChangesDataIfDataIsLocked()
517517
{
518518
$config = new FormConfigBuilder('name', null, $this->dispatcher);
519519
$config
520520
->setData('default')
521521
->setDataLocked(true)
522-
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
522+
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
523523
$event->setData('foobar');
524524
});
525525
$form = new Form($config);
526526

527-
$form->submit(false);
528-
529-
$this->assertTrue($form->isValid());
530-
531527
$this->assertSame('foobar', $form->getData());
528+
$this->assertSame('foobar', $form->getNormData());
529+
$this->assertSame('foobar', $form->getViewData());
532530
}
533531

534532
public function testSubmitConvertsEmptyToNullIfNoTransformer()

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"require-dev": {
2727
"doctrine/collections": "~1.0",
2828
"symfony/validator": "^2.8.18|~3.2.5",
29-
"symfony/dependency-injection": "~2.3|~3.0.0",
29+
"symfony/dependency-injection": "~2.7|~3.0.0",
3030
"symfony/http-foundation": "~2.2|~3.0.0",
3131
"symfony/http-kernel": "~2.4|~3.0.0",
3232
"symfony/security-csrf": "~2.4|~3.0.0",

0 commit comments

Comments
 (0)