Fix small typo
[gitmo/MooseX-Params-Validate.git] / t / 004_custom_cache_key.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Fatal;
8 use Scalar::Util;
9
10 {
11     package Foo;
12     use Moose;
13     use MooseX::Params::Validate;
14
15     sub bar {
16         my ( $self, $args, $params ) = @_;
17         $params->{MX_PARAMS_VALIDATE_CACHE_KEY}
18             = Scalar::Util::refaddr($self);
19         return validated_hash( $args, %$params );
20     }
21 }
22
23 my $foo = Foo->new;
24 isa_ok( $foo, 'Foo' );
25
26 is(
27     exception {
28         $foo->bar( [ baz => 1 ], { baz => { isa => 'Int' } } );
29     },
30     undef,
31     '... successfully applied the parameter validation'
32 );
33
34 like(
35     exception {
36         $foo->bar( [ baz => [ 1, 2, 3 ] ], { baz => { isa => 'ArrayRef' } } );
37     },
38     qr/\QThe 'baz' parameter/,
39     '... successfully re-used the parameter validation for this instance'
40 );
41
42 my $foo2 = Foo->new;
43 isa_ok( $foo2, 'Foo' );
44
45 is(
46     exception {
47         $foo2->bar(
48             [ baz => [ 1, 2, 3 ] ],
49             { baz => { isa => 'ArrayRef' } }
50         );
51     },
52     undef,
53     '... successfully applied the parameter validation'
54 );
55
56 like(
57     exception {
58         $foo2->bar( [ baz => 1 ], { baz => { isa => 'Int' } } );
59     },
60     qr/\QThe 'baz' parameter/,
61     '... successfully re-used the parameter validation for this instance'
62 );
63
64 is(
65     exception {
66         $foo->bar( [ baz => 1 ], { baz => { isa => 'Int' } } );
67     },
68     undef,
69     '... successfully applied the parameter validation (just checking)'
70 );
71
72 done_testing();