Bugzilla – Attachment 110911 Details for
Bug 26555
Add a way for Koha::Object(s) to carry execution information
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26555: Add Koha::Object::Message
Bug-26555-Add-KohaObjectMessage.patch (text/plain), 4.56 KB, created by
Tomás Cohen Arazi (tcohen)
on 2020-09-29 13:19:14 UTC
(
hide
)
Description:
Bug 26555: Add Koha::Object::Message
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2020-09-29 13:19:14 UTC
Size:
4.56 KB
patch
obsolete
>From 17505630574e84c3d85031ce7e9a43308eb3ab47 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 28 Sep 2020 10:23:50 -0300 >Subject: [PATCH] Bug 26555: Add Koha::Object::Message > >This patch introduces a tiny class for encapsulating execution messages in >Koha::Object derived classes. > >To test: >1. Apply this patch >2. Run; > $ kshell > k$ prove t/Koha/Object/Message.t >=> SUCCESS: Tests pass! >3. Sign off :-D >--- > Koha/Object/Message.pm | 77 +++++++++++++++++++++++++++++++++++++++++ > t/Koha/Object/Message.t | 51 +++++++++++++++++++++++++++ > 2 files changed, 128 insertions(+) > create mode 100644 Koha/Object/Message.pm > create mode 100755 t/Koha/Object/Message.t > >diff --git a/Koha/Object/Message.pm b/Koha/Object/Message.pm >new file mode 100644 >index 0000000000..8efbbc3fda >--- /dev/null >+++ b/Koha/Object/Message.pm >@@ -0,0 +1,77 @@ >+package Koha::Object::Message; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use base qw(Class::Accessor); >+ >+use Koha::Exceptions; >+ >+__PACKAGE__->mk_ro_accessors(qw( message type )); >+ >+=head1 NAME >+ >+Koha::Object::Message - Class encapsulating errors in Koha::Object-derived classes >+ >+=head1 SYNOPSIS >+ >+ my ($self, $params) = @_; >+ push @{$self->{_errors}} = Koha::Object::Message->new($params); >+ >+=head1 API >+ >+=head2 Class methods >+ >+=head3 new >+ >+ my $message = Koha::Object::Message->new( >+ { >+ message => $some_message, >+ [ type => 'error' ] >+ } >+ ); >+ >+Create a new Koha::Object::Message object. >+ >+=cut >+ >+sub new { >+ my ( $class, $params ) = @_; >+ >+ my $message = $params->{message}; >+ my $type = $params->{type} // 'error'; >+ >+ Koha::Exceptions::MissingParameter->throw( "Mandatory parameter missing: 'message'" ) >+ unless $message; >+ >+ my $self = $class->SUPER::new( >+ { >+ message => $message, >+ type => $type >+ } >+ ); >+ >+ return $self; >+} >+ >+=head1 AUTHOR >+ >+Tomas Cohen Arazi, E<lt>tomascohen@theke.ioE<gt> >+ >+=cut >+ >+1; >diff --git a/t/Koha/Object/Message.t b/t/Koha/Object/Message.t >new file mode 100755 >index 0000000000..04bbe5e796 >--- /dev/null >+++ b/t/Koha/Object/Message.t >@@ -0,0 +1,51 @@ >+#!/usr/bin/perl >+ >+# Copyright 2020 Koha Development team >+# >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+use Test::Exception; >+ >+BEGIN { >+ use_ok('Koha::Object::Message'); >+} >+ >+subtest 'new() tests' => sub { >+ >+ plan tests => 8; >+ >+ my $some_error = 'Some error'; >+ >+ my $message = Koha::Object::Message->new({ message => $some_error }); >+ is( ref($message), 'Koha::Object::Message', 'Type is correct' ); >+ is( $message->message, $some_error, 'The message attribute has the right value' ); >+ is( $message->type, 'error', 'If omitted, the type is error' ); >+ >+ $message = Koha::Object::Message->new({ message => $some_error, type => 'callback' }); >+ is( ref($message), 'Koha::Object::Message', 'Type is correct' ); >+ is( $message->message, $some_error, 'The message attribute has the right value' ); >+ is( $message->type, 'callback', 'type is correct' ); >+ >+ throws_ok >+ { Koha::Object::Message->new({ blah => 'ohh' }); } >+ 'Koha::Exceptions::MissingParameter', >+ 'Exception thrown if required parameter missing'; >+ >+ is( "$@", "Mandatory parameter missing: 'message'", 'Expected exception message' ); >+}; >-- >2.28.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 26555
:
110854
|
110855
|
110911
|
110912
|
110913
|
110957
|
110958
|
110959
|
110967
|
110968
|
110969
|
110983
|
111426
|
111427
|
111428
|
111723