Bugzilla – Attachment 108921 Details for
Bug 26157
Redirect expected DBI warnings
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26157: Hide expected DBI warnings from tests
Bug-26157-Hide-expected-DBI-warnings-from-tests.patch (text/plain), 9.14 KB, created by
Katrin Fischer
on 2020-08-22 12:07:07 UTC
(
hide
)
Description:
Bug 26157: Hide expected DBI warnings from tests
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2020-08-22 12:07:07 UTC
Size:
9.14 KB
patch
obsolete
>From 6e3f63ecd706779aa6f26e611cd90c162995535e Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 6 Aug 2020 13:11:50 +0200 >Subject: [PATCH] Bug 26157: Hide expected DBI warnings from tests > >We must redirect them to /dev/null if we know they will appear. > >Test plan: >prove the different test files and confirm that the output is clean when >this patch is applied > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> >--- > t/db_dependent/Koha/Account.t | 28 ++++++++++++--------- > t/db_dependent/Koha/ApiKeys.t | 14 ++++++++--- > t/db_dependent/Koha/Object.t | 11 ++++++--- > t/db_dependent/Koha/Patrons.t | 10 +++++--- > t/db_dependent/Koha/Suggestions.t | 51 ++++++++++++++++++++++++++++++--------- > 5 files changed, 81 insertions(+), 33 deletions(-) > >diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t >index 9b37a08f8a..0941fbbca5 100755 >--- a/t/db_dependent/Koha/Account.t >+++ b/t/db_dependent/Koha/Account.t >@@ -340,17 +340,23 @@ subtest 'add_debit() tests' => sub { > ); } 'Koha::Exceptions::Account::AmountNotPositive', 'Expected validation exception thrown (amount)'; > > throws_ok { >- $account->add_debit( >- { >- amount => 5, >- description => 'type validation failure', >- library_id => $patron->branchcode, >- note => 'this should fail anyway', >- type => 'failure', >- user_id => $patron->id, >- interface => 'commandline' >- } >- ); } 'Koha::Exceptions::Account::UnrecognisedType', 'Expected validation exception thrown (type)'; >+ local *STDERR; >+ open STDERR, '>', '/dev/null'; >+ $account->add_debit( >+ { >+ amount => 5, >+ description => 'type validation failure', >+ library_id => $patron->branchcode, >+ note => 'this should fail anyway', >+ type => 'failure', >+ user_id => $patron->id, >+ interface => 'commandline' >+ } >+ ); >+ close STDERR; >+ } >+ 'Koha::Exceptions::Account::UnrecognisedType', >+ 'Expected validation exception thrown (type)'; > > throws_ok { > $account->add_debit( >diff --git a/t/db_dependent/Koha/ApiKeys.t b/t/db_dependent/Koha/ApiKeys.t >index 154f69c018..94ce452c8b 100755 >--- a/t/db_dependent/Koha/ApiKeys.t >+++ b/t/db_dependent/Koha/ApiKeys.t >@@ -79,10 +79,18 @@ subtest 'store() tests' => sub { > my $deleted_id = $patron_to_delete->id; > $patron_to_delete->delete; > >- throws_ok >- { Koha::ApiKey->new({ patron_id => $deleted_id, description => 'a description' })->store } >+ { # hide useless warnings >+ local *STDERR; >+ open STDERR, '>', '/dev/null'; >+ throws_ok { >+ Koha::ApiKey->new( >+ { patron_id => $deleted_id, description => 'a description' } ) >+ ->store >+ } > 'Koha::Exceptions::Object::FKConstraint', >- 'Invalid patron ID raises exception'; >+ 'Invalid patron ID raises exception'; >+ close STDERR; >+ } > is( $@->message, 'Broken FK constraint', 'Exception message is correct' ); > is( $@->broken_fk, 'patron_id', 'Exception field is correct' ); > >diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t >index 919472e874..cae049cbd2 100755 >--- a/t/db_dependent/Koha/Object.t >+++ b/t/db_dependent/Koha/Object.t >@@ -620,8 +620,8 @@ subtest 'store() tests' => sub { > > my $dbh = $schema->storage->dbh; > { >- local $dbh->{PrintError} = 0; >- local $dbh->{RaiseError} = 0; >+ local *STDERR; >+ open STDERR, '>', '/dev/null'; > throws_ok > { $api_key->store } > 'Koha::Exceptions::Object::FKConstraint', >@@ -662,6 +662,7 @@ subtest 'store() tests' => sub { > qr/(api_keys\.)?secret/, > 'Exception field is correct (note that MySQL 8 is displaying the tablename)' > ); >+ close STDERR; > } > > # Successful test >@@ -714,10 +715,12 @@ subtest 'store() tests' => sub { > > my $patron = $builder->build_object({ class => 'Koha::Patrons' }); > >+ > try { >- local $schema->storage->dbh->{RaiseError} = 0; >- local $schema->storage->dbh->{PrintError} = 0; >+ local *STDERR; >+ open STDERR, '>', '/dev/null'; > $patron->lastseen('wrong_value')->store; >+ close STDERR; > } catch { > ok( $_->isa('Koha::Exceptions::Object::BadValue'), 'Exception thrown correctly' ); > like( $_->property, qr/(borrowers\.)?lastseen/, 'Column should be the expected one' ); # The table name is not always displayed, it depends on the DBMS version >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index 4f434adc3c..5704463390 100644 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -1738,10 +1738,14 @@ subtest '->store' => sub { > my $patron_1 = $builder->build_object({class=> 'Koha::Patrons'}); > my $patron_2 = $builder->build_object({class=> 'Koha::Patrons'}); > >- throws_ok >- { $patron_2->userid($patron_1->userid)->store; } >+ { >+ local *STDERR; >+ open STDERR, '>', '/dev/null'; >+ throws_ok { $patron_2->userid( $patron_1->userid )->store; } > 'Koha::Exceptions::Object::DuplicateID', >- 'Koha::Patron->store raises an exception on duplicate ID'; >+ 'Koha::Patron->store raises an exception on duplicate ID'; >+ close STDERR; >+ } > > # Test password > t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); >diff --git a/t/db_dependent/Koha/Suggestions.t b/t/db_dependent/Koha/Suggestions.t >index f4c4974548..a4941bbc59 100644 >--- a/t/db_dependent/Koha/Suggestions.t >+++ b/t/db_dependent/Koha/Suggestions.t >@@ -125,9 +125,16 @@ subtest 'constraints' => sub { > "The suggestion is not deleted when the related branch is deleted" ); > > # managerid >- throws_ok { $suggestion->managedby($nonexistent_borrowernumber)->store; } >- 'Koha::Exceptions::Object::FKConstraint', >- 'store raises an exception on invalid managerid'; >+ { # hide useless warnings >+ local *STDERR; >+ open STDERR, '>', '/dev/null'; >+ throws_ok { >+ $suggestion->managedby($nonexistent_borrowernumber)->store; >+ } >+ 'Koha::Exceptions::Object::FKConstraint', >+ 'store raises an exception on invalid managerid'; >+ close STDERR; >+ } > my $manager = $builder->build_object( { class => "Koha::Patrons" } ); > $suggestion->managedby( $manager->borrowernumber )->store; > $manager->delete; >@@ -136,9 +143,16 @@ subtest 'constraints' => sub { > "The suggestion is not deleted when the related manager is deleted" ); > > # acceptedby >- throws_ok { $suggestion->acceptedby($nonexistent_borrowernumber)->store; } >- 'Koha::Exceptions::Object::FKConstraint', >- 'store raises an exception on invalid acceptedby id'; >+ { # hide useless warnings >+ local *STDERR; >+ open STDERR, '>', '/dev/null'; >+ throws_ok { >+ $suggestion->acceptedby($nonexistent_borrowernumber)->store; >+ } >+ 'Koha::Exceptions::Object::FKConstraint', >+ 'store raises an exception on invalid acceptedby id'; >+ close STDERR; >+ } > my $acceptor = $builder->build_object( { class => "Koha::Patrons" } ); > $suggestion->acceptedby( $acceptor->borrowernumber )->store; > $acceptor->delete; >@@ -147,9 +161,16 @@ subtest 'constraints' => sub { > "The suggestion is not deleted when the related acceptor is deleted" ); > > # rejectedby >- throws_ok { $suggestion->rejectedby($nonexistent_borrowernumber)->store; } >- 'Koha::Exceptions::Object::FKConstraint', >- 'store raises an exception on invalid rejectedby id'; >+ { # hide useless warnings >+ local *STDERR; >+ open STDERR, '>', '/dev/null'; >+ throws_ok { >+ $suggestion->rejectedby($nonexistent_borrowernumber)->store; >+ } >+ 'Koha::Exceptions::Object::FKConstraint', >+ 'store raises an exception on invalid rejectedby id'; >+ close STDERR; >+ } > my $rejecter = $builder->build_object( { class => "Koha::Patrons" } ); > $suggestion->rejectedby( $rejecter->borrowernumber )->store; > $rejecter->delete; >@@ -158,9 +179,15 @@ subtest 'constraints' => sub { > "The suggestion is not deleted when the related rejecter is deleted" ); > > # budgetid >- throws_ok { $suggestion->budgetid($nonexistent_borrowernumber)->store; } >- 'Koha::Exceptions::Object::FKConstraint', >- 'store raises an exception on invalid budgetid'; >+ { # hide useless warnings >+ local *STDERR; >+ open STDERR, '>', '/dev/null'; >+ >+ throws_ok { $suggestion->budgetid($nonexistent_borrowernumber)->store; } >+ 'Koha::Exceptions::Object::FKConstraint', >+ 'store raises an exception on invalid budgetid'; >+ close STDERR; >+ } > my $fund = $builder->build_object( { class => "Koha::Acquisition::Funds" } ); > $suggestion->budgetid( $fund->id )->store; > $fund->delete; >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 26157
:
107874
|
108802
| 108921 |
109819