8 push @INC, "$FindBin::Bin/lib";
11 plan skip_all => 'requires DBD::SQLite'
12 unless eval { require DBD::SQLite };
15 use DBIx::Class::RowCountStatistics;
21 use parent 'DBIx::Class::Storage::Statistics';
28 my ($self, @args) = @_;
29 push @_COMPLETE, \@args;
33 my $schema = TestSchema->connect(
34 'dbi:SQLite:dbname=:memory:',
38 cursor_class => 'DBIx::Class::RowCountStatistics',
42 $schema->storage->debugobj(TestStats->new);
43 $schema->storage->debug(1);
45 ok $schema, 'schema created';
46 is $schema->storage->cursor_class,
47 'DBIx::Class::RowCountStatistics',
50 my $rs = $schema->resultset('Test');
52 subtest 'count with ->next' => sub {
54 $rs->create({ id => $_ }) for 1..10;
56 my $rows = $rs->search_rs;
57 is ref($rows->cursor), 'DBIx::Class::RowCountStatistics',
61 is scalar(@_COMPLETE), 1, 'single complete call';
62 is $_COMPLETE[0][0], 10, 'full count';
63 ok length($_COMPLETE[0][1]), 'SQL was passed';
64 like $_COMPLETE[0][1], qr{SELECT}i, 'SQL contains SELECT';
68 subtest 'count with ->all' => sub {
70 $rs->create({ id => $_ }) for 1..10;
72 my $rows = $rs->search_rs;
73 is ref($rows->cursor), 'DBIx::Class::RowCountStatistics',
77 is scalar(@_COMPLETE), 1, 'single complete call';
78 is $_COMPLETE[0][0], 10, 'full count';
82 subtest 'empty' => sub {
85 my $rows = $rs->search_rs;
88 is scalar(@_COMPLETE), 1, 'single complete call';
89 is $_COMPLETE[0][0], 0, 'full count';
92 subtest 'no fetch' => sub {
94 $rs->create({ id => $_ }) for 1..10;
96 my $rows = $rs->search_rs;
98 is scalar(@_COMPLETE), 0, 'no complete calls';