Coder Social home page Coder Social logo

test-mock-mongodb's Introduction

NAME

Test::Mock::MongoDB - mock module for MongoDB class.

SYNOPSIS

Mock all constructors by default:

use Test::Mock::MongoDB qw( any );

my $mock         = Test::Mock::MongoDB->new;
my $m_client     = $mock->get_client;
my $m_database   = $mock->get_database;
my $m_collection = $mock->get_collection;
my $m_cursor     = $mock->get_cursor;

my $db = $client->get_database('foo');
my $collection = $db->get_collection('bar');

$m_collection->method(insert => { name => any })->callback(
    sub { 42 }
);
print $collection->insert({ name => 'cono'}); # 42

Or you can leave default MongoDB behaviour by skipping init:

my $mock = Test::Mock::MongoDB->new(skip_init => 'all');

$mock->get_collection->method(find_one => { name => 'ivan'})->callback(
    sub {
        return { name => 'cono'};
    }
);

my $doc = $collection->find_one({ name => 'ivan'}); # { name => 'cono' }

DESCRIPTION

Current module mocks MongoDB class. Can be run in two modes:

overrides constructors (does not need real connection)
do not override anything by default

These modes controlled by: skip_init parameter.

METHODS

init()

This method invoked from constructor new() in base class: Test::Mock::Signature. Current method implement logic of skip_init parameter passed into constructor new().

skip_init parameter can be:

client - skip init of Test::Mock::MongoDB::MongoClient
database - skip init of Test::Mock::MongoDB::Database
collection - skip init of Test::Mock::MongoDB::Collection
cursor - skip init of Test::Mock::MongoDB::Cursor
all - skips all init

e.g.: $mock = Test::Mock::MongoDB->new( skip_init => 'client' );

or

$mock = Test::Mock::MongoDB->new( skip_init => 'all' );

or

$mock = Test::Mock::MongoDB->new( skip_init => [ qw| client database | ] );

get_client() : Test::Mock::MongoDB::MongoClient

Returns object of class Test::Mock::MongoDB::MongoClient.

get_database() : Test::Mock::MongoDB::Database

Returns object of class Test::Mock::MongoDB::Database.

get_collection() : Test::Mock::MongoDB::Collection

Returns object of class Test::Mock::MongoDB::Collection.

get_cursor() : Test::Mock::MongoDB::Cursor

Returns object of class Test::Mock::MongoDB::Cursor.

AUTHOR

cono <[email protected]>

COPYRIGHT

Copyright 2014 - cono

LICENSE

Artistic v2.0

SEE ALSO

Test::Mock::Signature, Data::Pattern::Compare

test-mock-mongodb's People

Contributors

cono avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.