File: 20invocations.t

package info (click to toggle)
libdbix-class-schema-loader-perl 0.03009-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 252 kB
  • ctags: 102
  • sloc: perl: 1,636; makefile: 44
file content (137 lines) | stat: -rw-r--r-- 4,395 bytes parent folder | download
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
use strict;
use Test::More;
use lib qw(t/lib);
use make_dbictest_db;

$SIG{__WARN__} = sub { }; # Suppress warnings, as we test a lot of deprecated stuff here

# Takes a $schema as input, runs 4 basic tests
sub test_schema {
    my ($testname, $schema) = @_;

    $schema = $schema->clone if !ref $schema;
    isa_ok($schema, 'DBIx::Class::Schema', $testname);

    my $foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref');
    isa_ok($foo_rs, 'DBIx::Class::ResultSet', $testname);

    my $foo_first = $foo_rs->first;
    like(ref $foo_first, qr/DBICTest::Schema::\d+::Foo/, $testname);

    my $foo_first_text = $foo_first->footext;
    is($foo_first_text, 'Foo record associated with the Bar with barid 3');
}

my @invocations = (
    'deprecated_one' => sub {
        package DBICTest::Schema::1;
        use base qw/ DBIx::Class::Schema::Loader /;
        __PACKAGE__->connection($make_dbictest_db::dsn);
        __PACKAGE__->load_from_connection( relationships => 1 );
        __PACKAGE__;
    },
    'deprecated_two' => sub {
        package DBICTest::Schema::2;
        use base qw/ DBIx::Class::Schema::Loader /;
        __PACKAGE__->load_from_connection(
            relationships => 1,
            connect_info => [ $make_dbictest_db::dsn ],
        );
        __PACKAGE__;
    },
    'deprecated_three' => sub {
        package DBICTest::Schema::3;
        use base qw/ DBIx::Class::Schema::Loader /;
        __PACKAGE__->load_from_connection(
            relationships => 1,
            dsn => $make_dbictest_db::dsn,
        );
        __PACKAGE__;
    },
    'deprecated_four' => sub {
        package DBICTest::Schema::4;
        use base qw/ DBIx::Class::Schema::Loader /;
        __PACKAGE__->connection($make_dbictest_db::dsn);
        __PACKAGE__->loader_options( relationships => 1 );
        __PACKAGE__;
    },
    'hardcode' => sub {
        package DBICTest::Schema::5;
        use base qw/ DBIx::Class::Schema::Loader /;
        __PACKAGE__->loader_options( relationships => 1 );
        __PACKAGE__->connection($make_dbictest_db::dsn);
        __PACKAGE__;
    },
    'normal' => sub {
        package DBICTest::Schema::6;
        use base qw/ DBIx::Class::Schema::Loader /;
        __PACKAGE__->loader_options( relationships => 1 );
        __PACKAGE__->connect($make_dbictest_db::dsn);
    },
    'make_schema_at' => sub {
        use DBIx::Class::Schema::Loader qw/ make_schema_at /;
        make_schema_at(
            'DBICTest::Schema::7',
            { relationships => 1 },
            [ $make_dbictest_db::dsn ],
        );
        DBICTest::Schema::7->clone;
    },
    'embedded_options' => sub {
        package DBICTest::Schema::8;
        use base qw/ DBIx::Class::Schema::Loader /;
        __PACKAGE__->connect(
            $make_dbictest_db::dsn,
            { loader_options => { relationships => 1 } }
        );
    },
    'embedded_options_in_attrs' => sub {
        package DBICTest::Schema::9;
        use base qw/ DBIx::Class::Schema::Loader /;
        __PACKAGE__->connect(
            $make_dbictest_db::dsn,
            undef,
            undef,
            { AutoCommit => 1, loader_options => { relationships => 1 } }
        );
    },
    'embedded_options_make_schema_at' => sub {
        use DBIx::Class::Schema::Loader qw/ make_schema_at /;
        make_schema_at(
            'DBICTest::Schema::10',
            { },
            [
                $make_dbictest_db::dsn,
                { loader_options => { relationships => 1 } },
            ],
        );
        "DBICTest::Schema::10";
    },
    'almost_embedded' => sub {
        package DBICTest::Schema::11;
        use base qw/ DBIx::Class::Schema::Loader /;
        __PACKAGE__->loader_options( relationships => 1 );
        __PACKAGE__->connect(
            $make_dbictest_db::dsn,
            undef, undef, { AutoCommit => 1 }
        );
    },
    'make_schema_at_explicit' => sub {
        use DBIx::Class::Schema::Loader;
        DBIx::Class::Schema::Loader::make_schema_at(
            'DBICTest::Schema::12',
            { relationships => 1 },
            [ $make_dbictest_db::dsn ],
        );
        DBICTest::Schema::12->clone;
    }
);

# 4 tests per k/v pair
plan tests => 2 * @invocations;

while(@invocations >= 2) {
    my $style = shift @invocations;
    my $subref = shift @invocations;
    test_schema($style, &$subref);
}