From: André Walker Date: Fri, 20 Jul 2012 03:34:48 +0000 (-0300) Subject: added test for new method get_all_component_services X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=5084877e2cbb4a0ecd44ac3dcd08b428899a72ed added test for new method get_all_component_services --- diff --git a/t/aggregate/unit_core_container_get_all_component_services.t b/t/aggregate/unit_core_container_get_all_component_services.t new file mode 100644 index 0000000..7f381c1 --- /dev/null +++ b/t/aggregate/unit_core_container_get_all_component_services.t @@ -0,0 +1,77 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +# FIXME +# the exact return value of get_all_component_services +# needs to be reviewed and discussed +# +# See also note in Catalyst::IOC::Container +# +# the temporary solution is +# { +# class_name => { +# type => (model|controller|view), +# service => Catalyst::IOC::*Injection instance, # most likely BlockInjection +# backcompat_service => Catalyst::IOC::ConstructorInjection instance or undef, +# }, +# class_name => ... +# } + +use Test::More; +use Test::Moose; +use FindBin '$Bin'; +use lib "$Bin/../lib"; +use TestAppGetAllComponentServices; + +ok(my $c = TestAppGetAllComponentServices->container, 'get the container'); +can_ok($c, 'get_all_component_services'); +ok(my $comp_services = $c->get_all_component_services, 'component services are fetched'); + +my $expected = { + 'TestAppGetAllComponentServices::Controller::Root' => { + type => 'controller', + service_isa => 'Catalyst::IOC::BlockInjection', + bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection', + }, + 'TestAppGetAllComponentServices::Model::Foo' => { + type => 'model', + service_isa => 'Catalyst::IOC::BlockInjection', + bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection', + }, + 'TestAppGetAllComponentServices::Model::Bar' => { + type => 'model', + service_isa => 'Catalyst::IOC::BlockInjection', + bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection', + }, + 'TestAppGetAllComponentServices::Model::Baz' => { + type => 'model', + service_isa => 'Catalyst::IOC::BlockInjection', + bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection', + }, + 'TestAppGetAllComponentServices::View::Wibble' => { + type => 'view', + service_isa => 'Catalyst::IOC::BlockInjection', + bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection', + }, + 'TestAppGetAllComponentServices::View::Wobble' => { + type => 'view', + service_isa => 'Catalyst::IOC::BlockInjection', + bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection', + }, + 'TestAppGetAllComponentServices::View::Wubble' => { + type => 'view', + service_isa => 'Catalyst::IOC::BlockInjection', + bcpt_service_isa => 'Catalyst::IOC::ConstructorInjection', + }, +}; + +while (my ($class, $info) = each %$expected) { + ok(exists $comp_services->{$class}, "class $class exists in the returned hash"); + my $received_info = $comp_services->{$class}; + is($received_info->{type}, $info->{type}, 'type is ok'); + isa_ok($received_info->{service}, $info->{service_isa}, 'service'); + isa_ok($received_info->{backcompat_service}, $info->{bcpt_service_isa}, 'backcompat_service'); +} + +done_testing; diff --git a/t/lib/TestAppGetAllComponentServices.pm b/t/lib/TestAppGetAllComponentServices.pm new file mode 100644 index 0000000..4218aa3 --- /dev/null +++ b/t/lib/TestAppGetAllComponentServices.pm @@ -0,0 +1,7 @@ +package TestAppGetAllComponentServices; +use Moose; +extends 'Catalyst'; +__PACKAGE__->setup_config; +__PACKAGE__->setup_components; +__PACKAGE__->meta->make_immutable; +1; diff --git a/t/lib/TestAppGetAllComponentServices/Controller/Root.pm b/t/lib/TestAppGetAllComponentServices/Controller/Root.pm new file mode 100644 index 0000000..00ad9dc --- /dev/null +++ b/t/lib/TestAppGetAllComponentServices/Controller/Root.pm @@ -0,0 +1,5 @@ +package TestAppGetAllComponentServices::Controller::Root; +use Moose; +BEGIN { extends 'Catalyst::Controller' }; +__PACKAGE__->meta->make_immutable; +1; diff --git a/t/lib/TestAppGetAllComponentServices/Model/Bar.pm b/t/lib/TestAppGetAllComponentServices/Model/Bar.pm new file mode 100644 index 0000000..8ff9654 --- /dev/null +++ b/t/lib/TestAppGetAllComponentServices/Model/Bar.pm @@ -0,0 +1,5 @@ +package TestAppGetAllComponentServices::Model::Bar; +use Moose; +extends 'Catalyst::Model'; +__PACKAGE__->meta->make_immutable; +1; diff --git a/t/lib/TestAppGetAllComponentServices/Model/Baz.pm b/t/lib/TestAppGetAllComponentServices/Model/Baz.pm new file mode 100644 index 0000000..6895a15 --- /dev/null +++ b/t/lib/TestAppGetAllComponentServices/Model/Baz.pm @@ -0,0 +1,5 @@ +package TestAppGetAllComponentServices::Model::Baz; +use Moose; +extends 'Catalyst::Model'; +__PACKAGE__->meta->make_immutable; +1; diff --git a/t/lib/TestAppGetAllComponentServices/Model/Foo.pm b/t/lib/TestAppGetAllComponentServices/Model/Foo.pm new file mode 100644 index 0000000..1695d05 --- /dev/null +++ b/t/lib/TestAppGetAllComponentServices/Model/Foo.pm @@ -0,0 +1,5 @@ +package TestAppGetAllComponentServices::Model::Foo; +use Moose; +extends 'Catalyst::Model'; +__PACKAGE__->meta->make_immutable; +1; diff --git a/t/lib/TestAppGetAllComponentServices/View/Wibble.pm b/t/lib/TestAppGetAllComponentServices/View/Wibble.pm new file mode 100644 index 0000000..b85bd8f --- /dev/null +++ b/t/lib/TestAppGetAllComponentServices/View/Wibble.pm @@ -0,0 +1,5 @@ +package TestAppGetAllComponentServices::View::Wibble; +use Moose; +extends 'Catalyst::View'; +__PACKAGE__->meta->make_immutable; +1; diff --git a/t/lib/TestAppGetAllComponentServices/View/Wobble.pm b/t/lib/TestAppGetAllComponentServices/View/Wobble.pm new file mode 100644 index 0000000..03ed514 --- /dev/null +++ b/t/lib/TestAppGetAllComponentServices/View/Wobble.pm @@ -0,0 +1,5 @@ +package TestAppGetAllComponentServices::View::Wobble; +use Moose; +extends 'Catalyst::View'; +__PACKAGE__->meta->make_immutable; +1; diff --git a/t/lib/TestAppGetAllComponentServices/View/Wubble.pm b/t/lib/TestAppGetAllComponentServices/View/Wubble.pm new file mode 100644 index 0000000..04294ce --- /dev/null +++ b/t/lib/TestAppGetAllComponentServices/View/Wubble.pm @@ -0,0 +1,5 @@ +package TestAppGetAllComponentServices::View::Wubble; +use Moose; +extends 'Catalyst::View'; +__PACKAGE__->meta->make_immutable; +1;