/**
  * @group legacy
  */
 public function testCreateViewForLegacyChoiceList()
 {
     // legacy ChoiceList instances provide legacy ChoiceView objects
     $preferred = array(new LegacyChoiceView('x', 'x', 'Preferred'));
     $other = array(new LegacyChoiceView('y', 'y', 'Other'));
     $list = $this->getMock('Symfony\\Component\\Form\\Extension\\Core\\ChoiceList\\ChoiceListInterface');
     $list->expects($this->once())->method('getPreferredViews')->will($this->returnValue($preferred));
     $list->expects($this->once())->method('getRemainingViews')->will($this->returnValue($other));
     $view = $this->factory->createView($list);
     $this->assertEquals(array(new ChoiceView('Other', 'y', 'y')), $view->choices);
     $this->assertEquals(array(new ChoiceView('Preferred', 'x', 'x')), $view->preferredChoices);
 }
 public function testCreateViewFlatAttrClosureReceivesValue()
 {
     $view = $this->factory->createView($this->list, array($this->obj2, $this->obj3), null, null, null, function ($object, $key, $value) {
         switch ($value) {
             case '1':
                 return array('attr1' => 'value1');
             case '2':
                 return array('attr2' => 'value2');
             default:
                 return array();
         }
     });
     $this->assertFlatViewWithAttr($view);
 }
 /**
  * {@inheritdoc}
  *
  * @deprecated Added for backwards compatibility in Symfony 2.7, to be
  *             removed in Symfony 3.0.
  */
 public function createListFromFlippedChoices($choices, $value = null)
 {
     if ($choices instanceof \Traversable) {
         $choices = iterator_to_array($choices);
     }
     // The value is not validated on purpose. The decorated factory may
     // decide which values to accept and which not.
     // We ignore the choice groups for caching. If two choice lists are
     // requested with the same choices, but a different grouping, the same
     // choice list is returned.
     DefaultChoiceListFactory::flattenFlipped($choices, $flatChoices);
     $hash = self::generateHash(array($flatChoices, $value), 'fromFlippedChoices');
     if (!isset($this->lists[$hash])) {
         $this->lists[$hash] = $this->decoratedFactory->createListFromFlippedChoices($choices, $value);
     }
     return $this->lists[$hash];
 }