4 use DBIx::Class::Schema::Loader::Optional::Dependencies;
5 use DBIx::Class::Schema::Loader::Utils qw/sigwarn_silencer/;
9 # Takes a $schema as input, runs 4 basic tests
11 my ($testname, $schema) = @_;
14 $schema = $schema->clone if !ref $schema;
15 isa_ok($schema, 'DBIx::Class::Schema', $testname);
17 my $rel_foo_rs = $schema->resultset('Bar')->search({ barid => 3})->search_related('fooref');
18 isa_ok($rel_foo_rs, 'DBIx::Class::ResultSet', $testname);
20 my $rel_foo = $rel_foo_rs->next;
21 isa_ok($rel_foo, "DBICTest::Schema::_${testname}::Foo", $testname);
23 is($rel_foo->footext, 'Foo record associated with the Bar with barid 3', "$testname correct object");
25 my $foo_rs = $schema->resultset('Foo');
26 my $foo_new = $foo_rs->create({footext => "${testname}_foo"});
27 is ($foo_rs->search({footext => "${testname}_foo"})->count, 1, "$testname object created") || die;
28 }, [], "No warnings during $testname invocations");
33 package DBICTest::Schema::_hardcode;
34 use base qw/ DBIx::Class::Schema::Loader /;
35 __PACKAGE__->naming('current');
36 __PACKAGE__->use_namespaces(0);
37 __PACKAGE__->connection($make_dbictest_db::dsn);
41 package DBICTest::Schema::_normal;
42 use base qw/ DBIx::Class::Schema::Loader /;
43 __PACKAGE__->loader_options();
44 __PACKAGE__->naming('current');
45 __PACKAGE__->use_namespaces(0);
46 __PACKAGE__->connect($make_dbictest_db::dsn);
48 'make_schema_at' => sub {
49 use DBIx::Class::Schema::Loader qw/ make_schema_at /;
51 'DBICTest::Schema::_make_schema_at',
53 really_erase_my_files => 1,
57 [ $make_dbictest_db::dsn ],
59 DBICTest::Schema::_make_schema_at->clone;
61 'embedded_options' => sub {
62 package DBICTest::Schema::_embedded_options;
63 use base qw/ DBIx::Class::Schema::Loader /;
64 __PACKAGE__->naming('current');
65 __PACKAGE__->use_namespaces(0);
67 $make_dbictest_db::dsn,
68 { loader_options => { really_erase_my_files => 1 } }
71 'embedded_options_in_attrs' => sub {
72 package DBICTest::Schema::_embedded_options_in_attrs;
73 use base qw/ DBIx::Class::Schema::Loader /;
74 __PACKAGE__->naming('current');
75 __PACKAGE__->use_namespaces(0);
77 $make_dbictest_db::dsn,
80 { AutoCommit => 1, loader_options => { really_erase_my_files => 1 } }
83 'embedded_options_make_schema_at' => sub {
84 use DBIx::Class::Schema::Loader qw/ make_schema_at /;
86 'DBICTest::Schema::_embedded_options_make_schema_at',
89 $make_dbictest_db::dsn,
91 really_erase_my_files => 1,
97 "DBICTest::Schema::_embedded_options_make_schema_at";
99 'almost_embedded' => sub {
100 package DBICTest::Schema::_almost_embedded;
101 use base qw/ DBIx::Class::Schema::Loader /;
102 __PACKAGE__->loader_options(
103 really_erase_my_files => 1,
107 __PACKAGE__->connect(
108 $make_dbictest_db::dsn,
109 undef, undef, { AutoCommit => 1 }
112 'make_schema_at_explicit' => sub {
113 use DBIx::Class::Schema::Loader;
114 DBIx::Class::Schema::Loader::make_schema_at(
115 'DBICTest::Schema::_make_schema_at_explicit',
117 really_erase_my_files => 1,
121 [ $make_dbictest_db::dsn ],
123 DBICTest::Schema::_make_schema_at_explicit->clone;
125 'no_skip_load_external' => sub {
126 # By default we should pull in t/lib/DBICTest/Schema/_no_skip_load_external/Foo.pm $skip_me since t/lib is in @INC
127 use DBIx::Class::Schema::Loader;
128 DBIx::Class::Schema::Loader::make_schema_at(
129 'DBICTest::Schema::_no_skip_load_external',
131 really_erase_my_files => 1,
135 [ $make_dbictest_db::dsn ],
137 DBICTest::Schema::_no_skip_load_external->clone;
139 'skip_load_external' => sub {
140 # When we explicitly skip_load_external t/lib/DBICTest/Schema/_skip_load_external/Foo.pm should be ignored
141 use DBIx::Class::Schema::Loader;
142 DBIx::Class::Schema::Loader::make_schema_at(
143 'DBICTest::Schema::_skip_load_external',
145 really_erase_my_files => 1,
148 skip_load_external => 1,
150 [ $make_dbictest_db::dsn ],
152 DBICTest::Schema::_skip_load_external->clone;
154 (DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for('use_moose') ?
155 ('use_moose' => sub {
156 package DBICTest::Schema::_use_moose;
157 use base qw/ DBIx::Class::Schema::Loader /;
158 __PACKAGE__->naming('current');
159 __PACKAGE__->use_namespaces(0);
160 __PACKAGE__->connect(
161 $make_dbictest_db::dsn,
162 { loader_options => { use_moose => 1 } }
169 # 6 tests per k/v pair
170 plan tests => 6 * (@invocations/2) + 2; # + 2 more manual ones below.
172 while(@invocations) {
173 my $style = shift @invocations;
174 my $cref = shift @invocations;
177 local $SIG{__WARN__} = sigwarn_silencer(
178 qr/Deleting existing file .+ due to 'really_erase_my_files' setting/
183 test_schema($style, $schema);
189 is($DBICTest::Schema::_no_skip_load_external::Foo::skip_me, "bad mojo",
190 "external content loaded");
191 is($DBICTest::Schema::_skip_load_external::Foo::skip_me, undef,
192 "external content not loaded with skip_load_external => 1");