Skip to content

Commit

Permalink
Enhance error messages with regard to form type properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Nov 1, 2011
1 parent 8a62e32 commit 149bdb9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/FormFactory.php
Expand Up @@ -249,11 +249,11 @@ public function createNamedBuilder($type, $name, $data = null, array $options =
$diff = array_diff($passedOptions, $knownOptions);

if (count($diff) > 1) {
throw new CreationException(sprintf('The options "%s" do not exist', implode('", "', $diff)));
throw new CreationException(sprintf('The options "%s" do not exist. Known options are: "%s"', implode('", "', $diff), implode('", "', $knownOptions)));
}

if (count($diff) > 0) {
throw new CreationException(sprintf('The option "%s" does not exist', current($diff)));
throw new CreationException(sprintf('The option "%s" does not exist. Known options are: "%s"', current($diff), implode('", "', $knownOptions)));
}

foreach ($optionValues as $option => $allowedValues) {
Expand Down
30 changes: 30 additions & 0 deletions tests/Symfony/Tests/Component/Form/FormFactoryTest.php
Expand Up @@ -475,6 +475,36 @@ public function testCreateBuilderUsesRequiredSettingWithHighestConfidence()
$this->assertEquals('builderInstance', $builder);
}

public function testUnknownOptions()
{
$type = new \Symfony\Component\Form\Extension\Core\Type\TextType();

$factory = new FormFactory(array(new \Symfony\Component\Form\Extension\Core\CoreExtension()));

$this->setExpectedException('Symfony\Component\Form\Exception\CreationException',
'The options "invalid", "unknown" do not exist. Known options are: "data", "data_class", ' .
'"trim", "required", "read_only", "max_length", "pattern", "property_path", "by_reference", ' .
'"error_bubbling", "error_mapping", "label", "attr", "invalid_message", "invalid_message_parameters", ' .
'"translation_domain", "empty_data"'
);
$factory->createNamedBuilder($type, "text", "value", array("invalid" => "opt", "unknown" => "opt"));
}

public function testUnknownOption()
{
$type = new \Symfony\Component\Form\Extension\Core\Type\TextType();

$factory = new FormFactory(array(new \Symfony\Component\Form\Extension\Core\CoreExtension()));

$this->setExpectedException('Symfony\Component\Form\Exception\CreationException',
'The option "unknown" does not exist. Known options are: "data", "data_class", ' .
'"trim", "required", "read_only", "max_length", "pattern", "property_path", "by_reference", ' .
'"error_bubbling", "error_mapping", "label", "attr", "invalid_message", "invalid_message_parameters", ' .
'"translation_domain", "empty_data"'
);
$factory->createNamedBuilder($type, "text", "value", array("unknown" => "opt"));
}

private function createMockFactory(array $methods = array())
{
return $this->getMockBuilder('Symfony\Component\Form\FormFactory')
Expand Down

0 comments on commit 149bdb9

Please sign in to comment.