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