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