1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7use Test::Fatal;
8
9use Bread::Board;
10
11{
12    package Foo;
13    use Moose;
14    has 'bar' => (is => 'ro', isa => 'Int', required => 1);
15
16    package Bar;
17    use Moose;
18    has 'foo' => (is => 'ro', isa => 'Int', required => 1);
19}
20
21my $c = container 'MyApp' => as {
22
23    service 'foo' => (
24        class      => 'Foo',
25        parameters => {
26            bar => { isa => 'Int' }
27        }
28    );
29
30    service 'bar' => (
31        class      => 'Bar',
32        parameters => {
33            foo => { isa => 'Int' }
34        }
35    );
36
37};
38
39my $foo;
40is(exception {
41    $foo = $c->resolve( service => 'foo', parameters => { bar => 10 } );
42}, undef, '... got the service correctly');
43isa_ok($foo, 'Foo');
44is($foo->bar, 10, '... got the right parameter value');
45
46my $bar;
47is(exception {
48    $bar = $c->resolve( service => 'bar', parameters => { foo => 20 } );
49}, undef, '... got the service correctly');
50isa_ok($bar, 'Bar');
51is($bar->foo, 20, '... got the right parameter value');
52
53done_testing;
54