use inlined module hiding in tests
[catagits/Catalyst-Runtime.git] / t / undef-params.t
1 use warnings;
2 use strict ;
3 use Test::More;
4 use HTTP::Request::Common;
5 use Plack::Test;
6
7 # If someone does $c->req->params(undef) you don't get a very good
8 # error message.  This is a test to see if the proposed change improves
9 # that.
10
11
12 {
13   package MyApp::Controller::Root;
14   $INC{'MyApp/Controller/Root.pm'} = __FILE__;
15
16   use base 'Catalyst::Controller';
17
18   sub test :Local {
19     my ($self, $c) = @_;
20     my $value = $c->req->param(undef);
21
22     $c->response->body("This is the body");
23   }
24
25   sub set_params :Local {
26     my ($self, $c) = @_;
27     $c->req->param(foo => 'a', 'b', 'c');
28     $c->res->body(join ',', $c->req->param('foo'));
29   }
30
31   package MyApp;
32   use Catalyst;
33
34   $SIG{__WARN__} = sub {
35     my $error = shift;
36     Test::More::like($error, qr[You called ->params with an undefined value])
37       unless MyApp->debug;
38   };
39
40   MyApp->setup;
41 }
42
43 ok my $psgi = MyApp->psgi_app, 'build psgi app';
44
45 test_psgi $psgi, sub {
46     my $cb = shift;
47
48     {
49       my $res = $cb->(GET "/root/test");
50       is $res->code, 200, 'OK';
51     }
52
53     {
54       my $res = $cb->(GET "/root/set_params");
55       is $res->code, 200, 'OK';
56       is $res->content, 'a,b,c';
57     }
58 };
59
60 done_testing;