X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=xt%2Fextra%2Fdiagnostics%2Fmany_to_many_warning.t;fp=xt%2Fextra%2Fdiagnostics%2Fmany_to_many_warning.t;h=2c42091bff48f748860c2c5b387fb2b62aedc941;hb=c26b30dee587fa008f7d956b61ae27c36ac7ec82;hp=0000000000000000000000000000000000000000;hpb=245e3f5d9725813b4c73a05b6162b0d93b335fd2;p=dbsrgits%2FDBIx-Class.git diff --git a/xt/extra/diagnostics/many_to_many_warning.t b/xt/extra/diagnostics/many_to_many_warning.t new file mode 100644 index 0000000..2c42091 --- /dev/null +++ b/xt/extra/diagnostics/many_to_many_warning.t @@ -0,0 +1,106 @@ +use strict; +use warnings; +use Test::More; + +use lib qw(t/lib); +use DBICTest; + +my $exp_warn = qr/The many-to-many relationship 'bars' is trying to create/; + +{ + my @w; + local $SIG{__WARN__} = sub { $_[0] =~ $exp_warn ? push @w, $_[0] : warn $_[0] }; + my $code = gen_code ( suffix => 1 ); + + local $ENV{DBIC_OVERWRITE_HELPER_METHODS_OK}; + eval "$code"; + ok (! $@, 'Eval code without warnings suppression') + || diag $@; + + ok (@w, "Warning triggered without DBIC_OVERWRITE_HELPER_METHODS_OK"); +} + +{ + my @w; + local $SIG{__WARN__} = sub { $_[0] =~ $exp_warn ? push @w, $_[0] : warn $_[0] }; + + my $code = gen_code ( suffix => 2 ); + + local $ENV{DBIC_OVERWRITE_HELPER_METHODS_OK} = 1; + eval "$code"; + ok (! $@, 'Eval code with warnings suppression') + || diag $@; + + ok (! @w, "No warning triggered with DBIC_OVERWRITE_HELPER_METHODS_OK"); +} + +sub gen_code { + + my $args = { @_ }; + my $suffix = $args->{suffix}; + + return <table('foo'); + __PACKAGE__->add_columns( + 'fooid' => { + data_type => 'integer', + is_auto_increment => 1, + }, + ); + __PACKAGE__->set_primary_key('fooid'); + + + __PACKAGE__->has_many('foo_to_bar' => 'DBICTest::Schema::FooToBar${suffix}' => 'bar'); + __PACKAGE__->many_to_many( foos => foo_to_bar => 'bar' ); +} +{ + package # + DBICTest::Schema::FooToBar${suffix}; + + use base 'DBIx::Class::Core'; + __PACKAGE__->table('foo_to_bar'); + __PACKAGE__->add_columns( + 'foo' => { + data_type => 'integer', + }, + 'bar' => { + data_type => 'integer', + }, + ); + __PACKAGE__->belongs_to('foo' => 'DBICTest::Schema::Foo${suffix}'); + __PACKAGE__->belongs_to('bar' => 'DBICTest::Schema::Foo${suffix}'); +} +{ + package # + DBICTest::Schema::Bar${suffix}; + + use base 'DBIx::Class::Core'; + + __PACKAGE__->table('bar'); + __PACKAGE__->add_columns( + 'barid' => { + data_type => 'integer', + is_auto_increment => 1, + }, + ); + + __PACKAGE__->set_primary_key('barid'); + __PACKAGE__->has_many('foo_to_bar' => 'DBICTest::Schema::FooToBar${suffix}' => 'foo'); + + __PACKAGE__->many_to_many( bars => foo_to_bar => 'foo' ); + + sub add_to_bars {} +} +EOF + +} + +done_testing;