Modify the null-branch pruning introduced in ce556881, restore compat
[dbsrgits/DBIx-Class.git] / t / resultset / inflate_result_api.t
index 558a662..a6914d9 100644 (file)
@@ -2,12 +2,10 @@ use strict;
 use warnings;
 
 use Test::More;
-use Test::Warn;
+use Test::Deep;
 use lib qw(t/lib);
 use DBICTest;
 
-my $new_collapser_version = DBIx::Class::ResultSet->can('_construct_objects');
-
 my $schema = DBICTest->init_schema(no_populate => 1);
 
 $schema->resultset('Artist')->create({ name => 'JMJ', cds => [{
@@ -58,12 +56,6 @@ $schema->resultset('CD')->create({ artist => 1, year => 1977, title => "fuzzy_1"
   sub inflate_result { [@_[2,3]] };
 }
 
-warnings_exist
-  { $schema->resultset ('CD')->search ({}, { result_class => 'DBICTest::_IRCapture', prefetch => 'tracks' } )->all }
-  qr/\QResultClass DBICTest::_IRCapture does not inherit from DBIx::Class::Row and therefore its inflate_result() will receive the full prefetched data tree, without any branch definedness checks/,
-  'Legacy inflate_result() API warned',
-if $new_collapser_version;
-
 cmp_structures(
   ([$schema->resultset ('CD')->search ({}, {
     result_class => 'DBICTest::_IRCapture',
@@ -73,31 +65,31 @@ cmp_structures(
   [
     [
       { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
-      { single_track => [
+      { single_track => bless( [
         { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
-        {  cd => [
+        {  cd => bless ( [
           { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
           {
-            artist => [
+            artist => bless ( [
               { artistid => undef, name => undef, charfield => undef, rank => undef }
-            ]
+            ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class )
           }
-        ] }
-      ] }
+        ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
+      ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
     ],
     [
       { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
-      { single_track => [
+      { single_track => bless( [
         { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
-        {  cd => [
+        {  cd => bless ( [
           { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
           {
-            artist => [
+            artist => bless ( [
               { artistid => undef, name => undef, charfield => undef, rank => undef }
-            ]
+            ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class )
           }
-        ] }
-      ] }
+        ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
+      ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
     ],
     [
       { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
@@ -115,60 +107,22 @@ cmp_structures(
     ],
     [
       { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
-      { single_track => [
+      { single_track => bless( [
         { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
-        {  cd => [
+        {  cd => bless ( [
           { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
           {
-            artist => [
+            artist => bless ( [
               { artistid => undef, name => undef, charfield => undef, rank => undef }
-            ]
-          }
-        ] }
-      ] }
-    ],
-  ],
-  'Simple 1:1 descend with classic prefetch legacy'
-);
-
-cmp_structures(
-  ([$schema->resultset ('CD')->search ({}, {
-    result_class => 'DBICTest::_IRCaptureAround',
-    prefetch => { single_track => { cd => 'artist' } },
-    order_by => 'me.cdid',
-  })->all]),
-  [
-    [
-      { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
-      { single_track => [] }
-    ],
-    [
-      { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
-      { single_track => [] }
-    ],
-    [
-      { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
-      { single_track => [
-        { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
-        {  cd => [
-          { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
-          {
-            artist => [
-              { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 }
-            ]
+            ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class )
           }
-        ] }
-      ] }
-    ],
-    [
-      { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
-      { single_track => [ ] }
+        ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
+      ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
     ],
   ],
-  'Simple 1:1 descend with classic prefetch pruning'
+  'Simple 1:1 descend with classic prefetch'
 );
 
-
 cmp_structures(
   [$schema->resultset ('CD')->search ({}, {
     result_class => 'DBICTest::_IRCapture',
@@ -185,7 +139,7 @@ cmp_structures(
   [
     [
       { artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
-      { single_track => [
+      { single_track => bless( [
         undef,
         {  cd => [
           undef,
@@ -195,11 +149,11 @@ cmp_structures(
             ]
           }
         ] }
-      ] }
+      ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
     ],
     [
       { artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
-      { single_track => [
+      { single_track => bless( [
         undef,
         {  cd => [
           undef,
@@ -209,7 +163,7 @@ cmp_structures(
             ]
           }
         ] }
-      ] }
+      ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
     ],
     [
       { artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
@@ -227,7 +181,7 @@ cmp_structures(
     ],
     [
       { artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
-      { single_track => [
+      { single_track => bless( [
         undef,
         {  cd => [
           undef,
@@ -237,54 +191,10 @@ cmp_structures(
             ]
           }
         ] }
-      ] }
-    ],
-  ],
-  'Simple 1:1 descend with missing selectors legacy'
-);
-
-cmp_structures(
-  [$schema->resultset ('CD')->search ({}, {
-    result_class => 'DBICTest::_IRCaptureAround',
-    join => { single_track => { cd => 'artist' } },
-    columns => [
-      { 'year'                                    => 'me.year' },
-      { 'genreid'                                 => 'me.genreid' },
-      { 'single_track.cd.artist.artistid'         => 'artist.artistid' },
-      { 'title'                                   => 'me.title' },
-      { 'artist'                                  => 'me.artist' },
-    ],
-    order_by => 'me.cdid',
-  })->all],
-  [
-    [
-      { artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
-      { single_track => [] }
-    ],
-    [
-      { artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
-      { single_track => [ ] }
-    ],
-    [
-      { artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
-      { single_track => [
-        undef,
-        {  cd => [
-          undef,
-          {
-            artist => [
-              { artistid => 1 }
-            ]
-          }
-        ] }
-      ] }
-    ],
-    [
-      { artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
-      { single_track => [] }
+      ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) }
     ],
   ],
-  'Simple 1:1 descend with missing selectors pruning'
+  'Simple 1:1 descend with missing selectors'
 );
 
 cmp_structures(
@@ -296,43 +206,43 @@ cmp_structures(
   [
     [
       { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
-      { single_track => [
+      { single_track => bless( [
         { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
         {  cd => [
           { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
           {
             artist => [
               { artistid => undef, name => undef, charfield => undef, rank => undef },
-              { cds => [ [
+              { cds => bless( [ [
                 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
-                { tracks => [ [
+                { tracks => bless( [ [
                   { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
-                ] ] },
-              ]]},
+                ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+              ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
             ],
           },
         ] },
-      ] },
+      ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
     ],
     [
       { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
-      { single_track => [
+      { single_track => bless( [
         { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
         {  cd => [
           { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
           {
             artist => [
               { artistid => undef, name => undef, charfield => undef, rank => undef },
-              { cds => [ [
+              { cds => bless( [ [
                 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
-                { tracks => [ [
+                { tracks => bless( [ [
                   { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
-                ] ] },
-              ]]},
-            ]
-          }
-        ] }
-      ] }
+                ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+              ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+            ],
+          },
+        ] },
+      ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
     ],
     [
       { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
@@ -346,9 +256,9 @@ cmp_structures(
               { cds => [
                 [
                   { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
-                  { tracks => [
+                  { tracks => bless( [
                     [ { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef } ],
-                  ] },
+                  ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
                 ],
                 [
                   { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
@@ -382,93 +292,26 @@ cmp_structures(
     ],
     [
       { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
-      { single_track => [
+      { single_track => bless( [
         { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
         {  cd => [
           { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
           {
             artist => [
               { artistid => undef, name => undef, charfield => undef, rank => undef },
-              { cds => [ [
+              { cds => bless( [ [
                 { cdid => undef, single_track => undef, artist => undef, genreid => undef, year => undef, title => undef },
-                { tracks => [ [
+                { tracks => bless( [ [
                   { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
-                ] ] },
-              ]]},
-            ]
-          }
-        ] }
-      ] }
-    ],
-  ],
-  'Collapsing 1:1 ending in chained has_many with classic prefetch legacy'
-);
-
-cmp_structures(
-  ([$schema->resultset ('CD')->search ({}, {
-    result_class => 'DBICTest::_IRCaptureAround',
-    prefetch => [ { single_track => { cd => { artist => { cds => 'tracks' } } } } ],
-    order_by => [qw/me.cdid tracks.trackid/],
-  })->all]),
-  [
-    [
-      { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
-      { single_track => [ ] },
-    ],
-    [
-      { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
-      { single_track => [ ] },
-    ],
-    [
-      { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
-      { single_track => [
-        { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
-        {  cd => [
-          { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
-          {
-            artist => [
-              { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
-              { cds => [
-                [
-                  { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
-                  { tracks => [ ] },
-                ],
-                [
-                  { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
-                  { tracks => [
-                    [ { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
-                    [ { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
-                    [ { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
-                    [ { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef } ],
-                  ]},
-                ],
-                [
-                  { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
-                  { tracks => [
-                    [ { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef } ],
-                    [ { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef } ],
-                  ]},
-                ],
-                [
-                  { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
-                  { tracks => [
-                    [ { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
-                    [ { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
-                    [ { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef } ],
-                  ]},
-                ],
-              ]},
-            ]
-          }
-        ] }
-      ] }
-    ],
-    [
-      { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
-      { single_track => [ ] },
+                ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+              ] ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
+            ],
+          },
+        ] },
+      ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
     ],
   ],
-  'Collapsing 1:1 ending in chained has_many with classic prefetch pruning'
+  'Collapsing 1:1 ending in chained has_many with classic prefetch'
 );
 
 cmp_structures (
@@ -567,126 +410,20 @@ cmp_structures (
       { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
       { cds => [
         { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
-        { tracks => [
+        { tracks => bless( [
           { trackid => undef, title => undef, position => undef, cd => undef, last_updated_at => undef, last_updated_on => undef },
-        ]},
-      ]},
-    ],
-  ],
-  'Non-Collapsing chained has_many legacy'
-);
-
-cmp_structures(
-  ([$schema->resultset ('Artist')->search ({}, {
-    result_class => 'DBICTest::_IRCaptureAround',
-    join => { cds => 'tracks' },
-    '+columns' => [
-      (map { "cds.$_" } $schema->source('CD')->columns),
-      (map { +{ "cds.tracks.$_" => "tracks.$_" } } $schema->source('Track')->columns),
-    ],
-    order_by => [qw/cds.cdid tracks.trackid/],
-  })->all]),
-  [
-    [
-      { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
-      { cds => [
-        { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
-        { tracks => [
-          { trackid => 1, title => 'm1', position => 1, cd => 1, last_updated_at => undef, last_updated_on => undef },
-        ]},
-      ]},
-    ],
-    [
-      { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
-      { cds => [
-        { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
-        { tracks => [
-          { trackid => 2, title => 'm2', position => 2, cd => 1, last_updated_at => undef, last_updated_on => undef },
-        ]},
-      ]},
-    ],
-    [
-      { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
-      { cds => [
-        { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
-        { tracks => [
-          { trackid => 3, title => 'm3', position => 3, cd => 1, last_updated_at => undef, last_updated_on => undef },
-        ]},
-      ]},
-    ],
-    [
-      { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
-      { cds => [
-        { cdid => 1, single_track => undef, artist => 1, genreid => 1, year => 1981, title => "Magnetic Fields" },
-        { tracks => [
-          { trackid => 4, title => 'm4', position => 4, cd => 1, last_updated_at => undef, last_updated_on => undef },
-        ]},
-      ]},
-    ],
-    [
-      { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
-      { cds => [
-        { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
-        { tracks => [
-          { trackid => 5, title => 'o2', position => 2, cd => 2, last_updated_at => undef, last_updated_on => undef },
-        ]},
-      ]},
-    ],
-    [
-      { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
-      { cds => [
-        { cdid => 2, single_track => undef, artist => 1, genreid => undef, year => 1976, title => "Oxygene" },
-        { tracks => [
-          { trackid => 6, title => 'o1', position => 1, cd => 2, last_updated_at => undef, last_updated_on => undef },
-        ]},
-      ]},
-    ],
-    [
-      { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
-      { cds => [
-        { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
-        { tracks => [
-          { trackid => 7, title => 'e1', position => 1, cd => 3, last_updated_at => undef, last_updated_on => undef },
-        ]},
-      ]},
-    ],
-    [
-      { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
-      { cds => [
-        { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
-        { tracks => [
-          { trackid => 8, title => 'e2', position => 2, cd => 3, last_updated_at => undef, last_updated_on => undef },
-        ]},
-      ]},
-    ],
-    [
-      { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
-      { cds => [
-        { cdid => 3, single_track => 6, artist => 1, genreid => 1, year => 1978, title => "Equinoxe" },
-        { tracks => [
-          { trackid => 9, title => 'e3', position => 3, cd => 3, last_updated_at => undef, last_updated_on => undef },
-        ]},
-      ]},
-    ],
-    [
-      { artistid => 1, name => 'JMJ', charfield => undef, rank => 13 },
-      { cds => [
-        { cdid => 4, single_track => undef, artist => 1, genreid => undef, year => 1977, title => "fuzzy_1" },
-        { tracks => [ ] },
+        ], $DBIx::Class::ResultSource::RowParser::Util::null_branch_class ) },
       ]},
     ],
   ],
-  'Non-Collapsing chained has_many pruning'
+  'Non-Collapsing chained has_many'
 );
 
 sub cmp_structures {
   my ($left, $right, $msg) = @_;
 
-  local $TODO = "Pruning test won't work on pre-rewrite DBIC"
-    if ($msg||'') =~ /pruning$/ and ! $new_collapser_version;
-
   local $Test::Builder::Level = $Test::Builder::Level + 1;
-  is_deeply($left, $right, $msg||());
+  cmp_deeply($left, $right, $msg||());
 }
 
 done_testing;