X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Funit_core_component_loading.t;h=1944ab6e63b266e9009948e4d17aeeff10d3c598;hb=f4c8c6d4387499e547c43c6e9deaecaaa50ba982;hp=d27b9b7078dd20b65d1514c520b38ac05782c809;hpb=f27f2c6dee65b9f6f18f2ff90ab337e97a585fed;p=catagits%2FCatalyst-Runtime.git diff --git a/t/unit_core_component_loading.t b/t/unit_core_component_loading.t index d27b9b7..1944ab6 100644 --- a/t/unit_core_component_loading.t +++ b/t/unit_core_component_loading.t @@ -1,7 +1,8 @@ # 2 initial tests, and 6 per component in the loop below # (do not forget to update the number of components in test 3 as well) # 5 extra tests for the loading options -use Test::More tests => 2 + 6 * 24 + 5; +# One test for components in inner packages +use Test::More tests => 2 + 6 * 24 + 8 + 1; use strict; use warnings; @@ -9,8 +10,6 @@ use warnings; use File::Spec; use File::Path; -use Test::MockObject; - my $libdir = 'test_trash'; unshift(@INC, $libdir); @@ -85,15 +84,7 @@ foreach my $component (@components) { } my $shut_up_deprecated_warnings = q{ - use Test::MockObject; - my $old_logger = __PACKAGE__->log; - my $logger = Test::MockObject->new; - $logger->mock('warn', sub { - my $self = shift; - return if $_[0] =~ /deprecated/; - $old_logger->warn(@_); - }); - __PACKAGE__->log($logger); + __PACKAGE__->log(Catalyst::Log->new('fatal')); }; eval "package $appclass; use Catalyst; $shut_up_deprecated_warnings __PACKAGE__->setup"; @@ -184,6 +175,9 @@ sub COMPONENT { my \$self = shift->next::method(\@_); no strict 'refs'; *{\__PACKAGE__ . "::whoami"} = sub { return \__PACKAGE__; }; + *${appclass}::Model::TopLevel::GENERATED::ACCEPT_CONTEXT = sub { + return bless {}, 'FooBarBazQuux'; + }; \$self; } @@ -199,8 +193,10 @@ write_component_file([$libdir, $appclass, 'Model', 'TopLevel'], 'Nested', <next::method(\@_); } +sub COMPONENT { \$called++;return shift->next::method(\@_); } +sub called { return \$called }; 1; EOF @@ -208,5 +204,23 @@ EOF eval "package $appclass; use Catalyst; __PACKAGE__->setup"; is($@, '', "Didn't load component twice"); +is($appclass->model('TopLevel::Nested')->called,1, 'COMPONENT called once'); + +ok($appclass->model('TopLevel::Generated'), 'Have generated model'); +is(ref($appclass->model('TopLevel::Generated')), 'FooBarBazQuux', + 'ACCEPT_CONTEXT in generated inner package fired as expected'); + +$appclass = "InnerComponent"; + +{ + package InnerComponent::Controller::Test; + use base 'Catalyst::Controller'; +} + +$INC{'InnerComponent/Controller/Test.pm'} = 1; + +eval "package $appclass; use Catalyst; __PACKAGE__->setup"; + +isa_ok($appclass->controller('Test'), 'Catalyst::Controller'); rmtree($libdir);