I used David B's suggestion and it worked great.
Thanks,
johnk
On 9/14/05, Dave Howorth <[EMAIL PROTECTED]> wrote:
> David Baird wrote:
>
> > On 9/14/05, John Krystynak <[EMAIL PROTECTED]> wrote:
> >
> >>I have a maypole application that has a Config class, which specifies
> >>the dsn/user/pass like so:
> >>
> >>Config.pm:
> >>MyApp->config->{dsn} = "dbi:mysql:bla";
> >>MyApp->config->{user} = "user";
> >>MyApp->config->{pass} = "pass";
> >>
> >>The dbi connect call happens in MyApp::DBI.pm:
> >>
> >>package MyApp::DBI;
> >>use base qw(Class::DBI::mysql);
> >>MyApp::DBI->connection(MyApp->config->{dsn},
> >> MyApp->config->{user},
> >> MyApp->config->{pass});
> >>MyApp::DBI->autoupdate(1);
> >>
> >>I want to test MyApp against a dummy database - i.e. using a different
> >>dbi connection in my tests.
> >>
> >>Since my package that uses Maypole::Application then pulls in my
> >>Config class, and then calls setup.
> >>
> >>package MyApp;
> >>use URI;
> >>use Maypole::Application qw(-Debug Authentication::UserSessionCookie);
> >>use MyApp::Config;
> >>use MyApp::DBI;
> >>use MyApp::User;
> >>...
> >>
> >>MyApp->config->model("Maypole::Model::CDBI::Plain");
> >>MyApp->setup([qw/MyApp::User...
> >>
> >>I can't find out how I can set the dsn to be different in my test class.
> >>
> >>Is there any modular way from a test to reset the database connection
> >>to my test database/user? How could I structure it so the
> >>dsn/user/pass info was able to be changed?
> >
> > Use environment variables. Set $ENV{TESTING} = 1 in your test scripts,
> > then set dsn, user, pass etc in your config according to that.
>
> This is good, and simple.
>
> You can also do nasty things like declare a dummy config package inside
> your test script, so the test dsn is in the same file as the test script
> itself, if you want to avoid test artefacts in your production module.
>
> What I do is make my driver class accept the DSN as an import argument
> so in the calling script I can say things like:
> use BeerDB('dbi:mysql:testbeerdb');
> But I do an awful lot of messing around to make sure things happen at
> the right time (use vs require etc) and my driver is grossly
> non-standard, so you probably don't want to go that far.
>
> Cheers, Dave
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.344 / Virus Database: 267.10.24/101 - Release Date: 13/09/05
>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by:
> Tame your development challenges with Apache's Geronimo App Server. Download
> it for free - -and be entered to win a 42" plasma tv or your very own
> Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
> _______________________________________________
> Maypole-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/maypole-users
>
--
Check out my AdWords and Overture blog:
http://gotads.blogspot.com
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Maypole-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/maypole-users