summaryrefslogtreecommitdiffstats
path: root/t/subcontainers.t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-10-10 18:18:00 -0500
committerJesse Luehrs <doy@tozt.net>2011-10-10 18:18:00 -0500
commitb2118130f3b95818f332816eaf97b9349e881146 (patch)
treecf740310a2d09ba3ecf5a072ab3c2ffdadcc430a /t/subcontainers.t
parent7c56a672849f7b3d1a47d4ea70a88302519e0f37 (diff)
downloadbread-board-declare-b2118130f3b95818f332816eaf97b9349e881146.tar.gz
bread-board-declare-b2118130f3b95818f332816eaf97b9349e881146.zip
more tests
Diffstat (limited to 't/subcontainers.t')
-rw-r--r--t/subcontainers.t116
1 files changed, 110 insertions, 6 deletions
diff --git a/t/subcontainers.t b/t/subcontainers.t
index 992f873..b5921ce 100644
--- a/t/subcontainers.t
+++ b/t/subcontainers.t
@@ -2,6 +2,7 @@
use strict;
use warnings;
use Test::More;
+use Test::Moose;
{
package SubContainer;
@@ -28,15 +29,118 @@ use Test::More;
}
{
- my $c = Container->new;
- is($c->resolve(service => 'subcontainer/foo_sub'), 'FOOSUB');
- is($c->subcontainer->foo_sub, 'FOOSUB');
+ package InlineSubContainers;
+ use Moose;
+ use Bread::Board::Declare;
+ use Bread::Board;
+
+ has subcontainer => (
+ traits => ['Container'],
+ is => 'ro',
+ isa => 'Bread::Board::Container',
+ default => sub {
+ container Foo => as {
+ service bar => 'BAR';
+ };
+ },
+ );
+
+ has other_subcontainer => (
+ traits => ['Container'],
+ is => 'ro',
+ isa => 'Bread::Board::Container',
+ default => sub {
+ container Foo => as {
+ service baz => (
+ block => sub {
+ my $s = shift;
+ "other " . $s->param('other_bar');
+ },
+ dependencies => {
+ other_bar => '../subcontainer/bar',
+ },
+ );
+ },
+ },
+ );
}
{
- my $c = Container->new(subcontainer => SubContainer->new(foo_sub => 'SUBFOO'));
- is($c->resolve(service => 'subcontainer/foo_sub'), 'SUBFOO');
- is($c->subcontainer->foo_sub, 'SUBFOO');
+ package WithDeps;
+ use Moose;
+ use Bread::Board::Declare;
+
+ has thing => (
+ is => 'ro',
+ isa => 'Str',
+ value => 'THING',
+ );
+
+ has other_thing => (
+ is => 'ro',
+ isa => 'Str',
+ block => sub {
+ my $s = shift;
+ $s->param('foo_sub');
+ },
+ dependencies => ['sub/foo_sub'],
+ );
+
+ has sub => (
+ traits => ['Container'],
+ is => 'ro',
+ isa => 'SubContainer',
+ dependencies => {
+ foo_sub => 'thing',
+ },
+ );
}
+with_immutable {
+ {
+ my $c = Container->new;
+ is($c->resolve(service => 'subcontainer/foo_sub'), 'FOOSUB');
+ isa_ok($c->subcontainer, 'SubContainer');
+ is($c->subcontainer->foo_sub, 'FOOSUB');
+
+ my $c2 = Container->new;
+ isnt($c->subcontainer, $c2->subcontainer);
+ }
+
+ {
+ my $c = Container->new(subcontainer => SubContainer->new(foo_sub => 'SUBFOO'));
+ is($c->resolve(service => 'subcontainer/foo_sub'), 'SUBFOO');
+ isa_ok($c->subcontainer, 'SubContainer');
+ is($c->subcontainer->foo_sub, 'SUBFOO');
+ }
+
+ {
+ my $c = InlineSubContainers->new;
+
+ is($c->resolve(service => 'subcontainer/bar'), 'BAR');
+ isa_ok($c->subcontainer, 'Bread::Board::Container');
+ is($c->subcontainer->resolve(service => 'bar'), 'BAR');
+
+ is($c->resolve(service => 'other_subcontainer/baz'), 'other BAR');
+ isa_ok($c->other_subcontainer, 'Bread::Board::Container');
+ is($c->other_subcontainer->resolve(service => 'baz'), 'other BAR');
+ }
+
+ {
+ my $c = WithDeps->new;
+ is($c->resolve(service => 'sub/foo_sub'), 'THING');
+ is($c->thing, 'THING');
+ is($c->sub->foo_sub, 'THING');
+ is($c->other_thing, 'THING');
+ }
+
+ {
+ my $c = WithDeps->new(thing => 'GNIHT');
+ is($c->resolve(service => 'sub/foo_sub'), 'GNIHT');
+ is($c->thing, 'GNIHT');
+ is($c->sub->foo_sub, 'GNIHT');
+ is($c->other_thing, 'GNIHT');
+ }
+} 'SubContainer', 'Container', 'InlineSubContainers', 'WithDeps';
+
done_testing;