Skip to content

Commit

Permalink
Merge branch '2.3' into 2.5
Browse files Browse the repository at this point in the history
* 2.3:
  [PropertyAccessor] Added test to allow null value for a array
  [Yaml] Fixed #10597: Improved Yaml directive parsing
  [Form] Set a child type to text if added to the form without a type.

Conflicts:
	src/Symfony/Component/PropertyAccess/PropertyAccessor.php
	src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php
  • Loading branch information
fabpot committed Jan 9, 2015
2 parents b52e0d1 + 55b8939 commit e300b43
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Component/Form/Form.php
Expand Up @@ -888,6 +888,10 @@ public function add($child, $type = null, array $options = array())
// Never initialize child forms automatically
$options['auto_initialize'] = false;

if (null === $type && null === $this->config->getDataClass()) {
$type = 'text';
}

if (null === $type) {
$child = $this->config->getFormFactory()->createForProperty($this->config->getDataClass(), $child, null, $options);
} else {
Expand Down
16 changes: 16 additions & 0 deletions src/Symfony/Component/Form/Tests/CompoundFormTest.php
Expand Up @@ -205,6 +205,22 @@ public function testAddUsingIntegerNameAndType()
$this->assertSame(array(0 => $child), $this->form->all());
}

public function testAddWithoutType()
{
$child = $this->getBuilder('foo')->getForm();

$this->factory->expects($this->once())
->method('createNamed')
->with('foo', 'text')
->will($this->returnValue($child));

$this->form->add('foo');

$this->assertTrue($this->form->has('foo'));
$this->assertSame($this->form, $child->getParent());
$this->assertSame(array('foo' => $child), $this->form->all());
}

public function testAddUsingNameButNoType()
{
$this->form = $this->getBuilder('name', null, '\stdClass')
Expand Down
8 changes: 6 additions & 2 deletions src/Symfony/Component/PropertyAccess/PropertyAccessor.php
Expand Up @@ -226,10 +226,14 @@ private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $pr

$property = $propertyPath->getElement($i);
$isIndex = $propertyPath->isIndex($i);
$isArrayAccess = is_array($objectOrArray) || $objectOrArray instanceof \ArrayAccess;

// Create missing nested arrays on demand
if ($isIndex && $isArrayAccess && !isset($objectOrArray[$property])) {
if ($isIndex &&
(
($objectOrArray instanceof \ArrayAccess && !isset($objectOrArray[$property])) ||
(is_array($objectOrArray) && !array_key_exists($property, $objectOrArray))
)
) {
if (!$ignoreInvalidIndices) {
if (!is_array($objectOrArray)) {
if (!$objectOrArray instanceof \Traversable) {
Expand Down
Expand Up @@ -277,6 +277,12 @@ public function testSetValueThrowsExceptionIfEmpty()
$this->propertyAccessor->setValue($value, 'foobar', 'bam');
}

public function testGetValueWhenArrayValueIsNull()
{
$this->propertyAccessor = new PropertyAccessor(false, true);
$this->assertNull($this->propertyAccessor->getValue(array('index' => array('nullable' => null)), '[index][nullable]'));
}

/**
* @dataProvider getValidPropertyPaths
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Parser.php
Expand Up @@ -621,7 +621,7 @@ private function cleanup($value)

// strip YAML header
$count = 0;
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#su', '', $value, -1, $count);
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#u', '', $value, -1, $count);
$this->offset += $count;

// remove leading comments
Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/Yaml/Tests/ParserTest.php
Expand Up @@ -697,6 +697,17 @@ public function testReferenceResolvingInInlineStrings()
EOF
));
}

public function testYamlDirective()
{
$yaml = <<<EOF
%YAML 1.2
---
foo: 1
bar: 2
EOF;
$this->assertEquals(array('foo' => 1, 'bar' => 2), $this->parser->parse($yaml));
}
}

class B
Expand Down

0 comments on commit e300b43

Please sign in to comment.