summaryrefslogtreecommitdiffstats
path: root/t/50-infer.t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-04-16 16:42:28 -0500
committerJesse Luehrs <doy@tozt.net>2011-04-16 16:42:28 -0500
commit30579545ce1517fb1b42a84dbb940e8d75aaa081 (patch)
tree75bec7bab63c49272940c909c07cde095e8ff25d /t/50-infer.t
parent8ae4f9f692f39a7a6dd6fed422b878d568210269 (diff)
downloadbread-board-declare-30579545ce1517fb1b42a84dbb940e8d75aaa081.tar.gz
bread-board-declare-30579545ce1517fb1b42a84dbb940e8d75aaa081.zip
more tests
Diffstat (limited to 't/50-infer.t')
-rw-r--r--t/50-infer.t61
1 files changed, 61 insertions, 0 deletions
diff --git a/t/50-infer.t b/t/50-infer.t
index bae915d..75879fa 100644
--- a/t/50-infer.t
+++ b/t/50-infer.t
@@ -124,6 +124,13 @@ use Test::Fatal;
isa_ok($c->baz, 'Baz2');
isa_ok($c->baz->foo, 'Foo');
isa_ok($c->baz->bar, 'Bar');
+
+ is(
+ $c->fetch('baz')->get_dependency('foo')->service,
+ $c->fetch('foo'),
+ "inferred the right dependency"
+ );
+
is($c->baz->foo->data, 'THING',
"inference finds services in the container");
is($c->baz->thing, 'THING', "partial dependency specification works");
@@ -185,4 +192,58 @@ use Test::Fatal;
is($c->quux2->foo->data, 'DATA', "but can be explicitly specified");
}
+{
+ package State;
+ use Moose;
+
+ has counter => (
+ traits => ['Counter'],
+ is => 'rw',
+ isa => 'Int',
+ handles => { inc => 'inc' },
+ default => 0,
+ );
+}
+
+{
+ package Controller;
+ use Moose;
+
+ has counter => (
+ is => 'ro',
+ isa => 'State',
+ required => 1,
+ handles => { inc => 'inc', counter_val => 'counter' },
+ );
+}
+
+{
+ package App;
+ use Moose;
+ use Bread::Board::Declare;
+
+ has counter => (
+ is => 'ro',
+ isa => 'State',
+ lifecycle => 'Singleton',
+ );
+
+ has controller => (
+ is => 'ro',
+ isa => 'Controller',
+ );
+}
+
+{
+ my $c = App->new;
+ is(
+ $c->fetch('controller')->get_dependency('counter')->service,
+ $c->fetch('counter'),
+ "inferred the right dependency"
+ );
+ $c->controller->inc;
+ $c->controller->inc;
+ is($c->controller->counter_val, 2, "state persisted as a singleton");
+}
+
done_testing;