RedUNIT\Base\Prefixes::testBasicOperations PHP Метод

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

Test basic CRUD operations.
public testBasicOperations ( )
    public function testBasicOperations()
    {
        //Can we dispense a naughty bean? (with underscore)
        $author = R::xdispense(AUTHOR);
        asrt($author instanceof OODBBean, TRUE);
        asrt($author->getMeta('type'), AUTHOR);
        $author->name = 'Mr. Quill';
        $book = R::xdispense(BOOK);
        asrt($book instanceof OODBBean, TRUE);
        asrt($book->getMeta('type'), BOOK);
        $book->title = 'Good Stories';
        $friend = R::xdispense(FRIEND);
        $friend->name = 'Muse';
        asrt($friend instanceof OODBBean, TRUE);
        asrt($friend->getMeta('type'), FRIEND);
        $publisher = R::xdispense(PUBLISHER);
        $publisher->name = 'Good Books';
        asrt($publisher instanceof OODBBean, TRUE);
        asrt($publisher->getMeta('type'), PUBLISHER);
        asrt(is_array($author->{BOOKLIST}), TRUE);
        //add books to the book list using the constant
        $author->{BOOKLIST}[] = $book;
        asrt(count($author->{BOOKLIST}), 1);
        //can we also add friends? (N-M)
        $author->{FRIENDLIST}[] = $friend;
        $author->{PUBLISHER} = $publisher;
        $id = R::store($author);
        asrt($id > 0, TRUE);
        $author = $author->fresh();
        //Can we add another friend after reload?
        $author->{FRIENDLIST}[] = R::xdispense(FRIEND)->setAttr('name', 'buddy');
        R::store($author);
        $author = $author->fresh();
        //Now check the contents of the bean, its lists (books,friends) and parent (publisher)
        asrt($author->name, 'Mr. Quill');
        asrt(count($author->{BOOKLIST}), 1);
        $firstBook = reset($author->{BOOKLIST});
        asrt($firstBook->title, 'Good Stories');
        asrt(count($author->{FRIENDLIST}), 2);
        $firstFriend = reset($author->{FRIENDLIST});
        $parent = $author->{PUBLISHER};
        asrt($parent instanceof OODBBean, TRUE);
        $tables = R::inspect();
        //have all tables been prefixed?
        foreach ($tables as $table) {
            asrt(strpos($table, 'tbl_'), 0);
        }
        //Can we make an export?
        $export = R::exportAll(R::findOne(AUTHOR), TRUE);
        $export = reset($export);
        asrt(isset($export[PUBLISHER]), TRUE);
        asrt(isset($export[BOOKLIST]), TRUE);
        asrt(isset($export[FRIENDLIST]), TRUE);
        asrt(isset($export['ownBook']), FALSE);
        asrt(isset($export['sharedFriend']), FALSE);
        asrt(isset($export['publisher']), FALSE);
        //Can we duplicate?
        $copy = R::dup($author);
        $copy->name = 'Mr. Clone';
        R::store($copy);
        $copy = $copy->fresh();
        asrt($copy->name, 'Mr. Clone');
        asrt(count($copy->{BOOKLIST}), 1);
        $firstBook = reset($copy->{BOOKLIST});
        asrt($firstBook->title, 'Good Stories');
        asrt(count($copy->{FRIENDLIST}), 2);
        $firstFriend = reset($copy->{FRIENDLIST});
        $parent = $copy->{PUBLISHER};
        asrt($parent instanceof OODBBean, TRUE);
        //Can we count?
        asrt(R::count(AUTHOR), 2);
        $copy = $copy->fresh();
        asrt($copy->countOwn(BOOK), 1);
        asrt($copy->countShared(FRIEND), 2);
        //Can we delete?
        R::trash($author);
        asrt(R::count(AUTHOR), 1);
        //Can we nuke?
        R::nuke();
        asrt(R::count(AUTHOR), 0);
        asrt(count(R::inspect()), 0);
    }