Phalcon\Test\Unit\Mvc\CollectionTest::testShouldCreateIfNotExistDocument PHP Method

testShouldCreateIfNotExistDocument() public method

Tests Collection::createIfNotExist
Since: 2016-03-13
Author: Serghei Iakovlev ([email protected])
    public function testShouldCreateIfNotExistDocument()
    {
        $this->specify("Collection::createIfNotExist does not work correctly", function () {
            $song = new Songs();
            $song->artist = 'Cinema Strange';
            $song->name = 'Catacomb Kittens';
            expect($song->createIfNotExist(['name', 'artist']))->true();
            $song = new Songs();
            $song->artist = 'Cinema Strange';
            $song->name = 'Catacomb Kittens';
            expect($song->createIfNotExist(['name', 'artist']))->false();
            expect(Songs::count())->equals(5);
            expect(Songs::count([['artist' => 'Cinema Strange']]))->equals(2);
        });
    }