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