a few fixes in the test, and the actual method
[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;
dcc2a475 22use Scalar::Util 'blessed';
5084877e 23use Test::Moose;
24use FindBin '$Bin';
25use lib "$Bin/../lib";
26use TestAppGetAllComponentServices;
27
28ok(my $c = TestAppGetAllComponentServices->container, 'get the container');
29can_ok($c, 'get_all_component_services');
30ok(my $comp_services = $c->get_all_component_services, 'component services are fetched');
31
32my $expected = {
33 'TestAppGetAllComponentServices::Controller::Root' => {
34 type => 'controller',
35 service_isa => 'Catalyst::IOC::BlockInjection',
36 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
37 },
38 'TestAppGetAllComponentServices::Model::Foo' => {
39 type => 'model',
40 service_isa => 'Catalyst::IOC::BlockInjection',
41 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
42 },
43 'TestAppGetAllComponentServices::Model::Bar' => {
44 type => 'model',
45 service_isa => 'Catalyst::IOC::BlockInjection',
46 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
47 },
48 'TestAppGetAllComponentServices::Model::Baz' => {
49 type => 'model',
50 service_isa => 'Catalyst::IOC::BlockInjection',
51 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
52 },
53 'TestAppGetAllComponentServices::View::Wibble' => {
54 type => 'view',
55 service_isa => 'Catalyst::IOC::BlockInjection',
56 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
57 },
58 'TestAppGetAllComponentServices::View::Wobble' => {
59 type => 'view',
60 service_isa => 'Catalyst::IOC::BlockInjection',
61 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
62 },
63 'TestAppGetAllComponentServices::View::Wubble' => {
64 type => 'view',
65 service_isa => 'Catalyst::IOC::BlockInjection',
66 bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection',
67 },
68};
69
70while (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');
76}
77
666d15c1 78my %singleton_component_classes;
79can_ok($c, 'get_all_singleton_lifecycle_components');
dcc2a475 80ok(my $singleton_comps = $c->get_all_singleton_lifecycle_components, 'singleton components are fetched');
81while (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");
666d15c1 84
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;
88}
dcc2a475 89is_deeply([ sort keys %$expected ], [ sort keys %singleton_component_classes ], 'all components returned');
666d15c1 90
5084877e 91done_testing;