Prevent invisible skipping of ResultSource proxy overrides
[dbsrgits/DBIx-Class.git] / t / resultsource / rsrc_proxy_invocation.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
3 $ENV{DBIC_ASSERT_NO_FAILING_SANITY_CHECKS} = 1;
4
5 use strict;
6 use warnings;
7
8 use Test::More;
9
10 use DBICTest;
11 use Sub::Quote 'quote_sub';
12
13 my $colinfo = DBICTest::Schema::Artist->result_source->column_info('artistid');
14
15 my $schema = DBICTest->init_schema ( no_deploy => 1 );
16 my $rsrc = $schema->source("Artist");
17
18 for my $overrides_marked_mandatory (0, 1) {
19   my $call_count;
20   my @methods_to_override = qw(
21     add_columns columns_info
22   );
23
24   my $attr = { attributes => [
25     $overrides_marked_mandatory
26       ? 'DBIC_method_is_mandatory_resultsource_proxy'
27       : 'DBIC_method_is_bypassable_resultsource_proxy'
28   ] };
29
30   for (@methods_to_override) {
31     $call_count->{$_} = 0;
32
33     quote_sub( "DBICTest::Schema::Artist::$_", <<'EOC', { '$cnt' => \\($call_count->{$_}) }, $attr );
34       $$cnt++;
35       shift->next::method(@_);
36 EOC
37   }
38
39   Class::C3->reinitialize() if DBIx::Class::_ENV_::OLD_MRO;
40
41   is_deeply
42     $rsrc->columns_info->{artistid},
43     $colinfo,
44     'Expected result from rsrc getter',
45   ;
46
47   $rsrc->add_columns("bar");
48
49   is_deeply
50     $call_count,
51     {
52       add_columns => ($overrides_marked_mandatory ? 1 : 0),
53
54       # ResultSourceProxy::add_columns will call colinfos as well
55       columns_info => ($overrides_marked_mandatory ? 2 : 0),
56     },
57     'expected rsrc proxy override callcounts',
58   ;
59 }
60
61 done_testing;