Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Mocking relative Time

use strict;
use warnings;

use Test::MockTime qw(set_relative_time);
use Test::More;

use MySession;

my $session = MySession->new;
$session->login('foo', 'secret');
ok $session->logged_in('foo'),  'foo logged in';
ok !$session->logged_in('bar'), 'bar not logged in';
#sleep 61;
set_relative_time(61);
ok !$session->logged_in('foo'),  'foo not logged in - timeout';
ok !$session->logged_in('bar'), 'bar not logged in';

done_testing;

Make sure you load Test::MockTime before you load the module under testing. Otherwise the time function in that module won't be mocked.