removed useless variable
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_component_setup.t
1 package TestAppComponents;
2 use warnings;
3 use strict;
4 use base 'Catalyst';
5
6 sub locate_components {
7     my @comps;
8     push @comps, "TestAppComponents::$_" for qw/
9         C::Bar
10         C::Foo::Bar
11         C::Foo::Foo::Bar
12         C::Foo::Foo::Foo::Bar
13         Controller::Bar::Bar::Bar::Foo
14         Controller::Bar::Bar::Foo
15         Controller::Bar::Foo
16         Controller::Foo
17         M::Bar
18         M::Foo::Bar
19         M::Foo::Foo::Bar
20         M::Foo::Foo::Foo::Bar
21         Model::Bar::Bar::Bar::Foo
22         Model::Bar::Bar::Foo
23         Model::Bar::Foo
24         Model::Foo
25         V::Bar
26         V::Foo::Bar
27         V::Foo::Foo::Bar
28         V::Foo::Foo::Foo::Bar
29         View::Bar::Bar::Bar::Foo
30         View::Bar::Bar::Foo
31         View::Bar::Foo
32         View::Foo
33     /;
34     return @comps;
35 }
36
37 __PACKAGE__->components( {} );
38
39 # this is so $c->container will work
40 __PACKAGE__->setup_config;
41
42 # this is so $c->log->warn will work
43 __PACKAGE__->setup_log;
44
45 for my $component (TestAppComponents->locate_components) {
46     eval <<COMPONENT;
47 package $component;
48 use warnings;
49 use strict;
50 use base 'Catalyst::Component';
51
52 1;
53 COMPONENT
54 }
55
56 package main;
57 use strict;
58 use warnings;
59
60 use Test::More;
61
62 my @comps = TestAppComponents->locate_components;
63
64 {
65     my @loaded_comps;
66     my $warnings = 0;
67
68     no warnings 'redefine';
69
70     local *Catalyst::Log::warn = sub { $warnings++ };
71     local *Catalyst::Utils::ensure_class_loaded = sub { my $class = shift; push @loaded_comps, $class; };
72
73     eval { TestAppComponents->setup_components };
74
75     ok( !$@, "setup_components doesnt die" );
76     ok( $warnings, "it warns about deprecated names" );
77     is_deeply( \@comps, \@loaded_comps, 'all components loaded' );
78 }
79
80 my @controllers = @comps[0..7];
81 my @models      = @comps[8..15];
82 my @views       = @comps[16..23];
83 my $container   = TestAppComponents->container;
84
85 is_deeply(
86     [ sort $container->get_sub_container('controller')->get_service_list ],
87     [ sort @controllers ],
88     'controllers are in the container',
89 );
90
91 is_deeply(
92     [ sort TestAppComponents->controllers ],
93     [ sort @controllers ],
94     'controllers are listed correctly by $c->controllers()',
95 );
96
97 is_deeply(
98     [ sort $container->get_sub_container('model')->get_service_list ],
99     [ sort @models ],
100     'models are in the container',
101 );
102
103 is_deeply(
104     [ sort TestAppComponents->models ],
105     [ sort @models ],
106     'models are listed correctly by $c->models()',
107 );
108
109 is_deeply(
110     [ sort $container->get_sub_container('view')->get_service_list ],
111     [ sort @views ],
112     'views are in the container',
113 );
114
115 is_deeply(
116     [ sort TestAppComponents->views ],
117     [ sort @views ],
118     'views are listed correctly by $c->views()',
119 );
120
121 is_deeply(
122     [ sort keys %{ TestAppComponents->components } ],
123     [ sort @comps ],
124     'all components are in the components accessor'
125 );
126
127 done_testing();