This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Fabien Potencier 2ae1f90cbe merged branch chmielot/ticket_3298 (PR #3299)
Commits
-------

dbaddbb [Form] Allow empty choices array for ChoiceType

Discussion
----------

[Form] Allow empty choices array for ChoiceType

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes

The documentation about ChoiceType says, that default for 'choices' is array().
This is not allowed because an empty array evaluates to false:

if (!$options['choice_list'] && !$options['choices']) {

Use case: choices are empty and items are added dynamically.

---------------------------------------------------------------------------

by chmielot at 2012-02-07T21:03:03Z

Sorry, I messed up with the tickets. Didn't know a pull request opens a ticket.

---------------------------------------------------------------------------

by bschussek at 2012-02-08T08:23:29Z

This ticket depends on #3290 for being merged.

Apart from this, a test case is missing. Add this to ChoiceTypeTest:

    // https://github.com/symfony/symfony/issues/3298
    public function testInitializeWithEmptyChoices()
    {
        $this->factory->createNamed('choice', 'name', null, array(
            'choices' => array(),
        ));
    }

---------------------------------------------------------------------------

by craue at 2012-02-10T20:32:44Z

@bschussek: Why does it depend on #3290? I have issues with the `!$options['choices']` check even without #3290 applied.

---------------------------------------------------------------------------

by chmielot at 2012-02-10T21:24:28Z

Ok, I updated the branch with the test case and craue's suggestion on explicitly checking valid values.

---------------------------------------------------------------------------

by chmielot at 2012-02-11T09:07:05Z

Should be fine now.

---------------------------------------------------------------------------

by bschussek at 2012-02-11T09:15:10Z

Good. I see that you added a check for \Traversable too - can you add a test for this too? It should be fine to pass an empty \ArrayObject().

---------------------------------------------------------------------------

by craue at 2012-02-11T10:05:36Z

@bschussek: But even if there's passed something different than an array, the c'tor of `SimpleChoiceList` (which is called in line 45) is type hinted with `array` and won't allow passing a `Traversable` anyway, right?

---------------------------------------------------------------------------

by bschussek at 2012-02-11T10:16:36Z

@craue Yes. But in EntityType the choices option is reused and passed to EntityChoiceList, which extends ChoiceList and accepts any array or Traversable.

You're right though that it's not possible to add a test covering this in ChoiceTypeTest, and in EntityTypeTest this is already covered.

@fabpot Ready to merge.
2012-02-11 11:53:58 +01:00
src/Symfony [Form] Allow empty choices array for ChoiceType 2012-02-11 10:04:40 +01:00
tests [Form] Allow empty choices array for ChoiceType 2012-02-11 10:04:40 +01:00
.gitignore Added vendor directory to .gitignore 2010-06-24 10:44:28 +02:00
.travis.yml also test PHP 5.3.2, since this is the official lowest supported PHP version 2011-12-26 01:15:21 +01:00
autoload.php.dist [Tests] [Propel] Added some tests for the ModelChoiceList class 2012-02-05 23:08:07 +01:00
CHANGELOG-2.0.md updated CHANGELOG for 2.0.9 2012-01-06 07:48:27 +01:00
CHANGELOG-2.1.md merged branch vicb/profiler/routing (PR #3283) 2012-02-10 13:31:26 +01:00
check_cs [Check CS] don't replace 'else if' on twig files (closes #2961) 2011-12-27 16:10:32 +01:00
composer.json [MonologBundle] moved bundle to its own repository 2012-02-09 10:22:21 +01:00
CONTRIBUTORS.md update CONTRIBUTORS for 2.0.9 2012-01-06 07:49:05 +01:00
LICENSE added the LICENSE file for the YAML component 2011-02-18 11:52:11 +01:00
phpunit.xml.dist [Security] cleaned up opt-in to benchmark test 2011-03-06 20:06:13 +01:00
README.md set travis-ci icon to master 2011-11-23 11:36:09 +01:00
UPGRADE-2.1.md [Form] Fixed issues mentioned in the PR comments 2012-02-09 17:13:33 +01:00
vendors.php [MonologBundle] moved bundle to its own repository 2012-02-09 10:22:21 +01:00

README

Build Status

What is Symfony2?

Symfony2 is a PHP 5.3 full-stack web framework. It is written with speed and flexibility in mind. It allows developers to build better and easy to maintain websites with PHP.

Symfony can be used to develop all kind of websites, from your personal blog to high traffic ones like Dailymotion or Yahoo! Answers.

Requirements

Symfony2 is only supported on PHP 5.3.2 and up.

Installation

The best way to install Symfony2 is to download the Symfony Standard Edition available at http://symfony.com/download.

Documentation

The "Quick Tour" tutorial gives you a first feeling of the framework. If, like us, you think that Symfony2 can help speed up your development and take the quality of your work to the next level, read the official Symfony2 documentation.

Contributing

Symfony2 is an open source, community-driven project. If you'd like to contribute, please read the Contributing Code part of the documentation. If you're submitting a pull request, please follow the guidelines in the Submitting a Patch section.