• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
 

YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing

on

  • 1,743 views

It's often useful to check that your DBIx::Class classes provide the methods you expect, and no-one has sneakily stolen or broken methods when you weren't looking. ...

It's often useful to check that your DBIx::Class classes provide the methods you expect, and no-one has sneakily stolen or broken methods when you weren't looking.

Being lazy I wanted to do this with as little fuss and typing as possible.

Thanks to Test::DBIx::Class::Schema I can do all of the above and would like to share thoughts and musings for the future of the module.

Statistics

Views

Total Views
1,743
Views on SlideShare
1,743
Embed Views
0

Actions

Likes
0
Downloads
5
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing Presentation Transcript

    • Introduction Test::DBIx::Class::Schema Future Finally Mostly Lazy DBIx::Class Testing Chisel Wright Net-A-Porter 2011Mostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyIn A Nutshell DBIx::Class schema sanity checking testsMostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyWhy? Ongoing Quest To Be As LAZY As PossibleMostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyNon-Lazy # are specific columns defined? my $thingy = $model->resultset(’BigBagOfFail’); my @columns = qw/id name department/); can_ok($thingy, @columns);Mostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyNon-Lazy foreach my $column (@columns) { try { $thingy->$column(); ok("called $column()"); } catch($e) { diag $e; fail("$column() failed"); } }Mostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyNon-Lazy What about . . . ? relationships custom methodsMostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyNon-Lazy Decide to test something new? How many .t files do you need to edit? More than zero? Too much work!!Mostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyGetting Lazy Test::DBIx::Class::SchemaMostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyTest::DBIx::Class::Schema My Attempt At LazinessMostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyAn example (setup) my $schematest = Test::DBIx::Class::Schema->new({ # required dsn => ’dbi:Pg:dbname=mydb’, namespace => ’MyDB::Schema’, moniker => ’SomeTable’, # optional username => ’some_user’, password => ’opensesame’, });Mostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyAn example (config) # tell it what to test $schematest->methods({ columns => [ qw( id name ) ], relations => [ qw( foo ) ], custom => [ qw( some_method ) ], resultsets => [ qw( ) ], });Mostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyAn example (running) $schematest->run_tests();Mostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyYou get. . . can ok( @columns ) can ok( @relations ) can ok( @customs ) # row subs can ok( @resultsets ) # rs subsMostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyYou also get. . . $thing->$column called ok $thing->$relation called ok test that $column exists in the database ensure related-source exists test self.* and foreign.* columns for relationships test proxied relationships PASS/FAIL for relationship validityMostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyYou don’t get Functional TestingMostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyBenefits only maintaining a list (or three) lots of sanity checking find out if someone deletes columns from the database upgrading ’TDCS’ improves *.t files for freeMostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyRecommendations Test one table/class per file Use Test::Aggregate Factor out ->new call for $schemaMostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyIn The Real World on the CPAN since 2008 used in production code since 2009 recent burst of improvements never used to test empty tables - OOPS! used to be quite basicMostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyDid It Work? YES! IMNSHOMostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyWhat Next? Wishlist relationship reciprocity relationships that are coderefs db columns that aren’t in the schema? tie-in with DBIx::Class::Schema::LoaderMostly Lazy DBIx::Class Testing Net-A-Porter
    • Introduction Test::DBIx::Class::Schema Future FinallyEnd Credits QUESTIONS? Me: chisel.wright@net-a-porter.com CPANID: CHISEL github: github.com/chiselwright Module: metacpan.org/release/Test-DBIx-Class-Schema github.com/chiselwright/test-dbix-class-schemaMostly Lazy DBIx::Class Testing Net-A-Porter