Skip to content

Commit

Permalink
working interceptLogging
Browse files Browse the repository at this point in the history
  • Loading branch information
haarg committed Jun 14, 2010
1 parent d661d97 commit b48b0be
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions t/lib/WebGUI/Test.pm
Expand Up @@ -224,16 +224,28 @@ mock the isDebug flag so that debug output is always generated.
=cut

my $origLogger;
sub interceptLogging {
my $logger = $CLASS->session->log->getLogger;
$logger = Test::MockObject::Extends->new( $logger );

$logger->mock( 'warn', sub { our $logger_warns = $_[1]} );
$logger->mock( 'debug', sub { our $logger_debug = $_[1]} );
$logger->mock( 'info', sub { our $logger_info = $_[1]} );
$logger->mock( 'error', sub { our $logger_error = $_[1]} );
$logger->mock( 'isDebug', sub { return 1 } );
$logger->mock( 'is_debug', sub { return 1 } );
my $log = $CLASS->session->log;
$origLogger ||= $log->{_logger};
$log->{_logger} = sub {
my $info = shift;
my $level = $info->{level};
my $message = $info->{message};

if ($level eq 'warn') {
our $logger_warns = $message;
}
elsif ($level eq 'debug') {
our $logger_debug = $message;
}
elsif ($level eq 'info') {
our $logger_info = $message;
}
elsif ($level eq 'error') {
our $logger_error = $message;
}
};
}

#----------------------------------------------------------------------------
Expand All @@ -245,14 +257,9 @@ Restores's the logging object to its original state.
=cut

sub restoreLogging {
my $logger = $CLASS->session->log->getLogger;

$logger->unmock( 'warn' )
->unmock( 'debug' )
->unmock( 'info' )
->unmock( 'error' )
->unmock( 'isDebug' )
->unmock( 'is_debug' );
my $log = $CLASS->session->log;
$log->{_logger} = $origLogger;
undef $origLogger;
}

#----------------------------------------------------------------------------
Expand Down

0 comments on commit b48b0be

Please sign in to comment.