toArray() public method

public toArray ( )
Ejemplo n.º 1
0
 public function testReverse()
 {
     $c = new Collection('int', [1, 2, 3]);
     $r = $c->reverse();
     $this->assertEquals([3, 2, 1], $r->toArray());
     $this->assertEquals([1, 2, 3], $c->toArray());
 }
Ejemplo n.º 2
0
 public function testToArray()
 {
     $items = array();
     $items[] = new TestClassA(1);
     $items[] = new TestClassA(2);
     $items[] = new TestClassA(3);
     $col = new Collection('TestClassA', $items);
     $this->assertEquals($items, $col->toArray());
 }
Ejemplo n.º 3
0
 public function test_sorts_with_callback()
 {
     $col = new Collection('int', [3, 1, 4, 2]);
     $comparator = function ($a, $b) {
         if ($a == $b) {
             return 0;
         }
         return $a < $b ? -1 : 1;
     };
     $sorted = $col->sort($comparator);
     $this->assertEquals(1, $sorted->at(0));
     $this->assertEquals(2, $sorted->at(1));
     $this->assertEquals(3, $sorted->at(2));
     $this->assertEquals(4, $sorted->at(3));
     //collection is unchanged
     $this->assertEquals([3, 1, 4, 2], $col->toArray());
 }