From 9638455f1f82e8e7904e8cf4dc62ae41fc900f5b Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 1 Dec 2022 08:51:53 +0000 Subject: [PATCH] Bug 32334: Exceptions - Add parameter to WrongParameter Test plan: Run t/Koha/Exceptions.t Signed-off-by: Marcel de Rooy Signed-off-by: David Nind --- Koha/Exceptions.pm | 3 ++- t/Koha/Exceptions.t | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Koha/Exceptions.pm b/Koha/Exceptions.pm index 80156abee7..00f45f661d 100644 --- a/Koha/Exceptions.pm +++ b/Koha/Exceptions.pm @@ -55,7 +55,8 @@ use Exception::Class ( }, 'Koha::Exceptions::WrongParameter' => { isa => 'Koha::Exception', - description => 'One or more parameters are wrong', + description => 'Parameter has wrong value or type', + fields => ['name', 'value', 'type'], }, 'Koha::Exceptions::NoPermission' => { isa => 'Koha::Exception', diff --git a/t/Koha/Exceptions.t b/t/Koha/Exceptions.t index fc3afb1601..748a0f8084 100755 --- a/t/Koha/Exceptions.t +++ b/t/Koha/Exceptions.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 10; +use Test::More tests => 11; use Test::MockObject; use Test::Exception; @@ -397,3 +397,15 @@ subtest 'Koha::Exception tests' => sub { 'Exception stringified correctly' ); }; + +subtest 'Passing parameters when throwing exception' => sub { + plan tests => 4; + + use Koha::Exceptions; + + throws_ok { Koha::Exceptions::WrongParameter->throw( name => 'wrong1', type => 'ARRAY', value => [ 1, 2 ] ) } qr/Koha::Exceptions::WrongParameter/, 'Exception thrown'; + my $desc = $@; + like( $desc, qr/name => wrong1/, 'Found name' ); + like( $desc, qr/type => ARRAY/, 'Found type' ); + like( $desc, qr/value => ARRAY\(\w+\)/, 'Found value' ); +}; -- 2.30.2