From: André Walker Date: Fri, 24 Jun 2011 03:54:30 +0000 (-0300) Subject: Testing if MyApp::Container is used when it exists. Fallback to Catalyst::Container... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=ff80a7101b25f8ac186eebaa1c007caae5d1afcf Testing if MyApp::Container is used when it exists. Fallback to Catalyst::Container when it doesn't --- diff --git a/t/aggregate/unit_core_container_custom_container.t b/t/aggregate/unit_core_container_custom_container.t new file mode 100644 index 0000000..647ddf0 --- /dev/null +++ b/t/aggregate/unit_core_container_custom_container.t @@ -0,0 +1,46 @@ +use strict; +use warnings; +use Test::More; + +# first, test if it loads Catalyst::Container when +# no custom container exists +{ + package ContainerTestApp; + use Moose; + BEGIN { extends 'Catalyst' }; + + __PACKAGE__->setup_config(); + __PACKAGE__->setup_log(); +} + +my $container = ContainerTestApp->container; + +# 'is' instead of 'isa_ok', because I want it to be only Catalyst::Container +# and not some subclass +is( ref $container, 'Catalyst::Container', 'The container is Catalyst::Container, not a subclass'); + +# now, check if it loads the subclass when it exists +{ + package CustomContainerTestApp::Container; + use Moose; + BEGIN { extends 'Catalyst::Container' }; + + sub my_custom_method { 1 } +} + +{ + package CustomContainerTestApp; + use Moose; + BEGIN { extends 'Catalyst' }; + + __PACKAGE__->setup_config(); +} + +$container = CustomContainerTestApp->container; + +isa_ok($container, 'CustomContainerTestApp::Container'); +isa_ok($container, 'Catalyst::Container'); +can_ok($container, 'my_custom_method'); +ok( eval { $container->my_custom_method }, 'executes the method correctly'); + +done_testing;