protected function _getTagString()
 {
     if (isset($this->_properties['tag_string'])) {
         return $this->_properties['tag_string'];
     }
     if (empty($this->tags)) {
         return '';
     }
     $tags = new Collection($this->tags);
     $str = $tags->reduce(function ($string, $tag) {
         return $string . $tag->label . ', ';
     }, '');
     return trim($str, ', ');
 }
Exemplo n.º 2
0
 /**
  * Tests reduce
  *
  * @return void
  */
 public function testReduce()
 {
     $items = ['a' => 1, 'b' => 2, 'c' => 3];
     $collection = new Collection($items);
     $callable = $this->getMock('stdClass', ['__invoke']);
     $callable->expects($this->at(0))->method('__invoke')->with(10, 1, 'a')->will($this->returnValue(11));
     $callable->expects($this->at(1))->method('__invoke')->with(11, 2, 'b')->will($this->returnValue(13));
     $callable->expects($this->at(2))->method('__invoke')->with(13, 3, 'c')->will($this->returnValue(16));
     $this->assertEquals(16, $collection->reduce($callable, 10));
 }
Exemplo n.º 3
0
 /**
  * Tests reduce without initial value
  *
  * @return void
  */
 public function testReduceWithoutInitialValue()
 {
     $items = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4];
     $collection = new Collection($items);
     $callable = $this->getMock('stdClass', ['__invoke']);
     $callable->expects($this->at(0))->method('__invoke')->with(1, 2, 'b')->will($this->returnValue(3));
     $callable->expects($this->at(1))->method('__invoke')->with(3, 3, 'c')->will($this->returnValue(6));
     $callable->expects($this->at(2))->method('__invoke')->with(6, 4, 'd')->will($this->returnValue(10));
     $this->assertEquals(10, $collection->reduce($callable));
 }