1 # test for loading additional methods from file-defined packages
2 # by Mark Hedges ( hedges -at| scriptdolphin.com )
5 use Test::More tests => 7 * 5;
12 use DBIx::Class::Schema::Loader;
14 $ENV{SCHEMA_LOADER_BACKCOMPAT} = 1;
16 # In the first test run, then, Foo should be a DBICTestMethods::Namespaces::Schema::Result::Foo
19 testname => "naming => 'current'",
20 schema_class => 'DBICTestMethods::Namespaces::Schema',
21 foo_class => 'DBICTestMethods::Namespaces::Schema::Result::Foo',
27 # In the second test run with use_namespaces => 0 (backcompat), Foo should be a DBICTestMethods::Backcompat::Schema
30 testname => "naming => 'current', use_namespaces => 0",
31 schema_class => 'DBICTestMethods::Backcompat::Schema',
32 foo_class => 'DBICTestMethods::Backcompat::Schema::Foo',
39 # In the third test, with use_namespaces => 1, Foo gets the explicit Result class again
42 testname => "naming => 'current', use_namespaces => 1",
43 schema_class => 'DBICTestMethods::Namespaces::Schema',
44 foo_class => 'DBICTestMethods::Namespaces::Schema::Result::Foo',
51 # try it in full backcompat 0.04006 mode with no schema options
54 testname => "no naming or namespaces options (0.04006 mode)",
55 schema_class => 'DBICTestMethods::Backcompat::Schema',
56 foo_class => 'DBICTestMethods::Backcompat::Schema::Foo',
61 # try it in backcompat mode (no naming option) but with use_namespaces => 1
64 testname => "no naming, but with use_namespaces options (0.04006 mode)",
65 schema_class => 'DBICTestMethods::Namespaces::Schema',
66 foo_class => 'DBICTestMethods::Namespaces::Schema::Result::Foo',
72 sub run_test_sequence {
74 die "specify a $_ test param" for grep !$p{$_},
75 qw( testname schema_opts schema_class foo_class );
78 lives_ok { $schema = make_schema_with(%p) } "($p{testname}) get schema";
81 skip 'no point in checking if schema could not be connected', 6 unless defined $schema;
83 # well, if that worked, try to get a ResultSet
86 $foo_rs = $schema->resultset('Foo')->search();
87 } "($p{testname}) get a ResultSet for Foo";
92 $foo = $foo_rs->first();
93 } "($p{testname}) get the first foo";
95 ok(defined $foo, "($p{testname}) \$foo is defined");
98 skip 'foo is not defined', 3 unless defined $foo;
100 isa_ok $foo, $p{foo_class};
102 # call the file-defined method
106 } "($p{testname}) call the file-defined Foo->biz method";
109 skip 'no point in checking value if method was not found', 1 unless defined $biz;
112 $biz eq 'foo bar biz baz boz noz schnozz',
113 "($p{testname}) biz() method returns correct string"
120 sub make_schema_with {
122 return DBIx::Class::Schema::Loader::make_schema_at(
125 [ $make_dbictest_db::dsn ],