model Baz
André Walker [Mon, 15 Aug 2011 15:38:46 +0000 (12:38 -0300)]
t/lib/TestAppCustomContainer/NoSugarContainer.pm
t/lib/TestCustomContainer.pm

index 10f50fd..dc31971 100644 (file)
@@ -8,7 +8,7 @@ extends 'Catalyst::IOC::Container';
 sub BUILD {
     my $self = shift;
 
-    warn("Add Bar to model");
+    warn("Add SingletonLifeCycle to model");
     $self->get_sub_container('model')->add_service(
         Catalyst::IOC::ConstructorInjection->new(
             name             => 'SingletonLifeCycle',
@@ -22,29 +22,19 @@ sub BUILD {
         )
     );
 
-#    $self->get_sub_container('model')->add_service(
-#        # FIXME - i think it should be a ConstructorInjection
-#        # but only BlockInjection gets ctx parameter
-#        Catalyst::IOC::BlockInjection->new(
-#            name         => 'Baz',
-#            lifecycle    => '+Catalyst::IOC::LifeCycle::Request',
-#            dependencies => [
-#                Bread::Board::Dependency->new(
-#                    service_name => 'foo',
-#                    service_path => 'Foo',
-#
-#                    # FIXME - same as above
-#                    service_params => {
-#                        ctx => +{},
-#                        accept_context_args => [ +{} ],
-#                    },
-#                ),
-#            ],
-#            block => sub {
-#                TestAppCustomContainer::Model::Baz->new(foo => shift->param('foo'));
-#            },
-#        )
-#    );
+    $self->get_sub_container('model')->add_service(
+        # FIXME - i think it should be a ConstructorInjection
+        # but only BlockInjection gets ctx parameter
+        Catalyst::IOC::ConstructorInjection->new(
+            name         => 'Baz',
+            lifecycle    => '+Catalyst::IOC::LifeCycle::Request',
+            class        => 'TestAppCustomContainer::Model::Baz',
+            dependencies => {
+                application_name => depends_on( '/application_name' ),
+                foo => depends_on('/model/DefaultSetup'),
+            },
+        )
+    );
 
 # Broken deps!?!
 #    $self->get_sub_container('model')->add_service(
index 2bcbdfe..e4ac52b 100644 (file)
@@ -32,14 +32,15 @@ has sugar => (
 
 sub BUILD {
     my $self = shift;
+    my $app  = $self->app_name;
 
     $ENV{TEST_APP_CURRENT_CONTAINER} = $self->container_class;
 
     require Catalyst::Test;
-    Catalyst::Test->import($self->app_name);
+    Catalyst::Test->import($app);
 
-    is(get('/container_class'), $self->container_class, 'config is set properly');
-    is(get('/container_isa'), $self->container_class,   'and container isa our container class');
+    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
@@ -52,10 +53,6 @@ sub BUILD {
         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');
-
         # 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)');
@@ -75,10 +72,6 @@ sub BUILD {
         is($bar->accept_context_called, 1, 'ACCEPT_CONTEXT called');
         isa_ok($bar->foo, 'TestAppCustomContainer::Model::Foo', 'Bar 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->bar_got_it, 1, 'Bar accessed Foo once');
-
         # 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)');