lithium\tests\cases\util\CollectionTest::testCollectionFirstFilter PHP Method

testCollectionFirstFilter() public method

Tests that the first() method properly returns the first non-empty value.
    public function testCollectionFirstFilter()
    {
        $collection = new Collection(array('data' => array(0, 1, 2)));
        $result = $collection->first(function ($value) {
            return $value;
        });
        $this->assertEqual(1, $result);
        $collection = new Collection(array('data' => array('Hello', '', 'Goodbye')));
        $result = $collection->first(function ($value) {
            return $value;
        });
        $this->assertEqual('Hello', $result);
        $collection = new Collection(array('data' => array('', 'Hello', 'Goodbye')));
        $result = $collection->first(function ($value) {
            return $value;
        });
        $this->assertEqual('Hello', $result);
        $collection = new Collection(array('data' => array('', 'Hello', 'Goodbye')));
        $result = $collection->first();
        $this->assertEqual('', $result);
    }