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