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