diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 59ec772525..93be4ee0d6 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ - Cache\IntegrationTests - Doctrine\Common\Cache - Symfony\Component\Cache - Symfony\Component\Cache\Tests\Fixtures - Symfony\Component\Cache\Traits - Symfony\Component\Console - Symfony\Component\HttpFoundation + Cache\IntegrationTests + Doctrine\Common\Cache + Symfony\Component\Cache + Symfony\Component\Cache\Tests\Fixtures + Symfony\Component\Cache\Traits + Symfony\Component\Console + Symfony\Component\HttpFoundation diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php index c0061dabc5..d60992fcf1 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php @@ -1482,4 +1482,43 @@ class EntityTypeTest extends BaseTypeTest $this->assertEquals(array(), $form->getNormData()); $this->assertSame(array(), $form->getViewData(), 'View data is always an array'); } + + public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expectedData = null) + { + $emptyData = '1'; + $entity1 = new SingleIntIdEntity(1, 'Foo'); + $this->persist(array($entity1)); + + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'em' => 'default', + 'class' => self::SINGLE_IDENT_CLASS, + 'empty_data' => $emptyData, + )); + $form->submit(null); + + $this->assertSame($emptyData, $form->getViewData()); + $this->assertSame($entity1, $form->getNormData()); + $this->assertSame($entity1, $form->getData()); + } + + public function testSubmitNullMultipleUsesDefaultEmptyData() + { + $emptyData = array('1'); + $entity1 = new SingleIntIdEntity(1, 'Foo'); + $this->persist(array($entity1)); + + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'em' => 'default', + 'class' => self::SINGLE_IDENT_CLASS, + 'multiple' => true, + 'empty_data' => $emptyData, + )); + $form->submit(null); + + $collection = new ArrayCollection(array($entity1)); + + $this->assertSame($emptyData, $form->getViewData()); + $this->assertEquals($collection, $form->getNormData()); + $this->assertEquals($collection, $form->getData()); + } } diff --git a/src/Symfony/Bridge/Doctrine/phpunit.xml.dist b/src/Symfony/Bridge/Doctrine/phpunit.xml.dist index 24f92f2ab8..fa76fa9b50 100644 --- a/src/Symfony/Bridge/Doctrine/phpunit.xml.dist +++ b/src/Symfony/Bridge/Doctrine/phpunit.xml.dist @@ -1,7 +1,7 @@ name; - $class = ($class = $r->getClosureThis()) ? \get_class($class) : null; - if ($scopeClass = $r->getClosureScopeClass() ?: $class) { - $data['class'] = $scopeClass; - if (!$class) { + if ($class = $r->getClosureScopeClass()) { + $data['class'] = $class->name; + if (!$r->getClosureThis()) { $data['static'] = true; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php index 3bfa918148..d5958f7317 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php @@ -353,10 +353,9 @@ class MarkdownDescriptor extends Descriptor } $string .= "\n".sprintf('- Name: `%s`', $r->name); - $class = ($class = $r->getClosureThis()) ? \get_class($class) : null; - if ($scopeClass = $r->getClosureScopeClass() ?: $class) { - $string .= "\n".sprintf('- Class: `%s`', $class); - if (!$class) { + if ($class = $r->getClosureScopeClass()) { + $string .= "\n".sprintf('- Class: `%s`', $class->name); + if (!$r->getClosureThis()) { $string .= "\n- Static: yes"; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php index 4aabaee07a..0adffd8a80 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php @@ -453,10 +453,7 @@ class TextDescriptor extends Descriptor return 'Closure()'; } if ($class = $r->getClosureScopeClass()) { - return sprintf('%s::%s()', $class, $r->name); - } - if ($class = $r->getClosureThis()) { - return sprintf('%s::%s()', \get_class($class), $r->name); + return sprintf('%s::%s()', $class->name, $r->name); } return $r->name.'()'; diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php index ecf79b23df..41ce47a504 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php @@ -524,10 +524,9 @@ class XmlDescriptor extends Descriptor } $callableXML->setAttribute('name', $r->name); - $class = ($class = $r->getClosureThis()) ? \get_class($class) : null; - if ($scopeClass = $r->getClosureScopeClass() ?: $class) { - $callableXML->setAttribute('class', $class); - if (!$class) { + if ($class = $r->getClosureScopeClass()) { + $callableXML->setAttribute('class', $class->name); + if (!$r->getClosureThis()) { $callableXML->setAttribute('static', 'true'); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php index 2b45a3edab..12e81898bf 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php @@ -155,7 +155,7 @@ class ObjectsProvider public static function getCallables() { - return array( + $callables = array( 'callable_1' => 'array_key_exists', 'callable_2' => array('Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\CallableClass', 'staticMethod'), 'callable_3' => array(new CallableClass(), 'method'), @@ -164,6 +164,12 @@ class ObjectsProvider 'callable_6' => function () { return 'Closure'; }, 'callable_7' => new CallableClass(), ); + + if (\PHP_VERSION_ID >= 70100) { + $callables['callable_from_callable'] = \Closure::fromCallable(new CallableClass()); + } + + return $callables; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/callable_from_callable.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/callable_from_callable.json new file mode 100644 index 0000000000..fc0b749d99 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/callable_from_callable.json @@ -0,0 +1,5 @@ +{ + "type": "closure", + "name": "__invoke", + "class": "Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\CallableClass" +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/callable_from_callable.md b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/callable_from_callable.md new file mode 100644 index 0000000000..caf4193b4a --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/callable_from_callable.md @@ -0,0 +1,4 @@ + +- Type: `closure` +- Name: `__invoke` +- Class: `Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\CallableClass` diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/callable_from_callable.txt b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/callable_from_callable.txt new file mode 100644 index 0000000000..78ef6a6527 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/callable_from_callable.txt @@ -0,0 +1 @@ +Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\CallableClass::__invoke() \ No newline at end of file diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/callable_from_callable.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/callable_from_callable.xml new file mode 100644 index 0000000000..1ad2ee8f47 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/callable_from_callable.xml @@ -0,0 +1,2 @@ + + diff --git a/src/Symfony/Bundle/FrameworkBundle/phpunit.xml.dist b/src/Symfony/Bundle/FrameworkBundle/phpunit.xml.dist index b447e1ac3e..c0d8df4156 100644 --- a/src/Symfony/Bundle/FrameworkBundle/phpunit.xml.dist +++ b/src/Symfony/Bundle/FrameworkBundle/phpunit.xml.dist @@ -1,7 +1,7 @@ - Cache\IntegrationTests - Doctrine\Common\Cache - Symfony\Component\Cache - Symfony\Component\Cache\Tests\Fixtures - Symfony\Component\Cache\Traits + Cache\IntegrationTests + Doctrine\Common\Cache + Symfony\Component\Cache + Symfony\Component\Cache\Tests\Fixtures + Symfony\Component\Cache\Traits diff --git a/src/Symfony/Component/Config/phpunit.xml.dist b/src/Symfony/Component/Config/phpunit.xml.dist index 36ef339fd7..1cfdb3cdc6 100644 --- a/src/Symfony/Component/Config/phpunit.xml.dist +++ b/src/Symfony/Component/Config/phpunit.xml.dist @@ -1,7 +1,7 @@ name, '{closure}')) { $this->pretty = $this->name = 'closure'; - } elseif ($this->name = $r->getClosureScopeClass()) { - $this->pretty = $this->name.'::'.$r->name; - } elseif ($class = $r->getClosureThis()) { - $this->name = \get_class($class); + } elseif ($class = $r->getClosureScopeClass()) { + $this->name = $class->name; $this->pretty = $this->name.'::'.$r->name; } else { $this->pretty = $this->name = $r->name; diff --git a/src/Symfony/Component/EventDispatcher/Tests/Debug/WrappedListenerTest.php b/src/Symfony/Component/EventDispatcher/Tests/Debug/WrappedListenerTest.php new file mode 100644 index 0000000000..f743f148d2 --- /dev/null +++ b/src/Symfony/Component/EventDispatcher/Tests/Debug/WrappedListenerTest.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\EventDispatcher\Tests\Debug; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\EventDispatcher\Debug\WrappedListener; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\Stopwatch\Stopwatch; + +class WrappedListenerTest extends TestCase +{ + /** + * @dataProvider provideListenersToDescribe + */ + public function testListenerDescription(callable $listener, $expected) + { + $wrappedListener = new WrappedListener($listener, null, $this->getMockBuilder(Stopwatch::class)->getMock(), $this->getMockBuilder(EventDispatcherInterface::class)->getMock()); + + $this->assertStringMatchesFormat($expected, $wrappedListener->getPretty()); + } + + public function provideListenersToDescribe() + { + $listeners = array( + array(new FooListener(), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::__invoke'), + array(array(new FooListener(), 'listen'), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'), + array(array('Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic'), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic'), + array('var_dump', 'var_dump'), + array(function () {}, 'closure'), + ); + + if (\PHP_VERSION_ID >= 70100) { + $listeners[] = array(\Closure::fromCallable(array(new FooListener(), 'listen')), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'); + $listeners[] = array(\Closure::fromCallable(array('Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic')), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic'); + $listeners[] = array(\Closure::fromCallable(function () {}), 'closure'); + } + + return $listeners; + } +} + +class FooListener +{ + public function listen() + { + } + + public function __invoke() + { + } + + public static function listenStatic() + { + } +} diff --git a/src/Symfony/Component/EventDispatcher/phpunit.xml.dist b/src/Symfony/Component/EventDispatcher/phpunit.xml.dist index b3ad1bdf5a..f2eb1692cd 100644 --- a/src/Symfony/Component/EventDispatcher/phpunit.xml.dist +++ b/src/Symfony/Component/EventDispatcher/phpunit.xml.dist @@ -1,7 +1,7 @@ assertSame($view, $form->getViewData()); } + public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expectedData = null) + { + $builder = $this->factory->createBuilder($this->getTestedType()); + + if ($builder->getCompound()) { + $emptyData = array(); + foreach ($builder as $field) { + // empty children should map null (model data) in the compound view data + $emptyData[$field->getName()] = null; + } + } else { + // simple fields share the view and the model format, unless they use a transformer + $expectedData = $emptyData; + } + + $form = $builder->setEmptyData($emptyData)->getForm()->submit(null); + + $this->assertSame($emptyData, $form->getViewData()); + $this->assertSame($expectedData, $form->getNormData()); + $this->assertSame($expectedData, $form->getData()); + } + protected function getTestedType() { return static::TESTED_TYPE; diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ButtonTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ButtonTypeTest.php index 4e2b4f49b8..350602306f 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ButtonTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ButtonTypeTest.php @@ -22,4 +22,16 @@ class ButtonTypeTest extends BaseTypeTest { $this->assertInstanceOf('Symfony\Component\Form\Button', $this->factory->create(static::TESTED_TYPE)); } + + /** + * @expectedException \Symfony\Component\Form\Exception\BadMethodCallException + * @expectedExceptionMessage Buttons do not support empty data. + * + * @param string $emptyData + * @param null $expectedData + */ + public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expectedData = null) + { + parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php index 5ef2f66ca2..b67f3e8029 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php @@ -209,4 +209,17 @@ class CheckboxTypeTest extends BaseTypeTest { parent::testSubmitNull(false, false, null); } + + public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expectedData = true) + { + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'empty_data' => $emptyData, + )); + $form->submit(null); + + // view data is transformed to the string true value + $this->assertSame('1', $form->getViewData()); + $this->assertSame($expectedData, $form->getNormData()); + $this->assertSame($expectedData, $form->getData()); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index e12ab6ff93..cb4d182b30 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -584,18 +584,19 @@ class ChoiceTypeTest extends BaseTypeTest $this->assertTrue($form->isSynchronized()); } - public function testSubmitSingleChoiceWithEmptyData() + public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expectedData = null) { $form = $this->factory->create(static::TESTED_TYPE, null, array( 'multiple' => false, 'expanded' => false, - 'choices' => array('test'), - 'empty_data' => 'test', + // empty data must match string choice value + 'choices' => array($emptyData), + 'empty_data' => $emptyData, )); $form->submit(null); - $this->assertSame('test', $form->getData()); + $this->assertSame($emptyData, $form->getData()); } public function testSubmitSingleChoiceWithEmptyDataAndInitialData() diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php index ffeace3038..9393c99dc0 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php @@ -408,4 +408,10 @@ class CollectionTypeTest extends BaseTypeTest { parent::testSubmitNull(array(), array(), array()); } + + public function testSubmitNullUsesDefaultEmptyData($emptyData = array(), $expectedData = array()) + { + // resize form listener always set an empty array + parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php index a8e9ddc7d3..249f9f918f 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php @@ -75,4 +75,9 @@ class CountryTypeTest extends BaseTypeTest { parent::testSubmitNull($expected, $norm, ''); } + + public function testSubmitNullUsesDefaultEmptyData($emptyData = 'FR', $expectedData = 'FR') + { + parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php index 01733c4917..1a98906fbb 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php @@ -56,4 +56,9 @@ class CurrencyTypeTest extends BaseTypeTest { parent::testSubmitNull($expected, $norm, ''); } + + public function testSubmitNullUsesDefaultEmptyData($emptyData = 'EUR', $expectedData = 'EUR') + { + parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateIntervalTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateIntervalTypeTest.php index 43fd180c16..1422dc17b5 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateIntervalTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateIntervalTypeTest.php @@ -410,4 +410,17 @@ class DateIntervalTypeTest extends BaseTypeTest 'days' => '', )); } + + public function testSubmitNullUsesDefaultEmptyData($emptyData = array(), $expectedData = null) + { + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'empty_data' => $emptyData, + )); + $form->submit(null); + + // view transformer writes back empty strings in the view data + $this->assertSame(array('years' => '', 'months' => '', 'days' => ''), $form->getViewData()); + $this->assertSame($expectedData, $form->getNormData()); + $this->assertSame($expectedData, $form->getData()); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php index a45b183142..d7e48e0712 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php @@ -628,4 +628,20 @@ class DateTimeTypeTest extends BaseTypeTest $this->assertNull($form->getNormData()); $this->assertSame('', $form->getViewData()); } + + public function testSubmitNullUsesDefaultEmptyData($emptyData = array(), $expectedData = null) + { + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'empty_data' => $emptyData, + )); + $form->submit(null); + + // view transformer writes back empty strings in the view data + $this->assertSame( + array('date' => array('year' => '', 'month' => '', 'day' => ''), 'time' => array('hour' => '', 'minute' => '')), + $form->getViewData() + ); + $this->assertSame($expectedData, $form->getNormData()); + $this->assertSame($expectedData, $form->getData()); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php index c8d1b4614d..94ae1a3a41 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php @@ -997,4 +997,33 @@ class DateTypeTest extends BaseTypeTest $this->assertNull($form->getNormData()); $this->assertSame('', $form->getViewData()); } + + public function testSubmitNullUsesDefaultEmptyData($emptyData = array(), $expectedData = null) + { + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'empty_data' => $emptyData, + )); + $form->submit(null); + + // view transformer write back empty strings in the view data + $this->assertSame(array('year' => '', 'month' => '', 'day' => ''), $form->getViewData()); + $this->assertSame($expectedData, $form->getNormData()); + $this->assertSame($expectedData, $form->getData()); + } + + public function testSingleTextSubmitNullUsesDefaultEmptyData() + { + $emptyData = '2018-11-11'; + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'widget' => 'single_text', + 'empty_data' => $emptyData, + )); + $form->submit(null); + + $date = new \DateTime($emptyData); + + $this->assertSame($emptyData, $form->getViewData()); + $this->assertEquals($date, $form->getNormData()); + $this->assertEquals($date, $form->getData()); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php index d7e958d559..68f30ef16b 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php @@ -170,6 +170,11 @@ class FormTypeTest extends BaseTypeTest )); } + public function testSubmitNullUsesDefaultEmptyData($emptyData = array(), $expectedData = array()) + { + parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData); + } + public function testSubmitWithEmptyDataCreatesObjectIfClassAvailable() { $form = $this->factory->createBuilder(static::TESTED_TYPE, null, array( diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/IntegerTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/IntegerTypeTest.php index 27a57eea79..fd3c2faf6a 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/IntegerTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/IntegerTypeTest.php @@ -38,4 +38,16 @@ class IntegerTypeTest extends BaseTypeTest { parent::testSubmitNull($expected, $norm, ''); } + + public function testSubmitNullUsesDefaultEmptyData($emptyData = '10', $expectedData = 10) + { + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'empty_data' => $emptyData, + )); + $form->submit(null); + + $this->assertSame($emptyData, $form->getViewData()); + $this->assertSame($expectedData, $form->getNormData()); + $this->assertSame($expectedData, $form->getData()); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php index ebe3d4ebb9..7b8e67f626 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php @@ -68,4 +68,9 @@ class LanguageTypeTest extends BaseTypeTest { parent::testSubmitNull($expected, $norm, ''); } + + public function testSubmitNullUsesDefaultEmptyData($emptyData = 'en', $expectedData = 'en') + { + parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php index ab0dfa4bf1..cf68da243c 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php @@ -56,4 +56,9 @@ class LocaleTypeTest extends BaseTypeTest { parent::testSubmitNull($expected, $norm, ''); } + + public function testSubmitNullUsesDefaultEmptyData($emptyData = 'en', $expectedData = 'en') + { + parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/MoneyTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/MoneyTypeTest.php index fe8b400a98..a430773152 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/MoneyTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/MoneyTypeTest.php @@ -71,6 +71,18 @@ class MoneyTypeTest extends BaseTypeTest $this->assertSame('{{ widget }}', $view->vars['money_pattern']); } + public function testSubmitNullUsesDefaultEmptyData($emptyData = '10.00', $expectedData = 10.0) + { + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'empty_data' => $emptyData, + )); + $form->submit(null); + + $this->assertSame($emptyData, $form->getViewData()); + $this->assertSame($expectedData, $form->getNormData()); + $this->assertSame($expectedData, $form->getData()); + } + public function testDefaultFormattingWithDefaultRounding() { $form = $this->factory->create(static::TESTED_TYPE, null, array('scale' => 0)); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php index 1daec3c059..a15d6f6642 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php @@ -63,4 +63,16 @@ class NumberTypeTest extends BaseTypeTest { parent::testSubmitNull($expected, $norm, ''); } + + public function testSubmitNullUsesDefaultEmptyData($emptyData = '10', $expectedData = 10.0) + { + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'empty_data' => $emptyData, + )); + $form->submit(null); + + $this->assertSame($emptyData, $form->getViewData()); + $this->assertSame($expectedData, $form->getNormData()); + $this->assertSame($expectedData, $form->getData()); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php index c58cb44fa8..03bcc3632a 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php @@ -790,4 +790,17 @@ class TimeTypeTest extends BaseTypeTest parent::testSubmitNull($expected, $norm, $view); } + + public function testSubmitNullUsesDefaultEmptyData($emptyData = array(), $expectedData = null) + { + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'empty_data' => $emptyData, + )); + $form->submit(null); + + // view transformer write back empty strings in the view data + $this->assertSame(array('hour' => '', 'minute' => ''), $form->getViewData()); + $this->assertSame($expectedData, $form->getNormData()); + $this->assertSame($expectedData, $form->getData()); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimezoneTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimezoneTypeTest.php index 51578bd6ad..fa02456f72 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimezoneTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimezoneTypeTest.php @@ -34,6 +34,18 @@ class TimezoneTypeTest extends BaseTypeTest parent::testSubmitNull($expected, $norm, ''); } + public function testSubmitNullUsesDefaultEmptyData($emptyData = 'Africa/Kinshasa', $expectedData = 'Africa/Kinshasa') + { + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'empty_data' => $emptyData, + )); + $form->submit(null); + + $this->assertSame($emptyData, $form->getViewData()); + $this->assertSame($expectedData, $form->getNormData()); + $this->assertSame($expectedData, $form->getData()); + } + public function testDateTimeZoneInput() { $form = $this->factory->create(static::TESTED_TYPE, new \DateTimeZone('America/New_York'), array('input' => 'datetimezone')); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php index d63665a0c1..a72bc985cd 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php @@ -90,4 +90,17 @@ class UrlTypeTest extends TextTypeTest $this->assertSame(array('domain.com', 'www.domain.com'), $form->getData()); } + + public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expectedData = 'http://empty') + { + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'empty_data' => $emptyData, + )); + $form->submit(null); + + // listener normalizes data on submit + $this->assertSame($expectedData, $form->getViewData()); + $this->assertSame($expectedData, $form->getNormData()); + $this->assertSame($expectedData, $form->getData()); + } } diff --git a/src/Symfony/Component/Form/phpunit.xml.dist b/src/Symfony/Component/Form/phpunit.xml.dist index b834e2f33a..ede79e207d 100644 --- a/src/Symfony/Component/Form/phpunit.xml.dist +++ b/src/Symfony/Component/Form/phpunit.xml.dist @@ -1,7 +1,7 @@ name; if ($class = $r->getClosureScopeClass()) { - $controller['class'] = $class; - } elseif ($class = $r->getClosureThis()) { - $controller['class'] = \get_class($class); + $controller['class'] = $class->name; } else { return $r->name; } diff --git a/src/Symfony/Component/HttpKernel/phpunit.xml.dist b/src/Symfony/Component/HttpKernel/phpunit.xml.dist index e0de769dd7..3fc07707f2 100644 --- a/src/Symfony/Component/HttpKernel/phpunit.xml.dist +++ b/src/Symfony/Component/HttpKernel/phpunit.xml.dist @@ -1,7 +1,7 @@ name, '{closure}')) { - if (isset($a[$prefix.'class'])) { - $stub->class = $a[$prefix.'class']->value.'::'.$c->name; - } elseif (isset($a[$prefix.'this'])) { - $stub->class = $a[$prefix.'this']->class.'::'.$c->name; - } else { - $stub->class = $c->name; - } + $stub->class = isset($a[$prefix.'class']) ? $a[$prefix.'class']->value.'::'.$c->name : $c->name; unset($a[$prefix.'class']); } diff --git a/src/Symfony/Component/VarDumper/phpunit.xml.dist b/src/Symfony/Component/VarDumper/phpunit.xml.dist index 4a25f42db8..3243fcd027 100644 --- a/src/Symfony/Component/VarDumper/phpunit.xml.dist +++ b/src/Symfony/Component/VarDumper/phpunit.xml.dist @@ -1,7 +1,7 @@