Is there any way to use the test database on the catalyst

When using a catalyst, is there a way to specify a database of developers, tests, and production, as in Rails? I looked through the documentation, but I did not find the answer.

+5
source share
1 answer

Referring to cpan Catalyst Testing Tutorial

You might want to save both the “production database” for your live application and the “test database” for your test cases.

SWITCHING THE DATABASE CONFIGURATION IN YOUR MODEL CLASS

, . , lib/MyApp/Model/MyAppDB.pm __PACKAGE__->config(... :

my $dsn = $ENV{MYAPP_DSN} ||= 'dbi:SQLite:myapp.db';
__PACKAGE__->config(
    schema_class => 'MyAppDB',
    connect_info => [
        $dsn,
        '',
        '',
        { AutoCommit => 1 },

    ],
);

, , , :

$cp myapp.db myappTEST.db
 $ CATALYST_DEBUG = 0 MYAPP_DSN = "dbi: SQLite: myappTEST.db" --lib lib -v t/live_app01.t

DSN . MYAPP_DSN , dbi: SQLite: myapp.db as .

Catalyst:: Plugin:: ConfigLoader , ().

$ENV {MYAPP_CONFIG_LOCAL_SUFFIX} '' script myapp_testing.conf myapp.conf, myapp.conf.

BEGIN test script, , , Catalyst .

script DBIx:: MyDB Foo:

myapp_testing.conf:

<Model::MyDB>
    <connect_info>
        dsn dbi:SQLite:myapp.db
    </connect_info>
</Model::MyDB>

this

+4

All Articles