silence the useless warning spew in 20invocations.t
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 20invocations.t
1 use strict;
2 use Test::More;
3 use lib qw(t/lib);
4 use make_dbictest_db;
5
6 $SIG{__WARN__} = sub { }; # Suppress warnings, as we test a lot of deprecated stuff here
7
8 # Takes a $schema as input, runs 4 basic tests
9 sub test_schema {
10     my ($testname, $schema) = @_;
11
12     $schema = $schema->clone if !ref $schema;
13     isa_ok($schema, 'DBIx::Class::Schema', $testname);
14
15     my $foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref');
16     isa_ok($foo_rs, 'DBIx::Class::ResultSet', $testname);
17
18     my $foo_first = $foo_rs->first;
19     like(ref $foo_first, qr/DBICTest::Schema::\d+::Foo/, $testname);
20
21     my $foo_first_text = $foo_first->footext;
22     is($foo_first_text, 'Foo record associated with the Bar with barid 3');
23 }
24
25 my @invocations = (
26     'deprecated_one' => sub {
27         package DBICTest::Schema::1;
28         use base qw/ DBIx::Class::Schema::Loader /;
29         __PACKAGE__->connection($make_dbictest_db::dsn);
30         __PACKAGE__->load_from_connection( relationships => 1 );
31         __PACKAGE__;
32     },
33     'deprecated_two' => sub {
34         package DBICTest::Schema::2;
35         use base qw/ DBIx::Class::Schema::Loader /;
36         __PACKAGE__->load_from_connection(
37             relationships => 1,
38             connect_info => [ $make_dbictest_db::dsn ],
39         );
40         __PACKAGE__;
41     },
42     'deprecated_three' => sub {
43         package DBICTest::Schema::3;
44         use base qw/ DBIx::Class::Schema::Loader /;
45         __PACKAGE__->load_from_connection(
46             relationships => 1,
47             dsn => $make_dbictest_db::dsn,
48         );
49         __PACKAGE__;
50     },
51     'deprecated_four' => sub {
52         package DBICTest::Schema::4;
53         use base qw/ DBIx::Class::Schema::Loader /;
54         __PACKAGE__->connection($make_dbictest_db::dsn);
55         __PACKAGE__->loader_options( relationships => 1 );
56         __PACKAGE__;
57     },
58     'hardcode' => sub {
59         package DBICTest::Schema::5;
60         use base qw/ DBIx::Class::Schema::Loader /;
61         __PACKAGE__->loader_options( relationships => 1 );
62         __PACKAGE__->connection($make_dbictest_db::dsn);
63         __PACKAGE__;
64     },
65     'normal' => sub {
66         package DBICTest::Schema::6;
67         use base qw/ DBIx::Class::Schema::Loader /;
68         __PACKAGE__->loader_options( relationships => 1 );
69         __PACKAGE__->connect($make_dbictest_db::dsn);
70     },
71     'make_schema_at' => sub {
72         use DBIx::Class::Schema::Loader qw/ make_schema_at /;
73         make_schema_at(
74             'DBICTest::Schema::7',
75             { relationships => 1 },
76             [ $make_dbictest_db::dsn ],
77         );
78         DBICTest::Schema::7->clone;
79     },
80     'embedded_options' => sub {
81         package DBICTest::Schema::8;
82         use base qw/ DBIx::Class::Schema::Loader /;
83         __PACKAGE__->connect(
84             $make_dbictest_db::dsn,
85             { loader_options => { relationships => 1 } }
86         );
87     },
88     'embedded_options_in_attrs' => sub {
89         package DBICTest::Schema::9;
90         use base qw/ DBIx::Class::Schema::Loader /;
91         __PACKAGE__->connect(
92             $make_dbictest_db::dsn,
93             undef,
94             undef,
95             { AutoCommit => 1, loader_options => { relationships => 1 } }
96         );
97     },
98     'embedded_options_make_schema_at' => sub {
99         use DBIx::Class::Schema::Loader qw/ make_schema_at /;
100         make_schema_at(
101             'DBICTest::Schema::10',
102             { },
103             [
104                 $make_dbictest_db::dsn,
105                 { loader_options => { relationships => 1 } },
106             ],
107         );
108         "DBICTest::Schema::10";
109     },
110     'almost_embedded' => sub {
111         package DBICTest::Schema::11;
112         use base qw/ DBIx::Class::Schema::Loader /;
113         __PACKAGE__->loader_options( relationships => 1 );
114         __PACKAGE__->connect(
115             $make_dbictest_db::dsn,
116             undef, undef, { AutoCommit => 1 }
117         );
118     },
119     'make_schema_at_explicit' => sub {
120         use DBIx::Class::Schema::Loader;
121         DBIx::Class::Schema::Loader::make_schema_at(
122             'DBICTest::Schema::12',
123             { relationships => 1 },
124             [ $make_dbictest_db::dsn ],
125         );
126         DBICTest::Schema::12->clone;
127     }
128 );
129
130 # 4 tests per k/v pair
131 plan tests => 2 * @invocations;
132
133 while(@invocations >= 2) {
134     my $style = shift @invocations;
135     my $subref = shift @invocations;
136     test_schema($style, &$subref);
137 }