Convert to Test::Fatal and tidy resulting code
[gitmo/MooseX-Params-Validate.git] / t / 004_custom_cache_key.t
CommitLineData
d9d1529d 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
d7a80104 6use Test::More;
37088308 7use Test::Fatal;
d9d1529d 8use 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
23my $foo = Foo->new;
24isa_ok( $foo, 'Foo' );
25
37088308 26is(
27 exception {
28 $foo->bar( [ baz => 1 ], { baz => { isa => 'Int' } } );
29 },
30 undef,
31 '... successfully applied the parameter validation'
32);
d9d1529d 33
37088308 34like(
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);
d9d1529d 41
42my $foo2 = Foo->new;
43isa_ok( $foo2, 'Foo' );
44
37088308 45is(
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);
d9d1529d 55
37088308 56like(
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);
d9d1529d 63
37088308 64is(
65 exception {
66 $foo->bar( [ baz => 1 ], { baz => { isa => 'Int' } } );
67 },
68 undef,
69 '... successfully applied the parameter validation (just checking)'
70);
d9d1529d 71
d7a80104 72done_testing();