public function testCompareChoicesByIdentityByDefault() { $callback = function ($choice) { return $choice->value; }; $obj1 = (object) array('value' => 'value1'); $obj2 = (object) array('value' => 'value2'); $choiceList = new ArrayChoiceList(array($obj1, $obj2), $callback); $this->assertSame(array(2 => 'value2'), $choiceList->getValuesForChoices(array(2 => $obj2))); $this->assertSame(array(2 => 'value2'), $choiceList->getValuesForChoices(array(2 => (object) array('value' => 'value2')))); }
public function testGetChoicesForValuesWithContainingEmptyStringAndBooleans() { $choiceList = new ArrayChoiceList(array('Empty String' => '', 'True' => true, 'False' => false)); $this->assertSame(array(0 => ''), $choiceList->getChoicesForValues(array(''))); $this->assertSame(array(0 => true), $choiceList->getChoicesForValues(array('1'))); $this->assertSame(array(0 => false), $choiceList->getChoicesForValues(array('0'))); }
public function testGetChoicesForValuesWithContainingNull() { $choiceList = new ArrayChoiceList(array('Null' => null)); $this->assertSame(array(0 => null), $choiceList->getChoicesForValues(array('0'))); }
/** * {@inheritdoc} */ public function getValuesForChoices(array $choices) { $choices = array_map(array(__CLASS__, 'toArrayKey'), $choices); if ($this->useChoicesAsValues) { // If the choices are identical to the values, we can just return // them to improve performance a little bit return array_map('strval', array_intersect($choices, $this->choices)); } return parent::getValuesForChoices($choices); }
public function testGetChoicesForValuesWithContainingEmptyStringAndFloats() { $choiceList = new ArrayChoiceList(array('Empty String' => '', '1/3' => 0.3, '1/2' => 0.5)); $this->assertSame(array(0 => ''), $choiceList->getChoicesForValues(array(''))); $this->assertSame(array(0 => 0.3), $choiceList->getChoicesForValues(array('0.3'))); $this->assertSame(array(0 => 0.5), $choiceList->getChoicesForValues(array('0.5'))); }