Testing if MyApp::Container is used when it exists. Fallback to Catalyst::Container...
André Walker [Fri, 24 Jun 2011 03:54:30 +0000 (00:54 -0300)]
t/aggregate/unit_core_container_custom_container.t [new file with mode: 0644]

diff --git a/t/aggregate/unit_core_container_custom_container.t b/t/aggregate/unit_core_container_custom_container.t
new file mode 100644 (file)
index 0000000..647ddf0
--- /dev/null
@@ -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;