Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Fix validation of $creationOptions in ElementFactory #232

Merged

Conversation

TysonAndre
Copy link
Contributor

@TysonAndre TysonAndre commented Sep 17, 2019

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:

  • Are you fixing a bug?

    • Detail how the bug is invoked currently. Calling __construct with Traversable
    • Detail the original, incorrect behavior. `__construct would throw a TypeError if passed a Traversable, contrary to documentation
    • Detail the new, expected behavior. __construct will convert traversables to arrays.
    • Base your feature on the master branch, and submit against that branch.
    • Add a regression test that demonstrates the bug, and proves the fix.
    • Add a CHANGELOG.md entry for the fix.
  • Are you creating a new feature?

    • Why is the new feature needed? What purpose does it serve?
    • How will users use the new feature?
    • Base your feature on the develop branch, and submit against that branch.
    • Add only one feature per pull request; split multiple features over multiple pull requests
    • Add tests for the new feature.
    • Add documentation for the new feature.
    • Add a CHANGELOG.md entry for the new feature.
  • Is this related to quality assurance?

  • Is this related to documentation?

@TysonAndre
Copy link
Contributor Author

TysonAndre commented Sep 24, 2019

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.

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.
@TysonAndre TysonAndre force-pushed the fix-creationOptions-check branch from ae5d326 to 637a97b Compare September 24, 2019 23:59
Added empty line between if statements
Removed redundant brackets
@michalbundyra
Copy link
Member

Thanks, @TysonAndre!

michalbundyra added a commit that referenced this pull request Oct 3, 2019
Fix validation of $creationOptions in ElementFactory
michalbundyra added a commit that referenced this pull request Oct 3, 2019
@michalbundyra michalbundyra merged commit 2cbf54f into zendframework:master Oct 3, 2019
michalbundyra added a commit that referenced this pull request Oct 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants