KelpX/Symbiosis/Test.pm

filter: Statementstmt 96.1% 25 / 26 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 33.3% 1 / 3 totaltotal 86.3% 38 / 44 SCAR 16.1
CC
5
Cov
91%
can
3.0
AUTOLOAD
3.0
__ANON__
1.1
CRAP 5.0
« Kelp/Module/Symbiosis/_Util.pm ↑ Summary Kelp/Module/Symbiosis/Base.pm »
1 package KelpX::Symbiosis::Test;
2 6 $KelpX::Symbiosis::Test::VERSION = '1.14';
3 6 ▶use Kelp::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Kelp::Test;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 0 ▶attr "-app" => sub { die "`app` parameter is required" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
7  
8 sub wrap
9 {
10 5 ▶ my ($class, %args) = @_;
Subroutine wrap: called CC=1 SCAR=0.0
Pod documented
11 5 my $self = $class->new(%args);
12 5 return Kelp::Test->new(app => $self);
13 }
14  
15 sub run
16 {
17 19 ▶ shift->app->run_all(@_);
Subroutine run: called CC=1 SCAR=0.0
Pod undocumented
18 }
19  
20 sub can
21 {
22 14 ▶ my ($self, $func) = @_;
Subroutine can: called CC=3 SCAR=11.0
Pod undocumented
23  
24 14 ▶ if (ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) 2 12 14
25 2 my $can = $self->app->can($func);
26 2 ▶ return $can if defined $can;
Branch: 1 branch
BranchTrueFalseTotal
if defined $can 2 0 2
27 }
28  
29 12 return $self->SUPER::can($func);
30 }
31  
32 sub AUTOLOAD
33 {
34 21 ▶ my ($self) = shift;
Subroutine AUTOLOAD: called CC=3 SCAR=11.0
35  
36 21 my $func = our $AUTOLOAD;
37 21 ▶ return if $func =~ /::DESTROY$/;
Branch: 1 branch
BranchTrueFalseTotal
if $func =~ /::DESTROY$/ 6 15 21
38 15 $func =~ s/.*:://;
39  
40 15 my $method = $self->app->can($func);
41 15 ▶ die "Kelp cannot $func" unless $method;
Branch: 1 branch
BranchTrueFalseTotal
unless $method 0 15 15
42 15 $method->($self->app, @_);
43 }
44  
45 6 1;
46 __END__
47  
48 =head1 NAME
49  
50 KelpX::Symbiosis::Test - Allow testing symbiotic environments using Kelp::Test
51  
52 =head1 SYNOPSIS
53  
54 # in test file
55 use KelpX::Symbiosis::Test;
56  
57 my $t = KelpX::Symbiosis::Test->wrap(app => $kelp_app);
58  
59 # continue testing using $t, just like Kelp::Test
60  
61 =head1 DESCRIPTION
62  
63 This module allows testing Kelp apps with Symbiosis using L<Kelp::Test>. The problem with I<Kelp::Test> is that it automatically runs I<run()> on the app without any way to configure this behavior. Symbiotic apps use I<run_all()> to run the whole environment, while I<run()> stays the same and only runs Kelp. This module replaces those two methods and autoloads the rest of the methods from Kelp instance.
64  
65 =head1 USAGE
66  
67 =head2 wrap
68  
69 I<new in 1.10>
70  
71 Instead of using I<Kelp::Test::new> use I<KelpX::Symbiosis::Test::wrap> with the same interface. Then you can create test cases not only for Kelp routes but also for the rest of Plack applications. The I<wrap> method will return a L<Kelp::Test> object, so refer to its documentation for more details.
72  
73 =head1 HOW DOES IT WORK?
74  
75 The main Kelp instance is wrapped in this module class and the resulting object is passed into Kelp::Test instead. I<KelpX::Symbiosis::Test> autoloads Kelp methods and wraps I<run_all> inside I<run>, which allows L<Kelp::Test> to use it.
76  
« Kelp/Module/Symbiosis/_Util.pm ↑ Summary Kelp/Module/Symbiosis/Base.pm »