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,
22 use Scalar::Util 'blessed';
25 use lib "$Bin/../lib";
26 use TestAppGetAllComponentServices;
28 ok(my $c = TestAppGetAllComponentServices->container, 'get the container');
29 can_ok($c, 'get_all_component_services');
30 ok(my $comp_services = $c->get_all_component_services, 'component services are fetched');
33 'TestAppGetAllComponentServices::Controller::Root' => {
35 service_isa => 'Catalyst::IOC::BlockInjection',
36 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
38 'TestAppGetAllComponentServices::Model::Foo' => {
40 service_isa => 'Catalyst::IOC::BlockInjection',
41 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
43 'TestAppGetAllComponentServices::Model::Bar' => {
45 service_isa => 'Catalyst::IOC::BlockInjection',
46 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
48 'TestAppGetAllComponentServices::Model::Baz' => {
50 service_isa => 'Catalyst::IOC::BlockInjection',
51 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
53 'TestAppGetAllComponentServices::View::Wibble' => {
55 service_isa => 'Catalyst::IOC::BlockInjection',
56 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
58 'TestAppGetAllComponentServices::View::Wobble' => {
60 service_isa => 'Catalyst::IOC::BlockInjection',
61 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
63 'TestAppGetAllComponentServices::View::Wubble' => {
65 service_isa => 'Catalyst::IOC::BlockInjection',
66 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
70 while (my ($class, $info) = each %$expected) {
71 ok(exists $comp_services->{$class}, "class $class exists in the returned hash");
72 my $received_info = $comp_services->{$class};
73 is($received_info->{type}, $info->{type}, 'type is ok');
74 isa_ok($received_info->{service}, $info->{service_isa}, 'service');
75 isa_ok($received_info->{backcompat_service}, $info->{bcpt_service_isa}, 'backcompat_service');
78 my %singleton_component_classes;
79 can_ok($c, 'get_all_singleton_lifecycle_components');
80 ok(my $singleton_comps = $c->get_all_singleton_lifecycle_components, 'singleton components are fetched');
81 while (my ($class, $comp) = each %$singleton_comps) {
82 ok(blessed $comp, "it's an object"); # it just happens this particular app has all components as objects, so I test it remains true
83 is($class, ref $comp, "of class $class");
85 ok(exists $expected->{$class}, "it's one of the existing components");
86 ok(!exists $singleton_component_classes{$class}, "it's the first instance of class $class");
87 $singleton_component_classes{$class} = 1;
89 is_deeply([ sort keys %$expected ], [ sort keys %singleton_component_classes ], 'all components returned');