Exemplo n.º 1
0
 public function testSetAndGetKey()
 {
     $this->_field->setKey('testkey');
     $this->assertEquals('testkey', $this->_field->getKey());
 }
Exemplo n.º 2
0
 /**
  * Add a field
  *
  * Supports a field instance or a config array, in that case a new
  * field instance wil be created based on the options.
  *
  * @param Solarium_Query_Select_Component_Stats_Field|array $field
  * @return Solarium_Query_Select_Component_Stats Provides fluent interface
  */
 public function addField($field)
 {
     if (is_array($field)) {
         $field = new Solarium_Query_Select_Component_Stats_Field($field);
     }
     $key = $field->getKey();
     if (0 === strlen($key)) {
         throw new Solarium_Exception('A field must have a key value');
     }
     //double add calls for the same field are ignored, but non-unique keys cause an exception
     //@todo add trigger_error with a notice for double add calls?
     if (array_key_exists($key, $this->_fields) && $this->_fields[$key] !== $field) {
         throw new Solarium_Exception('A field must have a unique key value');
     } else {
         $this->_fields[$key] = $field;
     }
     return $this;
 }