diff --git a/src/perl/Build.PL b/src/perl/Build.PL index 9e6838aac..3bdc00b4a 100644 --- a/src/perl/Build.PL +++ b/src/perl/Build.PL @@ -22,11 +22,12 @@ my $build = Build->new 'Module::Build' => 0.42 }, test_requires => { - 'TAP::Harness' => '>= 3.30', - 'Test::Class' => '>= 0.41', - 'Test::More' => '>= 0.98', - 'Test::Exception' => '>= 0.32', - 'Test::Compile' => 0 + 'TAP::Harness' => '>= 3.30', + 'Test::Class' => '>= 0.41', + 'Test::MockObject' => 0, + 'Test::More' => '>= 0.98', + 'Test::Exception' => '>= 0.32', + 'Test::Compile' => 0 }, requires => { 'Config::IniFiles' => '>= 2.8.6', diff --git a/src/perl/lib/WTSI/NPG/Genotyping/Database/Infinium.pm b/src/perl/lib/WTSI/NPG/Genotyping/Database/Infinium.pm index 95aad14dc..37632e926 100644 --- a/src/perl/lib/WTSI/NPG/Genotyping/Database/Infinium.pm +++ b/src/perl/lib/WTSI/NPG/Genotyping/Database/Infinium.pm @@ -384,7 +384,7 @@ sub find_called_file_project { idat_grn_path => , idat_red_path => , image_date => , - iso_image_date => } + image_iso_date => } The finds all samples in a project, even those that have never been scanned. For those that have been scanned more than @@ -520,7 +520,7 @@ sub find_project_samples { idat_grn_path => , idat_red_path => , image_date => , - iso_image_date => } + image_iso_date => } Returntype : hashref =cut @@ -625,7 +625,7 @@ sub find_project_completed_samples { idat_grn_path => , idat_red_path => , image_date => , - iso_image_date => } + image_iso_date => } Returntype : hashref =cut @@ -679,7 +679,7 @@ sub find_scanned_sample { idat_grn_path => , idat_red_path => , image_date => , - iso_image_date => } + image_iso_date => } Returntype : hashref =cut @@ -915,10 +915,10 @@ sub _choose_from_scans { foreach my $sample (@$samples) { my $name = $sample->{sample}; - push @sample_names, $name; unless (exists $samples_by_name{$name}) { $samples_by_name{$name} = []; + push @sample_names, $name; } push @{$samples_by_name{$name}}, $sample; diff --git a/src/perl/t/WTSI/NPG/Genotyping/Database/InfiniumTest.pm b/src/perl/t/WTSI/NPG/Genotyping/Database/InfiniumTest.pm index a84d515eb..51f5db5a2 100644 --- a/src/perl/t/WTSI/NPG/Genotyping/Database/InfiniumTest.pm +++ b/src/perl/t/WTSI/NPG/Genotyping/Database/InfiniumTest.pm @@ -7,8 +7,9 @@ use strict; use warnings; use base qw(WTSI::NPG::Test); -use Test::More tests => 13; +use Test::More tests => 14; use Test::Exception; +use Test::MockObject; use Log::Log4perl; @@ -60,4 +61,84 @@ sub disconnect : Test(4) { } } +sub repeat_scans : Test(1) { + + my $db = WTSI::NPG::Genotyping::Database::Infinium->new + (name => 'infinium', + inifile => $db_credentials); + + # This test is fragile because it relies on knowing about the + # internals of the package under test. However, it's better than + # nothing, until we commit resources to refactoring. + my $sth = Test::MockObject->new; + $sth->set_true('execute'); + $sth->set_series('fetchrow_hashref', + {plate => 'ABC123456-DNA', + well => 'A01', + sample => 'sample1', + beadchip => '0123456789', + beadchip_section => 'R01C01', + beadchip_design => 'test_design', + beadchip_revision => '1', + status => 'Pass', + gtc_file => 'test.gtc', + idat_grn_file => 'test_Grn.idat', + idat_red_file => 'test_Red.idat', + idat_grn_path => '/test', + idat_red_path => '/test', + image_date => '', + image_iso_date => '2016-10-01'}, + {plate => 'ABC123456-DNA', + well => 'A01', + sample => 'sample1', + beadchip => '0123456789', + beadchip_section => 'R01C01', + beadchip_design => 'test_design', + beadchip_revision => '1', + status => 'Pass', + gtc_file => 'test.gtc', + idat_grn_file => 'test_Grn.idat', + idat_red_file => 'test_Red.idat', + idat_grn_path => '/test', + idat_red_path => '/test', + image_date => '', + image_iso_date => '2016-10-02'}, + {plate => 'ABC123456-DNA', + well => 'A01', + sample => 'sample1', + beadchip => '0123456789', + beadchip_section => 'R01C01', + beadchip_design => 'test_design', + beadchip_revision => '1', + status => 'Pass', + gtc_file => 'test.gtc', + idat_grn_file => 'test_Grn.idat', + idat_red_file => 'test_Red.idat', + idat_grn_path => '/test', + idat_red_path => '/test', + image_date => '', + image_iso_date => '2016-10-03'}); + + my $dbh = Test::MockObject->new; + $dbh->set_always('prepare', $sth); + $db->dbh($dbh); + + is_deeply($db->find_project_samples('test'), + [{plate => 'ABC123456-DNA', + well => 'A01', + sample => 'sample1', + beadchip => '0123456789', + beadchip_section => 'R01C01', + beadchip_design => 'test_design', + beadchip_revision => '1', + status => 'Pass', + gtc_file => 'test.gtc', + idat_grn_file => 'test_Grn.idat', + idat_red_file => 'test_Red.idat', + idat_grn_path => '/test', + idat_red_path => '/test', + image_date => '', + image_iso_date => '2016-10-03'}], + 'Repeat scans resolved to latest'); +} 1;