small sketch for custom container tests
André Walker [Wed, 3 Aug 2011 03:52:37 +0000 (00:52 -0300)]
t/aggregate/live_container_custom_container_nosugar.t [new file with mode: 0644]
t/aggregate/live_container_custom_container_sugar.t [new file with mode: 0644]
t/lib/TestCustomContainer.pm [new file with mode: 0644]

diff --git a/t/aggregate/live_container_custom_container_nosugar.t b/t/aggregate/live_container_custom_container_nosugar.t
new file mode 100644 (file)
index 0000000..79eaff1
--- /dev/null
@@ -0,0 +1,7 @@
+use warnings;
+use strict;
+use FindBin '$Bin';
+use lib "$Bin/../lib";
+use TestCustomContainer;
+
+TestCustomContainer->new(sugar => 0);
diff --git a/t/aggregate/live_container_custom_container_sugar.t b/t/aggregate/live_container_custom_container_sugar.t
new file mode 100644 (file)
index 0000000..0a6ee67
--- /dev/null
@@ -0,0 +1,7 @@
+use warnings;
+use strict;
+use FindBin '$Bin';
+use lib "$Bin/../lib";
+use TestCustomContainer;
+
+TestCustomContainer->new(sugar => 1);
diff --git a/t/lib/TestCustomContainer.pm b/t/lib/TestCustomContainer.pm
new file mode 100644 (file)
index 0000000..310cc19
--- /dev/null
@@ -0,0 +1,47 @@
+package TestCustomContainer;
+use Moose;
+use namespace::autoclean;
+use Test::More;
+
+has app_name => (
+    is => 'ro',
+    isa => 'Str',
+    default => 'TestAppCustomContainer',
+);
+
+has container_class => (
+    is => 'ro',
+    isa => 'Str',
+    lazy_build => 1,
+);
+
+has sugar => (
+    is => 'ro',
+    isa => 'Int',
+);
+
+sub BUILD {
+    my $self = shift;
+
+    $ENV{TEST_APP_CURRENT_CONTAINER} = $self->container_class;
+
+    require Catalyst::Test;
+    Catalyst::Test->import($self->app_name);
+
+    is(get('/container_class'), $self->container_class);
+    is(get('/container_isa'), $self->container_class);
+
+    done_testing;
+}
+
+sub _build_container_class {
+    my $self = shift;
+
+    my $sugar = $self->sugar ? '' : 'No';
+
+    return $self->app_name . "::${sugar}SugarContainer";
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;