Introduction                      Test::DBIx::Class::Schema       Future        Finally                           Mostly L...
Introduction                      Test::DBIx::Class::Schema   Future        FinallyIn A Nutshell                          ...
Introduction                      Test::DBIx::Class::Schema   Future        FinallyWhy?                          Ongoing Q...
Introduction                      Test::DBIx::Class::Schema   Future        FinallyNon-Lazy       # are specific columns d...
Introduction                      Test::DBIx::Class::Schema   Future        FinallyNon-Lazy       foreach my $column (@col...
Introduction                      Test::DBIx::Class::Schema   Future        FinallyNon-Lazy       What about . . . ?      ...
Introduction                      Test::DBIx::Class::Schema   Future        FinallyNon-Lazy               Decide to test s...
Introduction                      Test::DBIx::Class::Schema      Future        FinallyGetting Lazy                        ...
Introduction                      Test::DBIx::Class::Schema     Future        FinallyTest::DBIx::Class::Schema            ...
Introduction                      Test::DBIx::Class::Schema   Future         FinallyAn example (setup)       my $schemates...
Introduction                       Test::DBIx::Class::Schema   Future        FinallyAn example (config)       # tell it wha...
Introduction                      Test::DBIx::Class::Schema   Future        FinallyAn example (running)       $schematest-...
Introduction                      Test::DBIx::Class::Schema   Future        FinallyYou get. . .               can ok( @col...
Introduction                      Test::DBIx::Class::Schema   Future        FinallyYou also get. . .               $thing-...
Introduction                      Test::DBIx::Class::Schema   Future        FinallyYou don’t get                          ...
Introduction                      Test::DBIx::Class::Schema   Future        FinallyBenefits               only maintaining ...
Introduction                      Test::DBIx::Class::Schema   Future        FinallyRecommendations               Test one ...
Introduction                      Test::DBIx::Class::Schema     Future        FinallyIn The Real World               on th...
Introduction                      Test::DBIx::Class::Schema   Future        FinallyDid It Work?                           ...
Introduction                      Test::DBIx::Class::Schema   Future        FinallyWhat Next?       Wishlist              ...
Introduction                       Test::DBIx::Class::Schema   Future        FinallyEnd Credits                           ...
Upcoming SlideShare
Loading in...5
×

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

1,739
-1

Published on

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.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,739
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

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

  1. 1. 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
  2. 2. Introduction Test::DBIx::Class::Schema Future FinallyIn A Nutshell DBIx::Class schema sanity checking testsMostly Lazy DBIx::Class Testing Net-A-Porter
  3. 3. Introduction Test::DBIx::Class::Schema Future FinallyWhy? Ongoing Quest To Be As LAZY As PossibleMostly Lazy DBIx::Class Testing Net-A-Porter
  4. 4. 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
  5. 5. 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
  6. 6. Introduction Test::DBIx::Class::Schema Future FinallyNon-Lazy What about . . . ? relationships custom methodsMostly Lazy DBIx::Class Testing Net-A-Porter
  7. 7. 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
  8. 8. Introduction Test::DBIx::Class::Schema Future FinallyGetting Lazy Test::DBIx::Class::SchemaMostly Lazy DBIx::Class Testing Net-A-Porter
  9. 9. Introduction Test::DBIx::Class::Schema Future FinallyTest::DBIx::Class::Schema My Attempt At LazinessMostly Lazy DBIx::Class Testing Net-A-Porter
  10. 10. 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
  11. 11. 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
  12. 12. Introduction Test::DBIx::Class::Schema Future FinallyAn example (running) $schematest->run_tests();Mostly Lazy DBIx::Class Testing Net-A-Porter
  13. 13. 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
  14. 14. 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
  15. 15. Introduction Test::DBIx::Class::Schema Future FinallyYou don’t get Functional TestingMostly Lazy DBIx::Class Testing Net-A-Porter
  16. 16. 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
  17. 17. 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
  18. 18. 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
  19. 19. Introduction Test::DBIx::Class::Schema Future FinallyDid It Work? YES! IMNSHOMostly Lazy DBIx::Class Testing Net-A-Porter
  20. 20. 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
  21. 21. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×