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 <cono@cpan.org>

COPYRIGHT

Copyright 2014 - cono

LICENSE

Artistic v2.0

SEE ALSO

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