X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flib%2FTestCustomContainer.pm;h=8481b0c0effad16bb1e169aa7bbe0d0fee193ec8;hb=6329bfe593d5ea3891011333f7d7984b4e5e7910;hp=5f2c637ee9f2a24a42a3271532f67b594d13adcf;hpb=e5e7c93126fc179034b07bd6e2f0055b0aca6599;p=catagits%2FCatalyst-Runtime.git diff --git a/t/lib/TestCustomContainer.pm b/t/lib/TestCustomContainer.pm index 5f2c637..8481b0c 100644 --- a/t/lib/TestCustomContainer.pm +++ b/t/lib/TestCustomContainer.pm @@ -39,19 +39,43 @@ sub BUILD { require Catalyst::Test; Catalyst::Test->import($app); - is($app->config('container_class'), $self->container_class, 'config is set properly'); + is($app->config->{container_class}, $self->container_class, 'config is set properly'); isa_ok($app->container, $self->container_class, 'and container isa our container class'); + # RequestLifeCycle { - ok(my ($res, $c) = ctx_request('/'), 'request'); + # just to be sure the app is not broken + ok(my ($res, $ctx) = ctx_request('/'), 'request'); ok($res->is_success, 'request 2xx'); is($res->content, 'foo', 'content is expected'); - ok(my $model = $c->container->get_sub_container('model')->resolve(service => 'RequestLifeCycle', parameters => { ctx => $c, accept_context_args => [$c] } ), 'fetching RequestLifeCycle'); + ok(my $model = $ctx->container->get_sub_container('model')->resolve(service => 'RequestLifeCycle', parameters => { ctx => $ctx, accept_context_args => [$ctx] } ), 'fetching RequestLifeCycle'); isa_ok($model, 'TestAppCustomContainer::Model::RequestLifeCycle'); - ok(my $model2 = $c->model('RequestLifeCycle'), 'fetching RequestLifeCycle again'); + ok(my $model2 = $ctx->model('RequestLifeCycle'), 'fetching RequestLifeCycle again'); is($model, $model2, 'object is not recreated during the same request'); + + # another request + my ($res2, $ctx2) = ctx_request('/'); + ok($model2 = $ctx2->model('RequestLifeCycle'), 'fetching RequestLifeCycle again'); + isnt($model, $model2, 'object is recreated in a different request'); + } + + # SingletonLifeCycle + { + # already tested, I only need the $ctx + my ($res, $ctx) = ctx_request('/'); + + ok(my $model = $ctx->container->get_sub_container('model')->resolve(service => 'SingletonLifeCycle', parameters => { ctx => $ctx, accept_context_args => [$ctx] } ), 'fetching SingletonLifeCycle'); + isa_ok($model, 'TestAppCustomContainer::Model::SingletonLifeCycle'); + + ok(my $model2 = $ctx->model('SingletonLifeCycle'), 'fetching SingletonLifeCycle again'); + is($model, $model2, 'object is not recreated during the same request'); + + # another request + my ($res2, $ctx2) = ctx_request('/'); + ok($model2 = $ctx2->model('SingletonLifeCycle'), 'fetching SingletonLifeCycle again'); + is($model, $model2, 'object is not recreated in a different request'); } done_testing;