nasty hack
[catagits/Catalyst-Plugin-Session.git] / t / 01_setup.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 10;
7 use Test::MockObject;
8 use Test::Deep;
9
10 my $m;
11 BEGIN { use_ok( $m = "Catalyst::Plugin::Session" ) }
12
13 my %config;
14 my $log      = Test::MockObject->new;
15 my @mock_isa = ();
16
17 $log->set_true("fatal");
18
19 {
20
21     package MockCxt;
22     use base $m;
23     sub new { bless {}, $_[0] }
24     sub config { \%config }
25     sub log    { $log }
26
27     sub isa {
28         my $self  = shift;
29         my $class = shift;
30         grep { $_ eq $class } @mock_isa or $self->SUPER::isa($class);
31     }
32 }
33
34 can_ok( $m, "setup" );
35
36 eval { MockCxt->new->setup };    # throws OK is not working with NEXT
37 like(
38     $@,
39     qr/requires.*((?:State|Store).*){2}/i,
40     "can't setup an object that doesn't use state/store plugins"
41 );
42
43 $log->called_ok( "fatal", "fatal error logged" );
44
45 @mock_isa = qw/Catalyst::Plugin::Session::State/;
46 eval { MockCxt->new->setup };
47 like( $@, qr/requires.*(?:Store)/i,
48     "can't setup an object that doesn't use state/store plugins" );
49
50 @mock_isa = qw/Catalyst::Plugin::Session::Store/;
51 eval { MockCxt->new->setup };
52 like( $@, qr/requires.*(?:State)/i,
53     "can't setup an object that doesn't use state/store plugins" );
54
55 $log->clear;
56
57 @mock_isa =
58   qw/Catalyst::Plugin::Session::State Catalyst::Plugin::Session::Store/;
59 eval { MockCxt->new->setup };
60 ok( !$@, "setup() lives with state/store plugins in use" );
61 ok( !$log->called("fatal"), "no fatal error logged either" );
62
63 cmp_deeply(
64     [ keys %{ $config{session} } ],
65     bag(qw/expires verify_address/),
66     "default values for config were populated in successful setup",
67 );
68
69 %config = ( session => { expires => 1234 } );
70 MockCxt->new->setup;
71 is( $config{session}{expires},
72     1234, "user values are not overwritten in config" );
73