1 package TestCustomContainer;
3 use namespace::autoclean;
9 default => 'TestAppCustomContainer',
12 has container_class => (
23 # Reason for this class:
24 # I wanted have a set of tests that would test both the sugar version of the
25 # container, as the sugar-less. I figured I shouldn't just copy and paste
26 # the tests. So after struggling for hours to find a way to test twice
27 # against the same TestApp using only one file, I decided to break it
28 # into a separate class (this one), and call it at
29 # - live_container_custom_container_sugar.t and
30 # - live_container_custom_container_nosugar.t
31 # setting only the sugar attribute.
35 my $app = $self->app_name;
37 $ENV{TEST_APP_CURRENT_CONTAINER} = $self->container_class;
39 require Catalyst::Test;
40 Catalyst::Test->import($app);
42 is($app->config->{container_class}, $self->container_class, 'config is set properly');
43 isa_ok($app->container, $self->container_class, 'and container isa our container class');
46 ok(my ($res, $c) = ctx_request('/'), 'request');
47 ok($res->is_success, 'request 2xx');
48 is($res->content, 'foo', 'content is expected');
50 ok(my $model = $c->container->get_sub_container('model')->resolve(service => 'RequestLifeCycle', parameters => { ctx => $c, accept_context_args => [$c] } ), 'fetching RequestLifeCycle');
51 isa_ok($model, 'TestAppCustomContainer::Model::RequestLifeCycle');
53 ok(my $model2 = $c->model('RequestLifeCycle'), 'fetching RequestLifeCycle again');
54 is($model, $model2, 'object is not recreated during the same request');
60 sub _build_container_class {
63 my $sugar = $self->sugar ? '' : 'No';
65 return $self->app_name . "::${sugar}SugarContainer";
68 __PACKAGE__->meta->make_immutable;