File: | t/store-sqlite.t |
Coverage: | 98.5% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | 1 1 1 | 126348 8 55 | use strict; | ||||
2 | 1 1 1 | 9 5 37 | use warnings; | ||||
3 | |||||||
4 | 1 1 1 | 2245 2828215 15 | use Test::Most; | ||||
5 | 1 1 1 | 831799 145567 347 | use Test::MockModule; | ||||
6 | |||||||
7 | 1 | 284129 | package MockDBI { | ||||
8 | sub new { | ||||||
9 | 2 | 22 | return bless( {}, shift ); | ||||
10 | } | ||||||
11 | sub do {} | ||||||
12 | sub prepare { | ||||||
13 | 3 | 30 | return shift; | ||||
14 | } | ||||||
15 | sub execute {} | ||||||
16 | sub fetchrow_array { | ||||||
17 | 1 | 6 | return '{"value":"things"}'; | ||||
18 | } | ||||||
19 | 0 | 0 | }; | ||||
20 | 1 | 14 | my $store = Test::MockModule->new('DBI'); | ||||
21 | 1 2 | 48 18 | $store->mock( connect => sub { return MockDBI->new } ); | ||||
22 | |||||||
23 | 1 1 1 | 293 7 480 | use constant MODULE => 'Bot::IRC::Store::SQLite'; | ||||
24 | |||||||
25 | 1 1 1 1 1 | 14 21106 6 5 244 | BEGIN { use_ok(MODULE); } | ||||
26 | 1 1 1 1 1 | 66081 17384 6 5 30 | BEGIN { use_ok('Bot::IRC'); } | ||||
27 | |||||||
28 | 1 | 96 | ok( MODULE->can('init'), 'init() method exists' ); | ||||
29 | |||||||
30 | 1 | 867 | my $plugin; | ||||
31 | 1 | 15 | my $bot = Bot::IRC->new( connect => { server => 'irc.perl.org' } ); | ||||
32 | |||||||
33 | 1 1 | 14 37 | lives_ok( sub { $plugin = MODULE->new($bot) }, 'new()' ); | ||||
34 | 1 1 | 618 30 | lives_ok( sub { Bot::IRC::Store::SQLite::init($bot) }, 'init()' ); | ||||
35 | |||||||
36 | 1 | 498 | ok( $bot->can('store'), 'store() method exists' ); | ||||
37 | 1 | 376 | ok( $bot->store->can('set'), 'set() method exists' ); | ||||
38 | 1 | 345 | ok( $bot->store->can('get'), 'get() method exists' ); | ||||
39 | |||||||
40 | 1 1 | 395 31 | lives_ok( sub { $bot->store->set( stuff => 'things' ) }, 'set()' ); | ||||
41 | 1 1 | 316 22 | lives_ok( sub { $bot->store->get('stuff') }, 'get()' ); | ||||
42 | |||||||
43 | 1 | 428 | done_testing; |