@@ -, +, @@ - Koha::Exceptions::Plugin::InstallDied - Koha::Exceptions::Plugin::UpgradeDied $ kshell k$ prove t/Koha/Exceptions.t --- Koha/Exceptions/Plugin.pm | 42 ++++++++++++++++++++++++++++++++++++++- t/Koha/Exceptions.t | 29 ++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) --- a/Koha/Exceptions/Plugin.pm +++ a/Koha/Exceptions/Plugin.pm @@ -31,7 +31,17 @@ use Exception::Class ( isa => 'Koha::Exceptions::Plugin', description => 'Required method is missing', fields => ['plugin_name','method'] - } + }, + 'Koha::Exceptions::Plugin::InstallDied' => { + isa => 'Koha::Exceptions::Plugin', + description => 'The plugin died on install', + fields => ['plugin_class'], + }, + 'Koha::Exceptions::Plugin::UpgradeDied' => { + isa => 'Koha::Exceptions::Plugin', + description => 'The plugin died on upgrade', + fields => ['plugin_class'], + }, ); sub full_message { @@ -43,6 +53,12 @@ sub full_message { if ( $self->isa('Koha::Exceptions::Plugin::MissingMethod') ) { $msg = sprintf("Cannot use plugin (%s) because the it doesn't implement the '%s' method which is required.", $self->plugin_name, $self->method ); } + elsif ( $self->isa('Koha::Exceptions::Plugin::InstallDied') ) { + $msg = sprintf("Calling 'install' died for plugin %s", $self->plugin_class); + } + elsif ( $self->isa('Koha::Exceptions::Plugin::UpgradeDied') ) { + $msg = sprintf("Calling 'upgrade' died for plugin %s", $self->plugin_class); + } } return $msg; @@ -73,6 +89,30 @@ method and it doesn't. =back +=head2 Koha::Exceptions::Plugin::InstallDied + +Exception to be used when a plugin 'install' method explodes. + +=head3 Parameters + +=over + +=item plugin_class: the plugin class + +=back + +=head2 Koha::Exceptions::Plugin::UpgradeDied + +Exception to be used when a plugin 'upgrade' method explodes. + +=head3 Parameters + +=over + +=item plugin_class: the plugin class + +=back + =head1 Class methods =head2 full_message --- a/t/Koha/Exceptions.t +++ a/t/Koha/Exceptions.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 8; +use Test::More tests => 9; use Test::MockObject; use Test::Exception; @@ -309,3 +309,30 @@ subtest 'Koha::Exceptions::Patron tests' => sub { 'Exception is thrown :-D'; is( "$@", 'Manual message exception', 'Exception not stringified if manually passed' ); }; + +subtest 'Koha::Exceptions::Plugin tests' => sub { + + plan tests => 5; + + use_ok("Koha::Exceptions::Plugin"); + + my $plugin_class = 'yahey'; + + throws_ok + { Koha::Exceptions::Plugin::InstallDied->throw( + plugin_class => $plugin_class ); } + 'Koha::Exceptions::Plugin::InstallDied', + 'Exception is thrown :-D'; + + # stringify the exception + is( "$@", "Calling 'install' died for plugin $plugin_class", 'Exception stringified correctly' ); + + throws_ok + { Koha::Exceptions::Plugin::UpgradeDied->throw( + plugin_class => $plugin_class ); } + 'Koha::Exceptions::Plugin::UpgradeDied', + 'Exception is thrown :-D'; + + # stringify the exception + is( "$@", "Calling 'upgrade' died for plugin $plugin_class", 'Exception stringified correctly' ); +}; --