Skip to content

Commit

Permalink
Merge branch '2.7' into 2.8
Browse files Browse the repository at this point in the history
* 2.7:
  [Form] backport DependencyInjectionExtension tests
  [Form] Fixed typo in a test after symfony#21877
  • Loading branch information
fabpot committed Mar 5, 2017
2 parents 663661b + 4816f65 commit 8279055
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
Expand Up @@ -35,9 +35,9 @@ public function testGetTypeExtensions()
->willReturn('other');

$services = array(
'extension1' => $typeExtension1,
'extension2' => $typeExtension2,
'extension3' => $typeExtension3,
'extension1' => $typeExtension1 = $this->createFormTypeExtensionMock('test'),
'extension2' => $typeExtension2 = $this->createFormTypeExtensionMock('test'),
'extension3' => $typeExtension3 = $this->createFormTypeExtensionMock('other'),
);

$container->expects($this->any())
Expand Down Expand Up @@ -78,4 +78,33 @@ public function testThrowExceptionForInvalidExtendedType()

$extension->getTypeExtensions('test');
}

public function testGetTypeGuesser()
{
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container
->expects($this->once())
->method('get')
->with('foo')
->willReturn($this->getMockBuilder('Symfony\Component\Form\FormTypeGuesserInterface')->getMock());
$extension = new DependencyInjectionExtension($container, array(), array(), array('foo'));

$this->assertInstanceOf('Symfony\Component\Form\FormTypeGuesserChain', $extension->getTypeGuesser());
}

public function testGetTypeGuesserReturnsNullWhenNoTypeGuessersHaveBeenConfigured()
{
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$extension = new DependencyInjectionExtension($container, array(), array(), array());

$this->assertNull($extension->getTypeGuesser());
}

private function createFormTypeExtensionMock($extendedType)
{
$extension = $this->getMockBuilder('Symfony\Component\Form\FormTypeExtensionInterface')->getMock();
$extension->expects($this->any())->method('getExtendedType')->willReturn($extendedType);

return $extension;
}
}
10 changes: 4 additions & 6 deletions src/Symfony/Component/Form/Tests/SimpleFormTest.php
Expand Up @@ -513,22 +513,20 @@ public function testSetDataIsIgnoredIfDataIsLocked()
$this->assertSame('default', $form->getData());
}

public function testPresSetDataChangesDataIfDataIsLocked()
public function testPreSetDataChangesDataIfDataIsLocked()
{
$config = new FormConfigBuilder('name', null, $this->dispatcher);
$config
->setData('default')
->setDataLocked(true)
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$event->setData('foobar');
});
$form = new Form($config);

$form->submit(false);

$this->assertTrue($form->isValid());

$this->assertSame('foobar', $form->getData());
$this->assertSame('foobar', $form->getNormData());
$this->assertSame('foobar', $form->getViewData());
}

public function testSubmitConvertsEmptyToNullIfNoTransformer()
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/composer.json
Expand Up @@ -26,7 +26,7 @@
"require-dev": {
"doctrine/collections": "~1.0",
"symfony/validator": "^2.8.18|~3.2.5",
"symfony/dependency-injection": "~2.3|~3.0.0",
"symfony/dependency-injection": "~2.7|~3.0.0",
"symfony/http-foundation": "~2.2|~3.0.0",
"symfony/http-kernel": "~2.4|~3.0.0",
"symfony/security-csrf": "~2.4|~3.0.0",
Expand Down

0 comments on commit 8279055

Please sign in to comment.