=head1 NAME Test::Mock::MongoDB - mock module for MongoDB class. =head1 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' } =head1 DESCRIPTION Current module mocks MongoDB class. Can be run in two modes: =over 8 =item overrides constructors (does not need real connection) =item do not override anything by default =back These modes controlled by: C parameter. =head1 METHODS =head2 init() This method invoked from constructor C in base class: L. Current method implement logic of C parameter passed into constructor C. C parameter can be: =over 8 =item client - skip init of L =item database - skip init of L =item collection - skip init of L =item cursor - skip init of L =item all - skips all init =back 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 | ] ); =head2 get_client() : L Returns object of class L. =head2 get_database() : L Returns object of class L. =head2 get_collection() : L Returns object of class L. =head2 get_cursor() : L Returns object of class L. =head1 AUTHOR cono Econo@cpan.orgE =head1 COPYRIGHT Copyright 2014 - cono =head1 LICENSE Artistic v2.0 =head1 SEE ALSO L, L