stop using Moo as a test package
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_setup.t
1 use strict;
2 use warnings;
3 use Class::MOP;
4 use Catalyst::Runtime;
5
6 use Test::More tests => 29;
7
8 {
9     # Silence the log.
10     my $meta = Catalyst::Log->meta;
11     $meta->make_mutable;
12     $meta->remove_method('_send_to_log');
13     $meta->add_method('_send_to_log', sub {});
14 }
15
16 sub build_test_app_with_setup {
17     my ($name, @flags) = @_;
18     my $flags = '(' . join(', ', map { "'".$_."'" } @flags) . ')';
19     $flags = '' if $flags eq '()';
20     eval qq{
21         package $name;
22         use Catalyst $flags;
23         $name->setup;
24     };
25     die $@ if $@;
26     return $name;
27 }
28
29 local %ENV = %ENV;
30
31 # Remove all relevant env variables to avoid accidental fail
32 foreach my $name (grep { /^(CATALYST|TESTAPP)/ } keys %ENV) {
33     delete $ENV{$name};
34 }
35
36 {
37     my $app = build_test_app_with_setup('TestAppMyTestDebug', '-Debug');
38
39     ok my $c = $app->new, 'Get debug app object';
40     ok my $log = $c->log, 'Get log object';
41     isa_ok $log, 'Catalyst::Log', 'It should be a Catalyst::Log object';
42     ok $log->is_warn, 'Warnings should be enabled';
43     ok $log->is_error, 'Errors should be enabled';
44     ok $log->is_fatal, 'Fatal errors should be enabled';
45     ok $log->is_info, 'Info should be enabled';
46     ok $log->is_debug, 'Debugging should be enabled';
47     ok $app->debug, 'debug method should return true';
48 }
49
50 {
51     my $app = build_test_app_with_setup('TestAppMyTestLogParam', '-Log=warn,error,fatal');
52
53     ok my $c = $app->new, 'Get log app object';
54     ok my $log = $c->log, 'Get log object';
55     isa_ok $log, 'Catalyst::Log', 'It should be a Catalyst::Log object';
56     ok $log->is_warn, 'Warnings should be enabled';
57     ok $log->is_error, 'Errors should be enabled';
58     ok $log->is_fatal, 'Fatal errors should be enabled';
59     ok !$log->is_info, 'Info should be disabled';
60     ok !$log->is_debug, 'Debugging should be disabled';
61     ok !$c->debug, 'Catalyst debugging is off';
62 }
63 {
64     my $app = build_test_app_with_setup('TestAppMyTestNoParams');
65
66     ok my $c = $app->new, 'Get log app object';
67     ok my $log = $c->log, 'Get log object';
68     isa_ok $log, 'Catalyst::Log', 'It should be a Catalyst::Log object';
69     ok $log->is_warn, 'Warnings should be enabled';
70     ok $log->is_error, 'Errors should be enabled';
71     ok $log->is_fatal, 'Fatal errors should be enabled';
72     ok $log->is_info, 'Info should be enabled';
73     ok $log->is_debug, 'Debugging should be enabled';
74     ok !$c->debug, 'Catalyst debugging turned off';
75 }
76 my $log_meta = Class::MOP::Class->create_anon_class(
77     methods => { map { $_ => sub { 0 } } qw/debug error fatal info warn/ },
78 );
79 {
80     package TestAppWithOwnLogger;
81     use base qw/Catalyst/;
82     __PACKAGE__->log($log_meta->new_object);
83     __PACKAGE__->setup('-Debug');
84 }
85
86 ok my $c = TestAppWithOwnLogger->new, 'Get with own logger app object';
87 ok $c->debug, '$c->debug is true';
88