1 # test for loading additional methods from file-defined packages
2 # by Mark Hedges ( hedges -at| scriptdolphin.com )
6 use Test::More tests => 7 * 5;
13 use DBIx::Class::Schema::Loader;
15 $ENV{SCHEMA_LOADER_BACKCOMPAT} = 1;
17 # In the first test run, then, Foo should be a DBICTestMethods::Namespaces::Schema::Result::Foo
20 testname => "naming => 'current'",
21 schema_class => 'DBICTestMethods::Namespaces::Schema',
22 foo_class => 'DBICTestMethods::Namespaces::Schema::Result::Foo',
28 # In the second test run with use_namespaces => 0 (backcompat), Foo should be a DBICTestMethods::Backcompat::Schema
31 testname => "naming => 'current', use_namespaces => 0",
32 schema_class => 'DBICTestMethods::Backcompat::Schema',
33 foo_class => 'DBICTestMethods::Backcompat::Schema::Foo',
40 # In the third test, with use_namespaces => 1, Foo gets the explicit Result class again
43 testname => "naming => 'current', use_namespaces => 1",
44 schema_class => 'DBICTestMethods::Namespaces::Schema',
45 foo_class => 'DBICTestMethods::Namespaces::Schema::Result::Foo',
52 # try it in full backcompat 0.04006 mode with no schema options
55 testname => "no naming or namespaces options (0.04006 mode)",
56 schema_class => 'DBICTestMethods::Backcompat::Schema',
57 foo_class => 'DBICTestMethods::Backcompat::Schema::Foo',
62 # try it in backcompat mode (no naming option) but with use_namespaces => 1
65 testname => "no naming, but with use_namespaces options (0.04006 mode)",
66 schema_class => 'DBICTestMethods::Namespaces::Schema',
67 foo_class => 'DBICTestMethods::Namespaces::Schema::Result::Foo',
73 sub run_test_sequence {
75 die "specify a $_ test param" for grep !$p{$_},
76 qw( testname schema_opts schema_class foo_class );
79 lives_ok { $schema = make_schema_with(%p) } "($p{testname}) get schema";
82 skip 'no point in checking if schema could not be connected', 6 unless defined $schema;
84 # well, if that worked, try to get a ResultSet
87 $foo_rs = $schema->resultset('Foo')->search();
88 } "($p{testname}) get a ResultSet for Foo";
93 $foo = $foo_rs->first();
94 } "($p{testname}) get the first foo";
96 ok(defined $foo, "($p{testname}) \$foo is defined");
99 skip 'foo is not defined', 3 unless defined $foo;
101 isa_ok $foo, $p{foo_class};
103 # call the file-defined method
107 } "($p{testname}) call the file-defined Foo->biz method";
110 skip 'no point in checking value if method was not found', 1 unless defined $biz;
113 $biz eq 'foo bar biz baz boz noz schnozz',
114 "($p{testname}) biz() method returns correct string"
121 sub make_schema_with {
123 return DBIx::Class::Schema::Loader::make_schema_at(
126 [ $make_dbictest_db::dsn ],