fix for AccessorGroup
[dbsrgits/DBIx-Class.git] / t / 05components.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Test::More;
6
7 use lib qw(t/lib);
8 use DBICTest::ForeignComponent;
9
10 plan tests => 6;
11
12 #   Tests if foreign component was loaded by calling foreign's method
13 ok( DBICTest::ForeignComponent->foreign_test_method, 'foreign component' );
14
15 #   Test for inject_base to filter out duplicates
16 {   package DBICTest::_InjectBaseTest;
17     use base qw/ DBIx::Class /;
18     package DBICTest::_InjectBaseTest::A;
19     package DBICTest::_InjectBaseTest::B;
20     package DBICTest::_InjectBaseTest::C;
21 }
22 DBICTest::_InjectBaseTest->inject_base( 'DBICTest::_InjectBaseTest', qw/
23     DBICTest::_InjectBaseTest::A
24     DBICTest::_InjectBaseTest::B
25     DBICTest::_InjectBaseTest::B
26     DBICTest::_InjectBaseTest::C
27 /);
28 is_deeply( \@DBICTest::_InjectBaseTest::ISA,
29     [qw/
30         DBICTest::_InjectBaseTest::A
31         DBICTest::_InjectBaseTest::B
32         DBICTest::_InjectBaseTest::C
33         DBIx::Class
34     /],
35     'inject_base filters duplicates'
36 );
37
38 # Test for a warning with incorrect order in load_components
39 my @warnings = ();
40 {
41   package A::Test;
42   our @ISA = 'DBIx::Class';
43   {
44     local $SIG{__WARN__} = sub { push @warnings, shift};
45     __PACKAGE__->load_components(qw(Core UTF8Columns));
46   }
47 }
48 like( $warnings[0], qr/Core loaded before UTF8Columns/,
49       'warning issued for incorrect order in load_components()' );
50 is( scalar @warnings, 1,
51     'only one warning issued for incorrect load_components call' );
52
53 # Test that no warning is issued for the correct order in load_components
54 {
55   @warnings = ();
56   package B::Test;
57   our @ISA = 'DBIx::Class';
58   {
59     local $SIG{__WARN__} = sub { push @warnings, shift };
60     __PACKAGE__->load_components(qw(UTF8Columns Core));
61   }
62 }
63 is( scalar @warnings, 0,
64     'warning not issued for correct order in load_components()' );
65
66 use_ok('DBIx::Class::AccessorGroup');