Skip to content

Commit 956fa58

Browse files
committed
bug symfony#9933 Propel1 exception message (jaugustin)
This PR was merged into the 2.3 branch. Discussion ---------- Propel1 exception message | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#9932 | License | MIT | Doc PR | none This add exception message for `ModelChoiceList` and `ModelType` when `class` parameter is not provided or invalid Commits ------- 047492f [Propel1Bridge][ModelChoiceList] add exception message for invalid classes
2 parents 34c0f1b + 047492f commit 956fa58

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
use Symfony\Component\Form\Exception\StringCastException;
1919
use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
20+
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
21+
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
2022
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
2123

2224
/**
@@ -84,6 +86,13 @@ public function __construct($class, $labelPath = null, $choices = null, $queryOb
8486
$this->class = $class;
8587

8688
$queryClass = $this->class.'Query';
89+
if (!class_exists($queryClass)) {
90+
if (empty($this->class)) {
91+
throw new MissingOptionsException('The "class" parameter is empty, you should provide the model class');
92+
}
93+
throw new InvalidOptionsException(sprintf('The query class "%s" is not found, you should provide the FQCN of the model class', $queryClass));
94+
}
95+
8796
$query = new $queryClass();
8897

8998
$this->query = $queryObject ?: $query;

src/Symfony/Bridge/Propel1/Tests/Form/ChoiceList/ModelChoiceListTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,20 @@ public function testDontAllowInvalidChoiceValues()
243243
$this->assertEquals(array(), $choiceList->getValuesForChoices(array(new Item(2, 'Bar'))));
244244
$this->assertEquals(array(), $choiceList->getChoicesForValues(array(2)));
245245
}
246+
247+
/**
248+
* @expectedException \Symfony\Component\OptionsResolver\Exception\MissingOptionsException
249+
*/
250+
public function testEmptyClass()
251+
{
252+
$choiceList = new ModelChoiceList('');
253+
}
254+
255+
/**
256+
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
257+
*/
258+
public function testInvalidClass()
259+
{
260+
$choiceList = new ModelChoiceList('Foo\Bar\DoesNotExistClass');
261+
}
246262
}

0 commit comments

Comments
 (0)