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