Your SlideShare is downloading. ×
0
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
YAPC::EU::2011 - Mostly Lazy DBIx::Class Testing
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

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

1,595

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. …

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,595
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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. Introduction Test::DBIx::Class::Schema Future FinallyIn A Nutshell DBIx::Class schema sanity checking testsMostly Lazy DBIx::Class Testing Net-A-Porter
  • 3. Introduction Test::DBIx::Class::Schema Future FinallyWhy? Ongoing Quest To Be As LAZY As PossibleMostly Lazy DBIx::Class Testing Net-A-Porter
  • 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. 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. Introduction Test::DBIx::Class::Schema Future FinallyNon-Lazy What about . . . ? relationships custom methodsMostly Lazy DBIx::Class Testing Net-A-Porter
  • 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. Introduction Test::DBIx::Class::Schema Future FinallyGetting Lazy Test::DBIx::Class::SchemaMostly Lazy DBIx::Class Testing Net-A-Porter
  • 9. Introduction Test::DBIx::Class::Schema Future FinallyTest::DBIx::Class::Schema My Attempt At LazinessMostly Lazy DBIx::Class Testing Net-A-Porter
  • 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. 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. Introduction Test::DBIx::Class::Schema Future FinallyAn example (running) $schematest->run_tests();Mostly Lazy DBIx::Class Testing Net-A-Porter
  • 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. 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. Introduction Test::DBIx::Class::Schema Future FinallyYou don’t get Functional TestingMostly Lazy DBIx::Class Testing Net-A-Porter
  • 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. 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. 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. Introduction Test::DBIx::Class::Schema Future FinallyDid It Work? YES! IMNSHOMostly Lazy DBIx::Class Testing Net-A-Porter
  • 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. 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

×