From: André Walker Date: Mon, 8 Aug 2011 03:27:20 +0000 (-0300) Subject: improved test for custom container - testing baz X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fe3f6b6d494628286575fe99103826bf9371df33;p=catagits%2FCatalyst-Runtime.git improved test for custom container - testing baz --- diff --git a/t/lib/TestAppCustomContainer/NoSugarContainer.pm b/t/lib/TestAppCustomContainer/NoSugarContainer.pm index b6658b2..8982966 100644 --- a/t/lib/TestAppCustomContainer/NoSugarContainer.pm +++ b/t/lib/TestAppCustomContainer/NoSugarContainer.pm @@ -11,11 +11,12 @@ sub BUILD { $self->get_sub_container('component')->add_service( Catalyst::IOC::ConstructorInjection->new( name => 'model_Bar', + lifecycle => 'Singleton', class => 'TestAppCustomContainer::Model::Bar', dependencies => [ depends_on( '/application_name' ), depends_on( '/config' ), - depends_on( '/model/Foo' ), + depends_on( 'model_Foo' ), ], ) ); @@ -23,7 +24,13 @@ sub BUILD { Catalyst::IOC::BlockInjection->new( name => 'Bar', dependencies => [ - depends_on( '/model/Foo' ), + Bread::Board::Dependency->new( + service_path => 'Foo', + service_params => { + ctx => +{}, + accept_context_args => [ +{} ], + }, + ), depends_on( '/component/model_Bar' ), ], block => sub { @@ -41,11 +48,12 @@ sub BUILD { Catalyst::IOC::ConstructorInjection->new( name => 'model_Baz', class => 'TestAppCustomContainer::Model::Baz', - lifecycle => '+Catalyst::IOC::LifeCycle::Request', + lifecycle => 'Singleton', + #lifecycle => '+Catalyst::IOC::LifeCycle::Request', dependencies => [ depends_on( '/application_name' ), depends_on( '/config' ), - depends_on( '/model/Foo' ), + depends_on( 'model_Foo' ), ], ) ); @@ -53,7 +61,13 @@ sub BUILD { Catalyst::IOC::BlockInjection->new( name => 'Baz', dependencies => [ - depends_on( '/model/Foo' ), + Bread::Board::Dependency->new( + service_path => 'Foo', + service_params => { + ctx => +{}, + accept_context_args => [ +{} ], + }, + ), depends_on( '/component/model_Baz' ), ], block => sub { diff --git a/t/lib/TestCustomContainer.pm b/t/lib/TestCustomContainer.pm index 1ec4d96..02fb9de 100644 --- a/t/lib/TestCustomContainer.pm +++ b/t/lib/TestCustomContainer.pm @@ -41,6 +41,21 @@ sub BUILD { is(get('/container_class'), $self->container_class); is(get('/container_isa'), $self->container_class); + { + ok(my ($res, $c) = ctx_request('/get_model_baz'), 'request'); + ok($res->is_success, 'request 2xx'); + is($res->content, 'TestAppCustomContainer::Model::Baz', 'content is expected'); + + ok(my $baz = $c->container->get_sub_container('component')->resolve(service => 'model_Baz'), '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 $foo = $c->container->get_sub_container('component')->resolve(service => 'model_Foo'), 'fetching Foo'); + isa_ok($foo, 'TestAppCustomContainer::Model::Foo'); + is($foo->baz_got_it, 1, 'Baz accessed Foo once'); + } + done_testing; }