Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / xt / extra / diagnostics / many_to_many_warning.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
3 use strict;
4 use warnings;
5 use Test::More;
6
7
8 use DBICTest;
9
10 my $exp_warn = qr/The many-to-many relationship 'bars' is trying to create/;
11
12 {
13   my @w;
14   local $SIG{__WARN__} = sub { $_[0] =~ $exp_warn ? push @w, $_[0] : warn $_[0] };
15   my $code = gen_code ( suffix => 1 );
16
17   local $ENV{DBIC_OVERWRITE_HELPER_METHODS_OK};
18   eval "$code";
19   ok (! $@, 'Eval code without warnings suppression')
20     || diag $@;
21
22   ok (@w, "Warning triggered without DBIC_OVERWRITE_HELPER_METHODS_OK");
23 }
24
25 {
26   my @w;
27   local $SIG{__WARN__} = sub { $_[0] =~ $exp_warn ? push @w, $_[0] : warn $_[0] };
28
29   my $code = gen_code ( suffix => 2 );
30
31   local $ENV{DBIC_OVERWRITE_HELPER_METHODS_OK} = 1;
32   eval "$code";
33   ok (! $@, 'Eval code with warnings suppression')
34     || diag $@;
35
36   ok (! @w, "No warning triggered with DBIC_OVERWRITE_HELPER_METHODS_OK");
37 }
38
39 sub gen_code {
40
41   my $args = { @_ };
42   my $suffix = $args->{suffix};
43
44   return <<EOF;
45 use strict;
46 use warnings;
47
48 {
49   package #
50     DBICTest::Schema::Foo${suffix};
51   use base 'DBIx::Class::Core';
52
53   __PACKAGE__->table('foo');
54   __PACKAGE__->add_columns(
55     'fooid' => {
56       data_type => 'integer',
57       is_auto_increment => 1,
58     },
59   );
60   __PACKAGE__->set_primary_key('fooid');
61
62
63   __PACKAGE__->has_many('foo_to_bar' => 'DBICTest::Schema::FooToBar${suffix}' => 'bar');
64   __PACKAGE__->many_to_many( foos => foo_to_bar => 'bar' );
65 }
66 {
67   package #
68     DBICTest::Schema::FooToBar${suffix};
69
70   use base 'DBIx::Class::Core';
71   __PACKAGE__->table('foo_to_bar');
72   __PACKAGE__->add_columns(
73     'foo' => {
74       data_type => 'integer',
75     },
76     'bar' => {
77       data_type => 'integer',
78     },
79   );
80   __PACKAGE__->belongs_to('foo' => 'DBICTest::Schema::Foo${suffix}');
81   __PACKAGE__->belongs_to('bar' => 'DBICTest::Schema::Foo${suffix}');
82 }
83 {
84   package #
85     DBICTest::Schema::Bar${suffix};
86
87   use base 'DBIx::Class::Core';
88
89   __PACKAGE__->table('bar');
90   __PACKAGE__->add_columns(
91     'barid' => {
92       data_type => 'integer',
93       is_auto_increment => 1,
94     },
95   );
96
97   __PACKAGE__->set_primary_key('barid');
98   __PACKAGE__->has_many('foo_to_bar' => 'DBICTest::Schema::FooToBar${suffix}' => 'foo');
99
100   __PACKAGE__->many_to_many( bars => foo_to_bar => 'foo' );
101
102   sub add_to_bars {}
103 }
104 EOF
105
106 }
107
108 done_testing;