X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flib%2FTestCustomContainer.pm;h=e078730780d3b3ff850c0c1006a950d2f37853d4;hb=00676824273760b287b5c8321b96e53df13f3261;hp=e4ac52b43684867a67b7c4b536427201d40558d3;hpb=a5f37ed617de951c53b88723fb64f0ee3278a7db;p=catagits%2FCatalyst-Runtime.git diff --git a/t/lib/TestCustomContainer.pm b/t/lib/TestCustomContainer.pm index e4ac52b..e078730 100644 --- a/t/lib/TestCustomContainer.pm +++ b/t/lib/TestCustomContainer.pm @@ -39,56 +39,19 @@ 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'); { - # DefaultSetup ACCEPT_CONTEXT called - total: 1 - ok(my ($res, $c) = ctx_request('/get_model_baz'), 'request'); + ok(my ($res, $c) = ctx_request('/'), 'request'); ok($res->is_success, 'request 2xx'); - is($res->content, 'TestAppCustomContainer::Model::Baz', 'content is expected'); + is($res->content, 'foo', 'content is expected'); - ok(my $baz = $c->container->get_sub_container('model')->resolve(service => 'Baz', parameters => { ctx => $c, accept_context_args => [$c] } ), 'fetching Baz'); - isa_ok($baz, 'TestAppCustomContainer::Model::Baz'); - is($baz->accept_context_called, 1, 'ACCEPT_CONTEXT called'); - isa_ok($baz->foo, 'TestAppCustomContainer::Model::Foo', 'Baz got Foo ok'); + ok(my $model = $c->container->get_sub_container('model')->resolve(service => 'RequestLifeCycle', parameters => { ctx => $c, accept_context_args => [$c] } ), 'fetching RequestLifeCycle'); + isa_ok($model, 'TestAppCustomContainer::Model::RequestLifeCycle'); - # DefaultSetup ACCEPT_CONTEXT called - total: 2 - ok(get('/get_model_baz'), 'another request'); - is($baz->accept_context_called, 1, 'ACCEPT_CONTEXT not called again (instance per context)'); -# is($foo->baz_got_it, 2, 'Baz accessed Foo again'); - } - - { - # DefaultSetup ACCEPT_CONTEXT called - total: 3 - ok(my ($res, $c) = ctx_request('/get_model_bar'), 'request'); - ok($res->is_success, 'request 2xx'); - is($res->content, 'TestAppCustomContainer::Model::Bar', 'content is expected'); - - ok(my $bar = $c->container->get_sub_container('component')->resolve(service => 'model_Bar'), 'fetching Bar'); - isa_ok($bar, 'TestAppCustomContainer::Model::Bar'); - - # FIXME - is this expected behavior? - is($bar->accept_context_called, 1, 'ACCEPT_CONTEXT called'); - isa_ok($bar->foo, 'TestAppCustomContainer::Model::Foo', 'Bar got Foo ok'); - - # DefaultSetup ACCEPT_CONTEXT *not* called - total: 3 - ok(get('/get_model_bar'), 'another request'); - is($bar->accept_context_called, 1, 'ACCEPT_CONTEXT not called again (lifecycle is Singleton)'); -# is($foo->bar_got_it, 1, 'Bar didn\'t access Foo again'); - } - - { - # DefaultSetup ACCEPT_CONTEXT called - total: 4 - ok(my ($res, $c) = ctx_request('/get_model_foo'), 'request'); - ok($res->is_success, 'request 2xx'); - is($res->content, 'TestAppCustomContainer::Model::Foo', 'content is expected'); - -# ok(my $foo = $c->container->get_sub_container('component')->resolve(service => 'model_Foo'), 'fetching Foo'); -# isa_ok($foo, 'TestAppCustomContainer::Model::Foo'); -# is($foo->accept_context_called, 4, 'ACCEPT_CONTEXT called'); -# is($foo->bar_got_it, 1, 'Bar accessed Foo once'); -# is($foo->baz_got_it, 2, 'Baz accessed Foo twice'); + ok(my $model2 = $c->model('RequestLifeCycle'), 'fetching RequestLifeCycle again'); + is($model, $model2, 'object is not recreated during the same request'); } done_testing;