5 use DBIx::Class::Schema::Loader::Optional::Dependencies;
6 use DBIx::Class::Schema::Loader::Utils qw/sigwarn_silencer/;
10 # Takes a $schema as input, runs 4 basic tests
12 my ($testname, $schema) = @_;
15 $schema = $schema->clone if !ref $schema;
16 isa_ok($schema, 'DBIx::Class::Schema', $testname);
18 my $rel_foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref');
19 isa_ok($rel_foo_rs, 'DBIx::Class::ResultSet', $testname);
21 my $rel_foo = $rel_foo_rs->next;
22 isa_ok($rel_foo, "DBICTest::Schema::_${testname}::Foo", $testname);
24 is($rel_foo->footext, 'Foo record associated with the Bar with barid 3', "$testname correct object");
26 my $foo_rs = $schema->resultset('Foo');
27 my $foo_new = $foo_rs->create({footext => "${testname}_foo"});
28 is ($foo_rs->search({footext => "${testname}_foo"})->count, 1, "$testname object created") || die;
29 } [], "No warnings during $testname invocations";
34 package DBICTest::Schema::_hardcode;
35 use base qw/ DBIx::Class::Schema::Loader /;
36 __PACKAGE__->naming('current');
37 __PACKAGE__->use_namespaces(0);
38 __PACKAGE__->connection($make_dbictest_db::dsn);
42 package DBICTest::Schema::_normal;
43 use base qw/ DBIx::Class::Schema::Loader /;
44 __PACKAGE__->loader_options();
45 __PACKAGE__->naming('current');
46 __PACKAGE__->use_namespaces(0);
47 __PACKAGE__->connect($make_dbictest_db::dsn);
49 'make_schema_at' => sub {
50 use DBIx::Class::Schema::Loader qw/ make_schema_at /;
52 'DBICTest::Schema::_make_schema_at',
54 really_erase_my_files => 1,
58 [ $make_dbictest_db::dsn ],
60 DBICTest::Schema::_make_schema_at->clone;
62 'embedded_options' => sub {
63 package DBICTest::Schema::_embedded_options;
64 use base qw/ DBIx::Class::Schema::Loader /;
65 __PACKAGE__->naming('current');
66 __PACKAGE__->use_namespaces(0);
68 $make_dbictest_db::dsn,
69 { loader_options => { really_erase_my_files => 1 } }
72 'embedded_options_in_attrs' => sub {
73 package DBICTest::Schema::_embedded_options_in_attrs;
74 use base qw/ DBIx::Class::Schema::Loader /;
75 __PACKAGE__->naming('current');
76 __PACKAGE__->use_namespaces(0);
78 $make_dbictest_db::dsn,
81 { AutoCommit => 1, loader_options => { really_erase_my_files => 1 } }
84 'embedded_options_make_schema_at' => sub {
85 use DBIx::Class::Schema::Loader qw/ make_schema_at /;
87 'DBICTest::Schema::_embedded_options_make_schema_at',
90 $make_dbictest_db::dsn,
92 really_erase_my_files => 1,
98 "DBICTest::Schema::_embedded_options_make_schema_at";
100 'almost_embedded' => sub {
101 package DBICTest::Schema::_almost_embedded;
102 use base qw/ DBIx::Class::Schema::Loader /;
103 __PACKAGE__->loader_options(
104 really_erase_my_files => 1,
108 __PACKAGE__->connect(
109 $make_dbictest_db::dsn,
110 undef, undef, { AutoCommit => 1 }
113 'make_schema_at_explicit' => sub {
114 use DBIx::Class::Schema::Loader;
115 DBIx::Class::Schema::Loader::make_schema_at(
116 'DBICTest::Schema::_make_schema_at_explicit',
118 really_erase_my_files => 1,
122 [ $make_dbictest_db::dsn ],
124 DBICTest::Schema::_make_schema_at_explicit->clone;
126 'no_skip_load_external' => sub {
127 # By default we should pull in t/lib/DBICTest/Schema/_no_skip_load_external/Foo.pm $skip_me since t/lib is in @INC
128 use DBIx::Class::Schema::Loader;
129 DBIx::Class::Schema::Loader::make_schema_at(
130 'DBICTest::Schema::_no_skip_load_external',
132 really_erase_my_files => 1,
136 [ $make_dbictest_db::dsn ],
138 DBICTest::Schema::_no_skip_load_external->clone;
140 'skip_load_external' => sub {
141 # When we explicitly skip_load_external t/lib/DBICTest/Schema/_skip_load_external/Foo.pm should be ignored
142 use DBIx::Class::Schema::Loader;
143 DBIx::Class::Schema::Loader::make_schema_at(
144 'DBICTest::Schema::_skip_load_external',
146 really_erase_my_files => 1,
149 skip_load_external => 1,
151 [ $make_dbictest_db::dsn ],
153 DBICTest::Schema::_skip_load_external->clone;
155 (DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for('use_moose') ?
156 ('use_moose' => sub {
157 package DBICTest::Schema::_use_moose;
158 use base qw/ DBIx::Class::Schema::Loader /;
159 __PACKAGE__->naming('current');
160 __PACKAGE__->use_namespaces(0);
161 __PACKAGE__->connect(
162 $make_dbictest_db::dsn,
163 { loader_options => { use_moose => 1 } }
170 # 6 tests per k/v pair
171 plan tests => 6 * (@invocations/2) + 2; # + 2 more manual ones below.
173 while(@invocations) {
174 my $style = shift @invocations;
175 my $cref = shift @invocations;
178 local $SIG{__WARN__} = sigwarn_silencer(
179 qr/Deleting existing file .+ due to 'really_erase_my_files' setting/
184 test_schema($style, $schema);
190 is($DBICTest::Schema::_no_skip_load_external::Foo::skip_me, "bad mojo",
191 "external content loaded");
192 is($DBICTest::Schema::_skip_load_external::Foo::skip_me, undef,
193 "external content not loaded with skip_load_external => 1");