UPDATE: I've added two more tests to .t/bo/Rekening.t to check the protected setCreditAmount and setDebetAmount subs (and of course changed the number of tests from 13 to 15
Thanks for the comments and answers :)
I think I'll go with the following (sorry for the dutch names, Passief eq Passive Account and Rekening eq Account (the base class):
I'll implement the wrapper class for testing protected subs later on :)
./t/bo/Passief.t
#!/usr/bin/perl
use strict;
use warnings;
use Math::BigInt;
use Test::More tests => 12;
use Test::Exception;
# We need the Rekening and Actief classes
use src::bo::Passief;
# we test the passief account
my $passief = Passief>new("kapitaal");
is( ref $passief, "Passief", "A passief object" );
is( $passief>getName(), "kapitaal", "It's kapitaal" );
lives_ok { $passief>addToAccount() } "addToAccount is overwritten";
$passief>addToAccount( Math::BigInt>new(5) );
is( $passief>getDebetAmount(), Math::BigInt>new(5), "kapitaal has 5
+credit" );
is( ref $passief>getDebetAmount(),
"Math::BigInt", "getCreditAmount() returns a BigInt" );
lives_ok { $passief>subtractFromAccount() }
"subtractFromAccount is overwritten";
$passief>subtractFromAccount( Math::BigInt>new(4) );
is( $passief>getCreditAmount(), Math::BigInt>new(4), "kapitaal has 4
+ debet" );
is( ref $passief>getCreditAmount(),
"Math::BigInt", "getDebetAmount() returns a BigInt" );
is( $passief>balance(), 1, "kapitaal has a 1 balance" );
is( ref $passief>balance(), "Math::BigInt", "balance() returns a BigI
+nt" );
# we test if we can call setCreditAmount directly
throws_ok { $passief>setCreditAmount(0) } qr/setCreditAmount is prote
+cted/,
"setCreditAmount is protected";
# we test if we can call setDebetAmount directly
throws_ok { $passief>setDebetAmount(0) } qr/setDebetAmount is protect
+ed/,
"setDebetAmount is protected";
./t/bo/Rekening.t
#!/usr/bin/perl
use strict;
use warnings;
use Math::BigInt;
use Test::More tests => 15;
use Test::Exception;
# We need the Rekening and Actief classes
use src::bo::Rekening;
# a quick test to see if rekening works
my $rekening = Rekening>new("rekeningnaam");
is( ref $rekening, "Rekening", "A rekening object" );
is( $rekening>getName(), "rekeningnaam", "It's rekeningnaam" );
my $zero = Math::BigInt>new(0);
is( $rekening>getCreditAmount(), $zero, "kas has 0 credit" );
is( ref $rekening>getCreditAmount(),
"Math::BigInt", "getCreditAmount() returns a BigInt" );
is( $rekening>getDebetAmount(), $zero, "kas has 0 debet" );
is( ref $rekening>getDebetAmount(),
"Math::BigInt", "getDebetAmount() returns a BigInt" );
# we test a rekening without a name
my $rekening2 = Rekening>new();
is( ref $rekening2, "Rekening", "A rekening object" );
is( $rekening2>getName(), undef, "It's undef" );
# we test if we can call addToAccount directly
throws_ok { $rekening>addToAccount() } qr/Rekening is a base class/,
"addToAccount is protected";
# we test if we can call subtractFromAccount directly
throws_ok { $rekening>subtractFromAccount() } qr/Rekening is a base c
+lass/,
"subtractFromAccount is protected";
# we test if we can call balance directly
throws_ok { $rekening>balance() } qr/Rekening is a base class/,
"balance is protected";
# we test if we can call setCreditAmount directly
throws_ok { $rekening>setCreditAmount(0) } qr/setCreditAmount is prot
+ected/,
"setCreditAmount is protected";
# we test if we can call setDebetAmount directly
throws_ok { $rekening>setDebetAmount(0) } qr/setDebetAmount is protec
+ted/,
"setDebetAmount is protected";
# magic, we test the setCredit protected sub
my $setCredit;
my $setDebet;
{
package Sub::Rekening;
our @ISA = 'Rekening';
eval {
$rekening>setCreditAmount($two);
$rekening>setDebetAmount($one);
$setCredit = $rekening>getCreditAmount();
$setDebet = $rekening>getDebetAmount();
};
}
is( $setCredit, $two, "setCreditAmount returns 2" );
is( $setDebet, $one, "setDebetAmount returns 1" );

if ( 1 ) { $postman>ring() for (1..2); }
