X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flib%2FDBICTest%2FBaseSchema.pm;h=5fb9022f32ee93eb6329df66493039680e4e86f6;hb=49eeb48de3d8ff685926b595fa0f3f5e680eaee2;hp=ae8d74a69c69bb9bb1c462844d1554b20daf3ce6;hpb=2cfc22ddff9cb35524031dfc9d429d294b5e3d6e;p=dbsrgits%2FDBIx-Class.git diff --git a/t/lib/DBICTest/BaseSchema.pm b/t/lib/DBICTest/BaseSchema.pm index ae8d74a..5fb9022 100644 --- a/t/lib/DBICTest/BaseSchema.pm +++ b/t/lib/DBICTest/BaseSchema.pm @@ -44,12 +44,35 @@ sub capture_executed_sql_bind { local $self->storage->{debugobj} = my $tracer_obj = DBICTest::SQLTracerObj->new; local $self->storage->{debug} = 1; - + local $Test::Builder::Level = $Test::Builder::Level + 2; $cref->(); return $tracer_obj->{sqlbinds} || []; } +sub is_executed_querycount { + my ($self, $cref, $exp_counts, $msg) = @_; + + local $Test::Builder::Level = $Test::Builder::Level + 1; + + $self->throw_exception("Expecting an hashref of counts or an integer representing total query count") + unless ref $exp_counts eq 'HASH' or (defined $exp_counts and ! ref $exp_counts); + + my @got = map { $_->[0] } @{ $self->capture_executed_sql_bind($cref) }; + + return Test::More::is( @got, $exp_counts, $msg ) + unless ref $exp_counts; + + my $got_counts = { map { $_ => 0 } keys %$exp_counts }; + $got_counts->{$_}++ for @got; + + return Test::More::is_deeply( + $got_counts, + $exp_counts, + $msg, + ); +} + sub is_executed_sql_bind { my ($self, $cref, $sqlbinds, $msg) = @_;