zendframework / zend-form

Form component from Zend Framework
BSD 3-Clause "New" or "Revised" License
69 stars 87 forks source link

Fix validation of $creationOptions in ElementFactory #232

Closed TysonAndre closed 5 years ago

TysonAndre commented 5 years ago

In setCreationOptions(array $options), a TypeError would be thrown if it was anything other than an array.

Move the exceptions and traversable checks to the constructor.

(This impossible condition was detected by Phan)

Provide a narrative description of what you are trying to accomplish:

TysonAndre commented 5 years ago

Okay. Without this change to src/, the unit test I added would fail.

I don't see many uses of new ElementFactory directly after a quick search, and none of them had args.

There was 1 error:

1) ZendTest\Form\FormElementManagerTest::testCreationOptionsHandled
TypeError: Argument 1 passed to Zend\Form\ElementFactory::setCreationOptions() must be of the type array, object given, called in /path/to/zend-form/src/ElementFactory.php on line 41

/path/to/zend-form/src/ElementFactory.php:119
/path/to/zend-form/src/ElementFactory.php:41
/path/to/zend-form/test/ElementFactoryTest.php:36
/path/to/zend-form/test/ElementFactoryTest.php:26

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
michalbundyra commented 5 years ago

Thanks, @TysonAndre!