Esempio n. 1
0
 /**
  * @test
  */
 public function 添字配列がマージされている事を確認()
 {
     $expected = ['foo', 'bar', 'baz', 'qux'];
     $collection = new Collection(['foo', 'bar']);
     $actual = $collection->merge(['baz', 'qux'])->all();
     $this->assertEquals($expected, $actual);
 }
Esempio n. 2
0
 public function getHistory($operation = null)
 {
     $operationToRetrieve = strtolower($operation == null ? $this->currentTotalName : $operation);
     if ($this->operationValues->has($operationToRetrieve)) {
         return $this->operationValues[$operationToRetrieve]->getHistory();
     }
     throw new InvalidArgumentException("Operation {$operationToRetrieve} has not been initialized.");
 }
Esempio n. 3
0
 /**
  * @test
  */
 public function unshiftで先頭に要素を追加する()
 {
     $expected = ['baz', 'foo', 'bar'];
     $collection = new Collection(['foo', 'bar']);
     $sum = $collection->unshift('baz');
     $this->assertSame(3, $sum);
     $this->assertSame($expected, $collection->all());
 }
 /**
  * @test
  */
 public function 連想配列のキーがfooの要素だけを返す()
 {
     $data = ['foo' => 1, 'bar' => 2];
     $expected = ['foo' => 1];
     $collect = new Collection($data);
     $actual = $collect->select(function ($key) {
         return $key === 'foo';
     }, ARRAY_FILTER_USE_KEY)->all();
     $this->assertSame($expected, $actual);
 }
Esempio n. 5
0
 public function testLastItemValue()
 {
     $last = $this->collection->getLast();
     $this->assertSame(1, $last->getValue());
     $this->assertSame(0, $last->getKey());
     $this->collection->set('foo', 'value');
     $this->assertSame('foo', $this->collection->getLast()->getKey());
     $this->collection->remove('foo');
     $this->assertSame(1, $this->collection->getLast()->getValue());
     $this->setExpectedException('\\Exception');
     $this->collection->remove(0);
     $this->collection->getLast();
 }
 public function testGettingAvgItemsFromCollection()
 {
     $c = new Collection([(object) ['foo' => 10], (object) ['foo' => 20]]);
     $this->assertEquals(15, $c->avg('foo'));
     $c = new Collection([['foo' => 10], ['foo' => 20]]);
     $this->assertEquals(15, $c->avg('foo'));
     $c = new Collection([1, 2, 3, 4, 5]);
     $this->assertEquals(3, $c->avg());
     $c = new Collection();
     $this->assertNull($c->avg());
 }
Esempio n. 7
0
 /**
  * @test
  */
 public function valuesで添字のキーをリセットする()
 {
     $expected = [0 => ['foo' => 1], 1 => ['bar' => 2]];
     $data = [10 => ['foo' => 1], 11 => ['bar' => 2]];
     $collection = new Collection($data);
     $actual = $collection->values()->all();
     $this->assertEquals($expected, $actual);
 }
Esempio n. 8
0
 /**
  * {@inheritdoc}
  */
 public function count()
 {
     return $this->collection->count();
 }
Esempio n. 9
0
 /**
  * Sort the array using the given callback.
  *
  * @param  array    $array
  * @param  callable $callback
  *
  * @return array
  */
 public static function sort($array, callable $callback)
 {
     return Collection::make($array)->sortBy($callback)->all();
 }