File: 011_container_path.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 (84 lines) | stat: -rw-r--r-- 2,474 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;
use Test::Moose;

use Bread::Board::Container;
use Bread::Board::ConstructorInjection;
use Bread::Board::Literal;

my $c = Bread::Board::Container->new(
    name           => 'Application',
    sub_containers => [
        Bread::Board::Container->new(
            name     => 'Model',
            services => [
                Bread::Board::Literal->new(name => 'dsn',  value => ''),
                Bread::Board::ConstructorInjection->new(
                    name  => 'schema',
                    class => 'My::App::Schema',
                    dependencies => {
                        dsn  => Bread::Board::Dependency->new(service_path => 'dsn'),
                        user => Bread::Board::Literal->new(name => 'user', value => ''),
                        pass => Bread::Board::Literal->new(name => 'pass', value => ''),
                    },
                )
            ]
        ),
        Bread::Board::Container->new(
            name     => 'View',
            services => [
                Bread::Board::ConstructorInjection->new(
                    name  => 'TT',
                    class => 'My::App::View::TT',
                    dependencies => {
                        tt_include_path => Bread::Board::Literal->new(name => 'include_path',  value => []),
                    },
                )
            ]
         ),
         Bread::Board::Container->new(name => 'Controller'),
    ]
);

#use Bread::Board::Dumper;
#diag(Bread::Board::Dumper->new->dump($c));

my $model = $c->fetch('Model');
isa_ok($model, 'Bread::Board::Container');

is($model->name, 'Model', '... got the right model');

{
    my $model2 = $c->fetch('/Model');
    isa_ok($model2, 'Bread::Board::Container');

    is($model, $model2, '... they are the same thing');
}

my $dsn = $model->fetch('schema/dsn');
isa_ok($dsn, 'Bread::Board::Dependency');

is($dsn->service_path, 'dsn', '... got the right name');

{
    my $dsn2 = $c->fetch('/Model/schema/dsn');
    isa_ok($dsn2, 'Bread::Board::Dependency');

    is($dsn, $dsn2, '... they are the same thing');
}

my $root = $model->fetch('../');
isa_ok($root, 'Bread::Board::Container');

is($root, $c, '... got the same container');

is($model, $model->fetch('../Model'), '... navigated back to myself');
is($dsn, $model->fetch('../Model/schema/dsn'), '... navigated to dsn');

is($model, $dsn->fetch('../Model'), '... got the model from the dsn');

done_testing;