Bugzilla – Attachment 117676 Details for
Bug 27833
Koha::Exceptions::Patron::Attribute::* should have parameters
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27833: (follow-up) Add InvalidType exception
Bug-27833-follow-up-Add-InvalidType-exception.patch (text/plain), 4.86 KB, created by
Tomás Cohen Arazi (tcohen)
on 2021-03-04 10:42:12 UTC
(
hide
)
Description:
Bug 27833: (follow-up) Add InvalidType exception
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2021-03-04 10:42:12 UTC
Size:
4.86 KB
patch
obsolete
>From 1b6d67d1dd5f1004b3ec59bf6115eff52de86f4a Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 4 Mar 2021 07:39:27 -0300 >Subject: [PATCH] Bug 27833: (follow-up) Add InvalidType exception > >Working on bug 27857 showed we needed one more exception, for when the >passed attribute type is invalid. > >This patch adds the Koha::Exceptions::Patron::Attribute::InvalidType >exception. It adds a format for stringifying it, and tests are added. >The previous exceptions tests lacked one case, so I add them on this >patch as well. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove tt/Koha/Exceptions.t >=> SUCCESS: Tests pass! >3. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/Exceptions/Patron/Attribute.pm | 11 +++++ > t/Koha/Exceptions.t | 65 +++++++++++++++++++++++++++-- > 2 files changed, 73 insertions(+), 3 deletions(-) > >diff --git a/Koha/Exceptions/Patron/Attribute.pm b/Koha/Exceptions/Patron/Attribute.pm >index 93bc34ca470..fd9b70cd394 100644 >--- a/Koha/Exceptions/Patron/Attribute.pm >+++ b/Koha/Exceptions/Patron/Attribute.pm >@@ -7,6 +7,11 @@ use Exception::Class ( > 'Koha::Exceptions::Patron::Attribute' => { > description => 'Something went wrong' > }, >+ 'Koha::Exceptions::Patron::Attribute::InvalidType' => { >+ isa => 'Koha::Exceptions::Patron::Attribute', >+ description => "the passed type is invalid", >+ fields => [ "type" ] >+ }, > 'Koha::Exceptions::Patron::Attribute::NonRepeatable' => { > isa => 'Koha::Exceptions::Patron::Attribute', > description => "repeatable not set for attribute type and tried to add a new attribute for the same code", >@@ -39,6 +44,12 @@ sub full_message { > $self->attribute->attribute > ); > } >+ elsif ( $self->isa('Koha::Exceptions::Patron::Attribute::InvalidType') ) { >+ $msg = sprintf( >+ "Tried to use an invalid attribute type. type=%s", >+ $self->type >+ ); >+ } > } > > return $msg; >diff --git a/t/Koha/Exceptions.t b/t/Koha/Exceptions.t >index 1a019435825..110b39e145a 100755 >--- a/t/Koha/Exceptions.t >+++ b/t/Koha/Exceptions.t >@@ -200,7 +200,7 @@ subtest 'Koha::Exceptions::Object::NotInstantiated tests' => sub { > > subtest 'Koha::Exceptions::Patron::Attribute::* tests' => sub { > >- plan tests => 5; >+ plan tests => 13; > > use_ok("Koha::Exceptions::Patron::Attribute"); > >@@ -218,11 +218,70 @@ subtest 'Koha::Exceptions::Patron::Attribute::* tests' => sub { > 'Exception is thrown :-D'; > > # stringify the exception >- is( "$@", "Tried to add more than one non-repeatable attributes. code=$code attribute=$attribute", 'Exception stringified correctly' ); >+ is( >+ "$@", >+ "Tried to add more than one non-repeatable attributes. code=$code attribute=$attribute", >+ 'Exception stringified correctly' >+ ); > > throws_ok > { Koha::Exceptions::Patron::Attribute::NonRepeatable->throw( "Manual message exception" ) } > 'Koha::Exceptions::Patron::Attribute::NonRepeatable', > 'Exception is thrown :-D'; >- is( "$@", 'Manual message exception', 'Exception not stringified if manually passed' ); >+ >+ is( >+ "$@", >+ 'Manual message exception', >+ 'Exception not stringified if manually passed' >+ ); >+ >+ throws_ok >+ { Koha::Exceptions::Patron::Attribute::UniqueIDConstraint->throw( >+ attribute => $mocked_attribute ); } >+ 'Koha::Exceptions::Patron::Attribute::UniqueIDConstraint', >+ 'Exception is thrown :-D'; >+ >+ # stringify the exception >+ is( >+ "$@", >+ "Your action breaks a unique constraint on the attribute. code=$code attribute=$attribute", >+ 'Exception stringified correctly' >+ ); >+ >+ throws_ok >+ { Koha::Exceptions::Patron::Attribute::UniqueIDConstraint->throw( "Manual message exception" ) } >+ 'Koha::Exceptions::Patron::Attribute::UniqueIDConstraint', >+ 'Exception is thrown :-D'; >+ >+ is( >+ "$@", >+ 'Manual message exception', >+ 'Exception not stringified if manually passed' >+ ); >+ >+ my $type = "SOME_TYPE"; >+ >+ throws_ok >+ { Koha::Exceptions::Patron::Attribute::InvalidType->throw( >+ type => $type ); } >+ 'Koha::Exceptions::Patron::Attribute::InvalidType', >+ 'Exception is thrown :-D'; >+ >+ # stringify the exception >+ is( >+ "$@", >+ "Tried to use an invalid attribute type. type=$type", >+ 'Exception stringified correctly' >+ ); >+ >+ throws_ok >+ { Koha::Exceptions::Patron::Attribute::InvalidType->throw( "Manual message exception" ) } >+ 'Koha::Exceptions::Patron::Attribute::InvalidType', >+ 'Exception is thrown :-D'; >+ >+ is( >+ "$@", >+ 'Manual message exception', >+ 'Exception not stringified if manually passed' >+ ); > }; >-- >2.30.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 27833
:
117516
|
117517
|
117518
|
117546
|
117547
|
117548
|
117676
|
117701
|
117702
|
117703
|
117704