Test::Mock::MongoDB - mock module for MongoDB class.
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' }
Current module mocks MongoDB class. Can be run in two modes:
These modes controlled by: skip_init parameter.
skip_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().
new()
skip_init parameter can be:
e.g.: $mock = Test::Mock::MongoDB->new( skip_init => 'client' );
or
$mock = Test::Mock::MongoDB->new( skip_init => 'all' );
$mock = Test::Mock::MongoDB->new( skip_init => [ qw| client database | ] );
Returns object of class Test::Mock::MongoDB::MongoClient.
Returns object of class Test::Mock::MongoDB::Database.
Returns object of class Test::Mock::MongoDB::Collection.
Returns object of class Test::Mock::MongoDB::Cursor.
cono <cono@cpan.org>
Copyright 2014 - cono
Artistic v2.0
Test::Mock::Signature, Data::Pattern::Compare
To install Test::Mock::MongoDB, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Mock::MongoDB
CPAN shell
perl -MCPAN -e shell install Test::Mock::MongoDB
For more information on module installation, please visit the detailed CPAN module installation guide.