Ensure the stack properly deals and warns on Null-Pattern exception objects
[dbsrgits/DBIx-Class.git] / t / prefetch / count.t
index 49370a4..f973575 100644 (file)
@@ -3,10 +3,7 @@ use warnings;
 
 use Test::More;
 use lib qw(t/lib);
-use DBICTest;
-use DBIC::SqlMakerTest;
-
-plan tests => 23;
+use DBICTest ':DiffSQL';
 
 my $schema = DBICTest->init_schema();
 
@@ -15,7 +12,6 @@ my $cd_rs = $schema->resultset('CD')->search (
   { prefetch => ['tracks', 'artist'] },
 );
 
-
 is($cd_rs->count, 5, 'CDs with tracks count');
 is($cd_rs->search_related('tracks')->count, 15, 'Tracks associated with CDs count (before SELECT()ing)');
 
@@ -73,29 +69,27 @@ is_same_sql_bind (
       JOIN track tracks ON tracks.cd = cds.cdid
     WHERE ( me.artistid = ? )
   )',
-  [ [ 'me.artistid' => 4 ] ],
+  [ [ { sqlt_datatype => 'integer', dbic_colname => 'me.artistid' }
+      => 4 ] ],
 );
 
-
-TODO: {
+{
   local $TODO = "Chaining with prefetch is fundamentally broken";
+  $schema->is_executed_querycount( sub {
 
-  my $queries;
-  $schema->storage->debugcb ( sub { $queries++ } );
-  $schema->storage->debug (1);
-
-  my $cds = $cd2->search_related ('artist', {}, { prefetch => { cds => 'tracks' }, join => 'twokeys' })
+    my $cds = $cd2->search_related ('artist', {}, { prefetch => { cds => 'tracks' }, join => 'twokeys' })
                   ->search_related ('cds');
 
-  my $tracks = $cds->search_related ('tracks');
-
-  is($tracks->count, 2, "2 Tracks counted on cd via artist via one of the cds");
-  is(scalar($tracks->all), 2, "2 Tracks prefetched on cd via artist via one of the cds");
-  is($tracks->count, 2, "Cached 2 Tracks counted on cd via artist via one of the cds");
+    my $tracks = $cds->search_related ('tracks');
 
-  is($cds->count, 2, "2 CDs counted on artist via one of the cds");
-  is(scalar($cds->all), 2, "2 CDs prefetched on artist via one of the cds");
-  is($cds->count, 2, "Cached 2 CDs counted on artist via one of the cds");
+    is($tracks->count, 2, "2 Tracks counted on cd via artist via one of the cds");
+    is(scalar($tracks->all), 2, "2 Tracks prefetched on cd via artist via one of the cds");
+    is($tracks->count, 2, "Cached 2 Tracks counted on cd via artist via one of the cds");
 
-  is ($queries, 3, '2 counts + 1 prefetch?');
+    is($cds->count, 2, "2 CDs counted on artist via one of the cds");
+    is(scalar($cds->all), 2, "2 CDs prefetched on artist via one of the cds");
+    is($cds->count, 2, "Cached 2 CDs counted on artist via one of the cds");
+  }, 3, '2 counts + 1 prefetch?' );
 }
+
+done_testing;