16a5e24983adcd0bc9835d038be08ec87f894d0a
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_plugin.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 use lib 't/lib';
9
10 {
11
12     package Faux::Plugin;
13
14     sub new { bless { count => 1 }, shift }
15     sub count { shift->{count}++ }
16 }
17
18 my $warnings = 0;
19
20 use PluginTestApp;
21 my $logger = Class::MOP::Class->create_anon_class(
22     methods => {
23         error => sub {0},
24         debug => sub {0},
25         info => sub {0},
26         warn => sub {
27             if ($_[1] =~ /plugin method is deprecated/) {
28                $warnings++;
29                 return;
30             }
31             die "Caught unexpected warning: " . $_[1];
32         },
33     },
34 )->new_object;
35 PluginTestApp->log($logger);
36
37 use Catalyst::Test qw/PluginTestApp/;
38
39 ok( get("/compile_time_plugins"), "get ok" );
40 is( $warnings, 0, 'no warnings' );
41 # FIXME - Run time plugin support is insane, and should be removed
42 #         for Catalyst 5.9
43 ok( get("/run_time_plugins"),     "get ok" );
44
45 local $ENV{CATALYST_DEBUG} = 0;
46
47 is( $warnings, 1, '1 warning' );
48
49 use_ok 'TestApp';
50 my @expected = qw(
51   Catalyst::Plugin::Test::Errors
52   Catalyst::Plugin::Test::Headers
53   Catalyst::Plugin::Test::Inline
54   Catalyst::Plugin::Test::MangleDollarUnderScore
55   Catalyst::Plugin::Test::Plugin
56   TestApp::Plugin::AddDispatchTypes
57   TestApp::Plugin::FullyQualified
58 );
59
60 # Faux::Plugin is no longer reported
61 is_deeply [ TestApp->registered_plugins ], \@expected,
62   'registered_plugins() should only report the plugins for the current class';
63
64 done_testing;