public function testAppendingMultipleElement() { $data = [new Entity(['id' => 1]), new Entity(['id' => 2])]; $collection = new Collection($data); $this->assertEquals(2, $collection->count()); $this->assertEquals([['id' => 1], ['id' => 2]], $collection->toArray()); }
public function test() { $e1 = new Entity(['id' => 1]); $collection = new Collection([$e2 = new Entity(['id' => 2]), $e3 = new Entity(['id' => 3])]); $collection->prepend($e1); $this->assertEquals([['id' => 1], ['id' => 2], ['id' => 3]], $collection->toArray()); }
public function test() { $collection = new Collection([new Entity(['id' => 1]), new Entity(['id' => 2]), new Entity(['id' => 3])]); $collection->walk(function ($entity) { $entity->id *= $entity->id; }); $this->assertEquals([['id' => 1], ['id' => 4], ['id' => 9]], $collection->toArray()); }
public function testCastingCollectionToArray() { $entity1 = new Entity(['one' => 1]); $entity2 = new Entity(['two' => 2]); $entity3 = new Entity(['three' => 3]); $collection = new Collection([$entity1, $entity2, $entity3]); $this->assertEquals([['one' => 1], ['two' => 2], ['three' => 3]], $collection->toArray()); }
public function test() { $collection = new Collection([$e1 = new Entity(['id' => 1]), $e2 = new Entity(['id' => 2]), $e3 = new Entity(['id' => 3])]); $collection->filter(function ($entity) { if ($entity->id == 2) { return false; } return true; }); $this->assertEquals([['id' => 1], ['id' => 3]], $collection->toArray()); }
public function test() { $collection = new Collection([new Entity(['id' => 1]), new Entity(['id' => 1]), new Entity(['id' => 1]), new Entity(['id' => 2]), new Entity(['id' => 3])]); $collection->distinctOn('id'); $this->assertEquals([['id' => 1], ['id' => 2], ['id' => 3]], $collection->toArray()); }