X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Faggregate%2Funit_core_component.t;h=1e63375eb5629138c7aa96ec27ea650a7bc0c70a;hb=20ceb68574fa36b43bd1d3a5b209aece7f191be7;hp=69ac6c0153a268d8219bbaa4b97db1680bc0820c;hpb=38a55e0cf0b70133b1a8369c04e3bc0ee444c4b7;p=catagits%2FCatalyst-Runtime.git diff --git a/t/aggregate/unit_core_component.t b/t/aggregate/unit_core_component.t index 69ac6c0..1e63375 100644 --- a/t/aggregate/unit_core_component.t +++ b/t/aggregate/unit_core_component.t @@ -1,72 +1,49 @@ -use Test::More tests => 22; +use Test::More; use strict; use warnings; +use FindBin; +use lib "$FindBin::Bin/../lib"; +use TestAppComponent; -use_ok('Catalyst'); +my @complist = map { "TestAppComponent::$_"; } qw/C::Controller M::Model V::View/; -my @complist = map { "MyApp::$_"; } qw/C::Controller M::Model V::View/; +is(ref TestAppComponent->comp('TestAppComponent::V::View'), 'TestAppComponent::V::View', 'Explicit return ok'); -{ - package MyApp; - - use base qw/Catalyst/; - - __PACKAGE__->components({ map { ($_, $_) } @complist }); - - # this is so $c->log->warn will work - __PACKAGE__->setup_log; -} - -is(MyApp->comp('MyApp::V::View'), 'MyApp::V::View', 'Explicit return ok'); +is(ref TestAppComponent->comp('C::Controller'), 'TestAppComponent::C::Controller', 'Two-part return ok'); -is(MyApp->comp('C::Controller'), 'MyApp::C::Controller', 'Two-part return ok'); +is(ref TestAppComponent->comp('Model'), 'TestAppComponent::M::Model', 'Single part return ok'); -is(MyApp->comp('Model'), 'MyApp::M::Model', 'Single part return ok'); - -is_deeply([ MyApp->comp() ], \@complist, 'Empty return ok'); +is_deeply([ TestAppComponent->comp() ], \@complist, 'Empty return ok'); # Is this desired behaviour? -is_deeply([ MyApp->comp('Foo') ], \@complist, 'Fallthrough return ok'); +is_deeply([ TestAppComponent->comp('Foo') ], \@complist, 'Fallthrough return ok'); # regexp behavior { - is_deeply( [ MyApp->comp( qr{Model} ) ], [ 'MyApp::M::Model'], 'regexp ok' ); - is_deeply( [ MyApp->comp('MyApp::V::View$') ], [ 'MyApp::V::View' ], 'Explicit return ok'); - is_deeply( [ MyApp->comp('MyApp::C::Controller$') ], [ 'MyApp::C::Controller' ], 'Explicit return ok'); - is_deeply( [ MyApp->comp('MyApp::M::Model$') ], [ 'MyApp::M::Model' ], 'Explicit return ok'); - - # a couple other varieties for regexp fallback - is_deeply( [ MyApp->comp('M::Model') ], [ 'MyApp::M::Model' ], 'Explicit return ok'); + is_deeply( [ map { ref $_ } TestAppComponent->comp( qr{Model} ) ], [ 'TestAppComponent::M::Model' ], 'regexp ok' ); { my $warnings = 0; no warnings 'redefine'; local *Catalyst::Log::warn = sub { $warnings++ }; - is_deeply( [ MyApp->comp('::M::Model') ], [ 'MyApp::M::Model' ], 'Explicit return ok'); - ok( $warnings, 'regexp fallback warnings' ); - - $warnings = 0; - is_deeply( [ MyApp->comp('Mode') ], [ 'MyApp::M::Model' ], 'Explicit return ok'); + is_deeply( [ TestAppComponent->comp('::M::Model$') ], \@complist, 'no results for regexp fallback'); ok( $warnings, 'regexp fallback warnings' ); - - $warnings = 0; - is(MyApp->comp('::M::'), 'MyApp::M::Model', 'Regex return ok'); - ok( $warnings, 'regexp fallback for comp() warns' ); } } # multiple returns { - my @expected = sort qw( MyApp::C::Controller MyApp::M::Model ); - my @got = sort MyApp->comp( qr{::[MC]::} ); + # already sorted + my @expected = qw( TestAppComponent::C::Controller TestAppComponent::M::Model ); + my @got = map { ref $_ } sort TestAppComponent->comp( qr{::[MC]::} ); is_deeply( \@got, \@expected, 'multiple results from regexp ok' ); } # failed search { - is_deeply( scalar MyApp->comp( qr{DNE} ), 0, 'no results for failed search' ); + is_deeply( scalar TestAppComponent->comp( qr{DNE} ), 0, 'no results for failed search' ); } @@ -76,18 +53,16 @@ is_deeply([ MyApp->comp('Foo') ], \@complist, 'Fallthrough return ok'); { no warnings 'once'; - *MyApp::M::Model::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args}; + *TestAppComponent::M::Model::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args}; } - my $c = bless {}, 'MyApp'; + my $c = bless {}, 'TestAppComponent'; - $c->component('MyApp::M::Model', qw/foo bar/); + $c->component('TestAppComponent::M::Model', qw/foo bar/); is_deeply($args, [qw/foo bar/], 'args passed to ACCEPT_CONTEXT ok'); $c->component('M::Model', qw/foo2 bar2/); is_deeply($args, [qw/foo2 bar2/], 'args passed to ACCEPT_CONTEXT ok'); - - $c->component('Mode', qw/foo3 bar3/); - is_deeply($args, [qw/foo3 bar3/], 'args passed to ACCEPT_CONTEXT ok'); } +done_testing;