X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Funit_core_plugin.t;h=cb48159fe20b92bd5be49bbe10dab0feb27896b0;hb=aa2e6d9e59b1373b13fe7c37725f3fab3b8a1e92;hp=46647fb0a774f7351efce4dd5c9f603608dd8ac2;hpb=836e1134dfc70e064464c366a44ebb6aabfa1648;p=catagits%2FCatalyst-Runtime.git diff --git a/t/unit_core_plugin.t b/t/unit_core_plugin.t index 46647fb..cb48159 100644 --- a/t/unit_core_plugin.t +++ b/t/unit_core_plugin.t @@ -2,8 +2,9 @@ use strict; use warnings; +use Test::MockObject::Extends; -use Test::More tests => 20; +use Test::More tests => 24; use lib 't/lib'; @@ -16,78 +17,40 @@ use lib 't/lib'; sub count { $count++ } } -{ - - package PluginTestApp; - use Test::More; - - use Catalyst qw( - Test::Plugin - +TestApp::Plugin::FullyQualified - ); - - sub compile_time_plugins : Local { - my ( $self, $c ) = @_; - - isa_ok $c, 'Catalyst::Plugin::Test::Plugin'; - isa_ok $c, 'TestApp::Plugin::FullyQualified'; - - can_ok $c, 'registered_plugins'; - $c->_test_plugins; - - $c->res->body("ok"); - } - - sub run_time_plugins : Local { - my ( $self, $c ) = @_; +my $warnings = 0; - $c->_test_plugins; - my $faux_plugin = 'Faux::Plugin'; - - # Trick perl into thinking the plugin is already loaded - $INC{'Faux/Plugin.pm'} = 1; - - __PACKAGE__->plugin( faux => $faux_plugin ); - - isa_ok $c, 'Catalyst::Plugin::Test::Plugin'; - isa_ok $c, 'TestApp::Plugin::FullyQualified'; - ok !$c->isa($faux_plugin), - '... and it should not inherit from the instant plugin'; - can_ok $c, 'faux'; - is $c->faux->count, 1, '... and it should behave correctly'; - is_deeply [ $c->registered_plugins ], - [ - qw/Catalyst::Plugin::Test::Plugin - Faux::Plugin - TestApp::Plugin::FullyQualified/ - ], - 'registered_plugins() should report all plugins'; - ok $c->registered_plugins('Faux::Plugin'), - '... and even the specific instant plugin'; - - $c->res->body("ok"); +use PluginTestApp; +my $logger = Test::MockObject::Extends->new(PluginTestApp->log); +$logger->mock('warn', sub { + if ($_[1] =~ /plugin method is deprecated/) { + $warnings++; + return; } - - sub _test_plugins { - my $c = shift; - is_deeply [ $c->registered_plugins ], - [ - qw/Catalyst::Plugin::Test::Plugin - TestApp::Plugin::FullyQualified/ - ], - '... and it should report the correct plugins'; - ok $c->registered_plugins('Catalyst::Plugin::Test::Plugin'), - '... or if we have a particular plugin'; - ok $c->registered_plugins('Test::Plugin'), - '... even if it is not fully qualified'; - ok !$c->registered_plugins('No::Such::Plugin'), - '... and it should return false if the plugin does not exist'; - } - - __PACKAGE__->setup; -} + die "Caught unexpected warning: " . $_[1]; +}); +#PluginTestApp->log($logger); use Catalyst::Test qw/PluginTestApp/; ok( get("/compile_time_plugins"), "get ok" ); +is( $warnings, 0, 'no warnings' ); +# FIXME - Run time plugin support is insane, and should be removed +# for Catalyst 5.9 ok( get("/run_time_plugins"), "get ok" ); + +is( $warnings, 1, '1 warning' ); + +use_ok 'TestApp'; +my @expected = qw( + Catalyst::Plugin::Test::Errors + Catalyst::Plugin::Test::Headers + Catalyst::Plugin::Test::Inline + Catalyst::Plugin::Test::MangleDollarUnderScore + Catalyst::Plugin::Test::Plugin + TestApp::Plugin::AddDispatchTypes + TestApp::Plugin::FullyQualified +); + +# Faux::Plugin is no longer reported +is_deeply [ TestApp->registered_plugins ], \@expected, + 'registered_plugins() should only report the plugins for the current class';