updated test. ConstructorInjection tries to load files from disk, so, instead of...
André Walker [Sat, 30 Jul 2011 01:34:43 +0000 (22:34 -0300)]
t/aggregate/unit_core_component.t
t/lib/TestAppComponent.pm [new file with mode: 0644]
t/lib/TestAppComponent/C/Controller.pm [new file with mode: 0644]
t/lib/TestAppComponent/M/Model.pm [new file with mode: 0644]
t/lib/TestAppComponent/V/View.pm [new file with mode: 0644]

index 2875f0c..62785ea 100644 (file)
@@ -1,43 +1,33 @@
 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(MyApp->comp('C::Controller'), 'MyApp::C::Controller', 'Two-part return ok');
+is(ref TestAppComponent->comp('C::Controller'), 'TestAppComponent::C::Controller', 'Two-part return ok');
 
-is(MyApp->comp('Model'), 'MyApp::M::Model', 'Single part return ok');
+is(ref TestAppComponent->comp('Model'), 'TestAppComponent::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( [ 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') ], \@complist, 'no reulsts for regexp fallback');
+        is_deeply( [ TestAppComponent->comp('::M::Model') ], \@complist, 'no reulsts for regexp fallback');
         ok( $warnings, 'regexp fallback warnings' );
     }
 
@@ -45,14 +35,15 @@ is_deeply([ MyApp->comp('Foo') ], \@complist, 'Fallthrough return ok');
 
 # 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' );
 }
 
 
@@ -62,12 +53,12 @@ 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/);
diff --git a/t/lib/TestAppComponent.pm b/t/lib/TestAppComponent.pm
new file mode 100644 (file)
index 0000000..e6fb92b
--- /dev/null
@@ -0,0 +1,12 @@
+package TestAppComponent;
+use Moose;
+use Catalyst;
+extends q/Catalyst/;
+
+{
+    no warnings 'redefine';
+    local *Catalyst::Log::warn = sub {};
+    __PACKAGE__->setup;
+}
+
+1;
diff --git a/t/lib/TestAppComponent/C/Controller.pm b/t/lib/TestAppComponent/C/Controller.pm
new file mode 100644 (file)
index 0000000..4f48381
--- /dev/null
@@ -0,0 +1,5 @@
+package TestAppComponent::C::Controller;
+use Moose;
+BEGIN { extends 'Catalyst::Controller' }
+
+1;
diff --git a/t/lib/TestAppComponent/M/Model.pm b/t/lib/TestAppComponent/M/Model.pm
new file mode 100644 (file)
index 0000000..17f4dcd
--- /dev/null
@@ -0,0 +1,5 @@
+package TestAppComponent::M::Model;
+use Moose;
+extends 'Catalyst::Model';
+
+1;
diff --git a/t/lib/TestAppComponent/V/View.pm b/t/lib/TestAppComponent/V/View.pm
new file mode 100644 (file)
index 0000000..3d284e5
--- /dev/null
@@ -0,0 +1,5 @@
+package TestAppComponent::V::View;
+use Moose;
+extends 'Catalyst::View';
+
+1;