Nelmio\Alice\ObjectBag::count PHP Method

count() public method

public count ( )
    public function count()
    {
        return count($this->objects);
    }

Usage Example

Example #1
0
 public function testCountable()
 {
     $this->assertTrue(is_a(ObjectBag::class, \Countable::class, true));
     $bag = new ObjectBag();
     $this->assertEquals(0, $bag->count());
     $bag = new ObjectBag(['foo' => new \stdClass(), 'bar' => new \stdClass()]);
     $this->assertEquals(2, $bag->count());
     $object1 = new CompleteObject(new SimpleObject('foo', new \stdClass()));
     $object2 = new CompleteObject(new SimpleObject('bar', new \stdClass()));
     $bag = (new ObjectBag())->with($object1)->with($object2);
     $this->assertEquals(2, $bag->count());
     $object3 = new CompleteObject(new SimpleObject('foz', new \stdClass()));
     $object4 = new CompleteObject(new SimpleObject('baz', new \stdClass()));
     $anotherBag = (new ObjectBag())->with($object3)->with($object4);
     $bag = $bag->mergeWith($anotherBag);
     $this->assertEquals(4, $bag->count());
 }