include test for failure mode
[catagits/Catalyst-Runtime.git] / t / unit_core_setup.t
1 use strict;
2 use warnings;
3 use Catalyst::Runtime;
4
5 use Test::More tests => 20;
6
7 {
8     # Silence the log.
9     no warnings 'redefine';
10     *Catalyst::Log::_send_to_log = sub {};
11 }
12
13 TESTDEBUG: {
14     package MyTestDebug;
15     use base qw/Catalyst/;
16     __PACKAGE__->setup(
17         '-Debug',
18     );
19 }
20
21 ok my $c = MyTestDebug->new, 'Get debug app object';
22 ok my $log = $c->log, 'Get log object';
23 isa_ok $log,        'Catalyst::Log', 'It should be a Catalyst::Log object';
24 ok !$log->is_warn,  'Warnings should be disabled';
25 ok !$log->is_error, 'Errors should be disabled';
26 ok !$log->is_fatal, 'Fatal errors should be disabled';
27 ok !$log->is_info,  'Info should be disabled';
28 ok $log->is_debug,  'Debugging should be enabled';
29 can_ok 'MyTestDebug', 'debug';
30 ok +MyTestDebug->debug, 'And it should return true';
31
32
33 TESTAPP: {
34     package MyTestLog;
35     use base qw/Catalyst/;
36     __PACKAGE__->setup(
37         '-Log=warn,error,fatal'
38     );
39 }
40
41 ok $c = MyTestLog->new, 'Get log app object';
42 ok $log = $c->log, 'Get log object';
43 isa_ok $log,        'Catalyst::Log', 'It should be a Catalyst::Log object';
44 ok $log->is_warn,   'Warnings should be enabled';
45 ok $log->is_error,  'Errors should be enabled';
46 ok $log->is_fatal,  'Fatal errors should be enabled';
47 ok !$log->is_info,  'Info should be disabled';
48 ok !$log->is_debug, 'Debugging should be disabled';
49
50 TESTOWNLOGGER: {
51     package MyTestAppWithOwnLogger;
52     use base qw/Catalyst/;
53     use Test::MockObject;
54     my $log = Test::MockObject->new;
55     $log->set_false(qw/debug error fatal info warn/);
56     __PACKAGE__->log($log);
57     __PACKAGE__->setup('-Debug');
58 }
59
60 ok $c = MyTestAppWithOwnLogger->new, 'Get with own logger app object';
61 ok $c->debug, '$c->debug is true';