Conver the FlatRate shipping driver to use exceptions.

This commit is contained in:
Colin Kuskie 2008-02-28 17:00:34 +00:00
parent 922830386d
commit ea500fd1b2
2 changed files with 14 additions and 4 deletions

View file

@ -2,7 +2,7 @@ package WebGUI::Shop::ShipDriver::FlatRate;
use strict;
use base qw/WebGUI::Shop::ShipDriver/;
use Carp qw/croak/;
use WebGUI::Exception;
=head1 NAME
@ -58,7 +58,7 @@ the user.
sub definition {
my $class = shift;
my $session = shift;
croak "Definition requires a session object"
WebGUI::Error::InvalidParam->throw(error => q{Must provide a session variable})
unless ref $session eq 'WebGUI::Session';
my $definition = shift || [];
my $i18n = WebGUI::International->new($session, 'ShipDriver_FlatRate');

View file

@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 11;
my $tests = 12;
plan tests => 1 + $tests;
#----------------------------------------------------------------------------
@ -52,9 +52,19 @@ skip 'Unable to load module WebGUI::Shop::ShipDriver::FlatRate', $tests unless $
#######################################################################
my $definition;
my $e; ##Exception variable, used throughout the file
eval { $definition = WebGUI::Shop::ShipDriver::FlatRate->definition(); };
like ($@, qr/^Definition requires a session object/, 'definition croaks without a session object');
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'definition takes an exception to not giving it a session variable');
cmp_deeply(
$e,
methods(
error => 'Must provide a session variable',
),
'definition: requires a session variable',
);
$definition = WebGUI::Shop::ShipDriver::FlatRate->definition($session);