6 # the exact return value of get_all_component_services
7 # needs to be reviewed and discussed
9 # See also note in Catalyst::IOC::Container
11 # the temporary solution is
14 # type => (model|controller|view),
15 # service => Catalyst::IOC::*Injection instance, # most likely BlockInjection
16 # backcompat_service => Catalyst::IOC::ConstructorInjection instance or undef,
24 use lib "$Bin/../lib";
25 use TestAppGetAllComponentServices;
27 ok(my $c = TestAppGetAllComponentServices->container, 'get the container');
28 can_ok($c, 'get_all_component_services');
29 ok(my $comp_services = $c->get_all_component_services, 'component services are fetched');
32 'TestAppGetAllComponentServices::Controller::Root' => {
34 service_isa => 'Catalyst::IOC::BlockInjection',
35 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
37 'TestAppGetAllComponentServices::Model::Foo' => {
39 service_isa => 'Catalyst::IOC::BlockInjection',
40 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
42 'TestAppGetAllComponentServices::Model::Bar' => {
44 service_isa => 'Catalyst::IOC::BlockInjection',
45 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
47 'TestAppGetAllComponentServices::Model::Baz' => {
49 service_isa => 'Catalyst::IOC::BlockInjection',
50 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
52 'TestAppGetAllComponentServices::View::Wibble' => {
54 service_isa => 'Catalyst::IOC::BlockInjection',
55 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
57 'TestAppGetAllComponentServices::View::Wobble' => {
59 service_isa => 'Catalyst::IOC::BlockInjection',
60 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
62 'TestAppGetAllComponentServices::View::Wubble' => {
64 service_isa => 'Catalyst::IOC::BlockInjection',
65 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
69 while (my ($class, $info) = each %$expected) {
70 ok(exists $comp_services->{$class}, "class $class exists in the returned hash");
71 my $received_info = $comp_services->{$class};
72 is($received_info->{type}, $info->{type}, 'type is ok');
73 isa_ok($received_info->{service}, $info->{service_isa}, 'service');
74 isa_ok($received_info->{backcompat_service}, $info->{bcpt_service_isa}, 'backcompat_service');
77 my %singleton_component_classes;
78 can_ok($c, 'get_all_singleton_lifecycle_components');
79 ok(my @singleton_comps = $c->get_all_singleton_lifecycle_components, 'singleton components are fetched');
80 foreach my $comp (@singleton_comps) {
81 blessed_ok($comp, "it's an object");
82 my $class = ref $comp;
84 ok(exists $expected->{$class}, "it's one of the existing components");
85 ok(!exists $singleton_component_classes{$class}, "it's the first instance of class $class");
86 $singleton_component_classes{$class} = 1;
88 is_deeply([ keys %$expected ], [ keys %singleton_component_classes ]);