added test for 'get_all_singleton_lifecycle_components'
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_container_get_all_component_services.t
CommitLineData
5084877e 1#!/usr/bin/env perl
2use strict;
3use warnings;
4
5# FIXME
6# the exact return value of get_all_component_services
7# needs to be reviewed and discussed
8#
9# See also note in Catalyst::IOC::Container
10#
11# the temporary solution is
12# {
13# class_name => {
14# type => (model|controller|view),
15# service => Catalyst::IOC::*Injection instance, # most likely BlockInjection
16# backcompat_service => Catalyst::IOC::ConstructorInjection instance or undef,
17# },
18# class_name => ...
19# }
20
21use Test::More;
22use Test::Moose;
23use FindBin '$Bin';
24use lib "$Bin/../lib";
25use TestAppGetAllComponentServices;
26
27ok(my $c = TestAppGetAllComponentServices->container, 'get the container');
28can_ok($c, 'get_all_component_services');
29ok(my $comp_services = $c->get_all_component_services, 'component services are fetched');
30
31my $expected = {
32 'TestAppGetAllComponentServices::Controller::Root' => {
33 type => 'controller',
34 service_isa => 'Catalyst::IOC::BlockInjection',
35 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
36 },
37 'TestAppGetAllComponentServices::Model::Foo' => {
38 type => 'model',
39 service_isa => 'Catalyst::IOC::BlockInjection',
40 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
41 },
42 'TestAppGetAllComponentServices::Model::Bar' => {
43 type => 'model',
44 service_isa => 'Catalyst::IOC::BlockInjection',
45 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
46 },
47 'TestAppGetAllComponentServices::Model::Baz' => {
48 type => 'model',
49 service_isa => 'Catalyst::IOC::BlockInjection',
50 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
51 },
52 'TestAppGetAllComponentServices::View::Wibble' => {
53 type => 'view',
54 service_isa => 'Catalyst::IOC::BlockInjection',
55 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
56 },
57 'TestAppGetAllComponentServices::View::Wobble' => {
58 type => 'view',
59 service_isa => 'Catalyst::IOC::BlockInjection',
60 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
61 },
62 'TestAppGetAllComponentServices::View::Wubble' => {
63 type => 'view',
64 service_isa => 'Catalyst::IOC::BlockInjection',
65 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
66 },
67};
68
69while (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');
75}
76
666d15c1 77my %singleton_component_classes;
78can_ok($c, 'get_all_singleton_lifecycle_components');
79ok(my @singleton_comps = $c->get_all_singleton_lifecycle_components, 'singleton components are fetched');
80foreach my $comp (@singleton_comps) {
81 blessed_ok($comp, "it's an object");
82 my $class = ref $comp;
83
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;
87}
88is_deeply([ keys %$expected ], [ keys %singleton_component_classes ]);
89
5084877e 90done_testing;