DBICx::...Database(3)
π DBICx::TestDatabase(3) β like, the whole vibe
okay so real talk: you're reading the DBICx::TestDatabase(3) page, and it lives in the User Contributed Perl Documentation section of your man pages. grab a snack, we're gonna make test databases together π«Ά
β¨ NAME β¨
DBICx::TestDatabase β literally makes a temporary database out of a DBIx::Class::Schema, no cap π
πΈ SYNOPSIS πΈ
say you've got a DBIx::Class::Schema hanging out at MyApp::Schema β here's how you spin up a test database for it:
use DBICx::TestDatabase;
my $schema = DBICx::TestDatabase->new('MyApp::Schema');
and then bestie, $schema is just... a normal schema. use it however:
$schema->resultset('Blah')->create({ blah => '123' });
and the moment your program exits, the temporary database dips out. gone. iconic behaviour honestly β¨
π¦ DESCRIPTION π¦
so what's actually happening under the hood? this module creates a temporary SQLite database, deploys your DBIC schema onto it, and then connects to it. that's the whole trick π
the point is that testing your DBIC schema becomes, like, effortless. every single test gets a fresh database, which means:
- you don't have to worry about cleanup after your tests π
- you don't have to worry about test ordering messing with your failures
- you don't have to worry about, y'know, anything
it's giving main character energy for your test suite, fr fr π
π METHODS π
new($schema)
loads $schema and hands you back a connection to it. that's it, that's the method π«Ά
connect
an alias for new. same thing, different name, both slay π
π ENVIRONMENT π
you can control how this module behaves at runtime by setting environment variables β yes, at runtime, we love a flexible queen β¨
DBIC_KEEP_TEST
if this variable is true, then the test database will not be deleted at END time. instead, you get a message printed out containing the paths of the test databases. π
this is the move when you actually want to look at the database your test generated, for debugging purposes. very "let me see what you did there" of you π
ngl this one's important: the database will never exist on disk if you don't set this to a true value. so if you're out here wondering where your sqlite file went... that's why, bestie π
π AUTHOR π
Jonathan Rockway <jrockway@cpan.org> β thank you for your service, king π
β LICENSE β
Copyright (c) 2007 Jonathan Rockway.
This program is free software. You may use, modify, and redistribute it under the same terms as Perl itself. πͺ
and that's the whole page!! this one's perl v5.42.0, dated 2017-10-12, and it's been serving looks in the DBICx::...Database(3) section ever since π bye bestie, go write some tests π§
π¦ where this page comes from
- opensuse-leap 16.0: perl-DBICx-TestDatabase 0.05-bp160.1.10 Β· Artistic-1.0 or GPL-1.0+
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms