Phalcon\Test\Unit\Mvc\CollectionTest::testShouldGetArrayOfCollectionsByUsingFind PHP Метод

testShouldGetArrayOfCollectionsByUsingFind() публичный Метод

Tests Collection::find
С версии: 2016-03-03
Автор: Serghei Iakovlev ([email protected])
    public function testShouldGetArrayOfCollectionsByUsingFind()
    {
        $this->specify("Collection::find does not return expected result", function () {
            $songs = Songs::find();
            expect(is_array($songs))->true();
            $this->clearCollection();
            $this->createDocument(['artist' => 'Radiohead', 'name' => 'Lotus Flower']);
            $songs = Songs::find();
            expect(is_array($songs))->true();
            expect($songs)->count(1);
            expect($songs[0]->_id)->isInstanceOf('MongoId');
            expect($songs[0]->artist)->equals('Radiohead');
            expect($songs[0]->name)->equals('Lotus Flower');
            $this->createDocument(['artist' => 'Massive Attack', 'name' => 'Teardrop']);
            $songs = Songs::find();
            expect(is_array($songs))->true();
            expect($songs)->count(2);
            expect($songs[1]->_id)->isInstanceOf('MongoId');
            expect($songs[1]->artist)->equals('Massive Attack');
            expect($songs[1]->name)->equals('Teardrop');
            expect((string) $songs[0]->_id)->notEquals((string) $songs[1]->_id);
            $this->createDocument(['artist' => 'Massive Attack', 'name' => 'Paradise Circus']);
            $songs = Songs::find();
            expect(is_array($songs))->true();
            expect($songs)->count(3);
            expect($songs[2]->_id)->isInstanceOf('MongoId');
            expect($songs[2]->artist)->equals('Massive Attack');
            expect($songs[2]->name)->equals('Paradise Circus');
            expect((string) $songs[0]->_id)->notEquals((string) $songs[1]->_id);
            expect((string) $songs[1]->_id)->notEquals((string) $songs[2]->_id);
            expect((string) $songs[2]->_id)->notEquals((string) $songs[0]->_id);
            $songs = Songs::find([['artist' => 'Massive Attack']]);
            expect(is_array($songs))->true();
            expect($songs)->count(2);
            expect($songs[0]->name)->equals('Teardrop');
            expect($songs[1]->name)->equals('Paradise Circus');
            $songs = Songs::find(['conditions' => ['artist' => 'Massive Attack']]);
            expect(is_array($songs))->true();
            expect($songs)->count(2);
            expect($songs[0]->name)->equals('Teardrop');
            expect($songs[1]->name)->equals('Paradise Circus');
            $songs = Songs::find(['conditions' => ['artist' => 'Massive Attack'], 'sort' => ['name' => 1]]);
            expect($songs[0]->name)->equals('Paradise Circus');
            expect($songs[1]->name)->equals('Teardrop');
            $songs = Songs::find(['conditions' => ['artist' => 'Massive Attack'], 'sort' => ['name' => 1], 'limit' => 1]);
            expect(is_array($songs))->true();
            expect($songs)->count(1);
            expect($songs[0]->name)->equals('Paradise Circus');
            $songs = Songs::find(['conditions' => ['artist' => 'Massive Attack'], 'limit' => 1]);
            expect(is_array($songs))->true();
            expect($songs)->count(1);
            expect($songs[0]->name)->equals('Teardrop');
        });
    }