Skip to content

Commit

Permalink
Test situation for issue #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Burgov committed May 2, 2014
1 parent fd94910 commit 6cf224e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Tests/Form/Fixtures/ObjectWithAdderRemoverSetterAndGetter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Burgov\Bundle\KeyValueFormBundle\Tests\Form\Fixtures;

class ObjectWithAdderRemoverSetterAndGetter
{
private $values = array();

public function setValues(array $values)
{
$this->values = $values;
}

public function getValues()
{
return $this->values;
}

public function addValue($key, $value)
{
$this->values[$key] = $value;
}

public function removeValue($key)
{
unset($this->values[$key]);
}
}

26 changes: 26 additions & 0 deletions Tests/Form/Type/KeyValueTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Burgov\Bundle\KeyValueFormBundle\Form\Type\KeyValueRowType;
use Burgov\Bundle\KeyValueFormBundle\Form\Type\KeyValueType;
use Burgov\Bundle\KeyValueFormBundle\Tests\Form\Fixtures\ObjectWithAdderRemoverSetterAndGetter;
use Symfony\Component\Form\AbstractExtension;
use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
use Symfony\Component\Form\Test\TypeTestCase;
Expand Down Expand Up @@ -93,6 +94,31 @@ public function testWithChoiceType()
$this->assertSame(array('key1' => $obj2, 'key2' => $obj1), $form->getData());
}

public function testSettingValuesToObjectWithAddersAndRemoversWorksFine()
{
$object = new ObjectWithAdderRemoverSetterAndGetter();
$object->setValues(array('key1' => '2', 'key2' => '1'));

$builder = $this->factory->createBuilder('form', $object);
$builder->add('values', 'burgov_key_value', array('value_type' => 'text'));

$form = $builder->getForm();

$form->submit(array(
'values' => array(
array(
'key' => 'key3',
'value' => '6'
), array(
'key' => 'key4',
'value' => '8'
)
)
));

$this->assertEquals(array('key3' => '6', 'key4' => '8'));
}

private function assertFormTypes(array $types, $form)
{
$this->assertCount(count($types), $form);
Expand Down

2 comments on commit 6cf224e

@ElectricMaxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a failing test i hope?

@Burgov
Copy link
Owner Author

@Burgov Burgov commented on 6cf224e May 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, makes reproducing and researching the bug a little easier

Please sign in to comment.