summaryrefslogtreecommitdiffstats
path: root/t/parameters.t
blob: 2c37629e5549f141f3feca7321b53905dee13089 (plain) (blame)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Fatal;

{
    package Schema;
    use Moose;
}

{
    package Thing;
    use Moose;

    has schema => (
        is       => 'ro',
        isa      => 'Schema',
        required => 1,
    );

    has foo => (
        is       => 'ro',
        required => 1,
    );

    has bar => (
        is       => 'ro',
        required => 1,
    );
}

{
    package Model;
    use Moose;
    use Bread::Board::Declare;

    has schema => (
        is  => 'ro',
        isa => 'Schema',
    );

    has thing => (
        is           => 'ro',
        isa          => 'Thing',
        dependencies => ['schema'],
        parameters   => ['foo', 'bar'],
    );
}

my $m = Model->new;
like(
    exception { $m->thing },
    qr/Mandatory parameters .* missing/,
    "error with unsatisfied parameters"
);
is(
    exception {
        my $thing = $m->resolve(
            service => 'thing',
            parameters => { foo => 'a', bar => 'b' },
        );
        is($thing->foo, 'a');
        is($thing->bar, 'b');
        isa_ok($thing->schema, 'Schema');
    },
    undef,
    "no error with satisfied parameters"
);

done_testing;