File: 041_parameter_cache_handling.t

package info (click to toggle)
libbread-board-perl 0.29-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 620 kB
  • sloc: perl: 5,280; makefile: 13
file content (53 lines) | stat: -rw-r--r-- 1,038 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;
use Test::Fatal;

use Bread::Board;

{
    package Foo;
    use Moose;
    has 'bar' => (is => 'ro', isa => 'Int', required => 1);

    package Bar;
    use Moose;
    has 'foo' => (is => 'ro', isa => 'Int', required => 1);
}

my $c = container 'MyApp' => as {

    service 'foo' => (
        class      => 'Foo',
        parameters => {
            bar => { isa => 'Int' }
        }
    );

    service 'bar' => (
        class      => 'Bar',
        parameters => {
            foo => { isa => 'Int' }
        }
    );

};

my $foo;
is(exception {
    $foo = $c->resolve( service => 'foo', parameters => { bar => 10 } );
}, undef, '... got the service correctly');
isa_ok($foo, 'Foo');
is($foo->bar, 10, '... got the right parameter value');

my $bar;
is(exception {
    $bar = $c->resolve( service => 'bar', parameters => { foo => 20 } );
}, undef, '... got the service correctly');
isa_ok($bar, 'Bar');
is($bar->foo, 20, '... got the right parameter value');

done_testing;