Bugzilla – Attachment 102070 Details for
Bug 22001
Add RaiseError and PrintError flags for all tests
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22001: Fix Object.t - handle correct RaiseError and PrintError
Bug-22001-Fix-Objectt---handle-correct-RaiseError-.patch (text/plain), 4.23 KB, created by
Jonathan Druart
on 2020-03-30 09:06:13 UTC
(
hide
)
Description:
Bug 22001: Fix Object.t - handle correct RaiseError and PrintError
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-03-30 09:06:13 UTC
Size:
4.23 KB
patch
obsolete
>From 489fcc99b2dc385398386683cbe8a542f3f8a97e Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 30 Mar 2020 11:04:51 +0200 >Subject: [PATCH] Bug 22001: Fix Object.t - handle correct RaiseError and > PrintError > >--- > t/db_dependent/Koha/Object.t | 94 ++++++++++++++++++------------------ > 1 file changed, 46 insertions(+), 48 deletions(-) > >diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t >index 73e4e10762..0918785375 100755 >--- a/t/db_dependent/Koha/Object.t >+++ b/t/db_dependent/Koha/Object.t >@@ -610,50 +610,51 @@ subtest 'store() tests' => sub { > > my $api_key = Koha::ApiKey->new({ patron_id => $patron_id, secret => 'a secret', description => 'a description' }); > >- my $print_error = $schema->storage->dbh->{PrintError}; >- $schema->storage->dbh->{PrintError} = 0; >- throws_ok >- { $api_key->store } >- 'Koha::Exceptions::Object::FKConstraint', >- 'Exception is thrown correctly'; >- is( >- $@->message, >- "Broken FK constraint", >- 'Exception message is correct' >- ); >- is( >- $@->broken_fk, >- 'patron_id', >- 'Exception field is correct' >- ); >- >- $patron = $builder->build_object({ class => 'Koha::Patrons' }); >- $api_key = $builder->build_object({ class => 'Koha::ApiKeys' }); >- >- my $new_api_key = Koha::ApiKey->new({ >- patron_id => $patron_id, >- secret => $api_key->secret, >- description => 'a description', >- }); >- >- throws_ok >- { $new_api_key->store } >- 'Koha::Exceptions::Object::DuplicateID', >- 'Exception is thrown correctly'; >- >- is( >- $@->message, >- 'Duplicate ID', >- 'Exception message is correct' >- ); >- >- like( >- $@->duplicate_id, >- qr/(api_keys\.)?secret/, >- 'Exception field is correct (note that MySQL 8 is displaying the tablename)' >- ); >+ my $dbh = $schema->storage->dbh; >+ { >+ local $dbh->{PrintError} = 0; >+ local $dbh->{RaiseError} = 0; >+ throws_ok >+ { $api_key->store } >+ 'Koha::Exceptions::Object::FKConstraint', >+ 'Exception is thrown correctly'; >+ is( >+ $@->message, >+ "Broken FK constraint", >+ 'Exception message is correct' >+ ); >+ is( >+ $@->broken_fk, >+ 'patron_id', >+ 'Exception field is correct' >+ ); >+ >+ $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ $api_key = $builder->build_object({ class => 'Koha::ApiKeys' }); >+ >+ my $new_api_key = Koha::ApiKey->new({ >+ patron_id => $patron_id, >+ secret => $api_key->secret, >+ description => 'a description', >+ }); > >- $schema->storage->dbh->{PrintError} = $print_error; >+ throws_ok >+ { $new_api_key->store } >+ 'Koha::Exceptions::Object::DuplicateID', >+ 'Exception is thrown correctly'; >+ >+ is( >+ $@->message, >+ 'Duplicate ID', >+ 'Exception message is correct' >+ ); >+ >+ like( >+ $@->duplicate_id, >+ qr/(api_keys\.)?secret/, >+ 'Exception field is correct (note that MySQL 8 is displaying the tablename)' >+ ); >+ } > > # Successful test > $api_key->set({ secret => 'Manuel' }); >@@ -705,18 +706,15 @@ subtest 'store() tests' => sub { > > my $patron = $builder->build_object({ class => 'Koha::Patrons' }); > >- my $print_error = $schema->storage->dbh->{PrintError}; >- $schema->storage->dbh->{PrintError} = 0; >- > try { >+ local $schema->storage->dbh->{RaiseError} = 0; >+ local $schema->storage->dbh->{PrintError} = 0; > $patron->lastseen('wrong_value')->store; > } 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 > is( $_->value, 'wrong_value', 'Value should be the expected one' ); > }; >- >- $schema->storage->dbh->{PrintError} = $print_error; > }; > > $schema->storage->txn_rollback; >-- >2.20.1
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 22001
:
83230
|
83231
|
83232
|
98910
|
98911
|
98912
|
99589
|
99590
|
99591
|
101989
|
101990
|
101991
| 102070 |
102140
|
102147
|
102149
|
102150
|
102151
|
102152