count() public method

public count ( )
Exemplo n.º 1
0
 public function test_clear_returns_an_empty_collection()
 {
     $col = new Collection('TestClassA', [new TestClassA(1)]);
     //col will have one
     $this->assertEquals(1, $col->count());
     //empty should have no items
     $empty = $col->clear();
     $this->assertEquals(0, $empty->count());
     //col should remain unchanged
     $this->assertEquals(1, $col->count());
 }
Exemplo n.º 2
0
 public function test_add_item_creates_new_col_with_item()
 {
     $col = new Collection('TestClassA');
     //count should be zero
     $this->assertEquals(0, $col->count());
     $a = new TestClassA(1);
     //add the item
     $col2 = $col->add($a);
     //col should be unchanged
     $this->assertEquals(0, $col->count());
     $this->assertEquals(1, $col2->count());
     $this->assertEquals($a, $col2->at(0));
 }
Exemplo n.º 3
0
 public function test_add_range_adds_new_collection_with_items()
 {
     $col = new Collection('TestClassA');
     $range = [new TestClassA(0), new TestClassA(1)];
     $withRange = $col->merge($range);
     $this->assertEquals(0, $col->count());
     $this->assertEquals(2, $withRange->count());
     $this->assertEquals($range, $withRange->toArray());
 }
Exemplo n.º 4
0
 public function test_that_tail_gives_you_everything_but_head()
 {
     $col = new Collection('int', [1, 2, 3]);
     $tail = $col->tail();
     $this->assertEquals(2, $tail->count());
     //col shouldn't be changed and should have 3 items
     $this->assertEquals(3, $col->count());
     //check that tail has two and three
     $this->assertEquals(2, $tail->at(0));
     $this->assertEquals(3, $tail->at(1));
 }