1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#!perl
use strict;
use warnings;
use Test::More tests => 6;
use Test::Fatal;
{
package MetaCPAN::Client::FakeEntityEmpty;
use Moo;
with 'MetaCPAN::Client::Role::Entity';
sub BUILDARGS {
my ( $class, %args ) = @_;
return \%args;
}
}
{
package MetaCPAN::Client::FakeEntityFull;
use Moo;
with 'MetaCPAN::Client::Role::Entity';
sub _known_fields {
+{
scalar => ['this'],
arrayref => [],
hashref => [],
}
}
}
ok(
exception { MetaCPAN::Client::FakeEntityEmpty->new },
'data is missing, causing exception',
);
is(
exception { MetaCPAN::Client::FakeEntityEmpty->new( data => {} ) },
undef,
'data available, not causing exception',
);
like(
exception { MetaCPAN::Client::FakeEntityEmpty->new_from_request( {} ) },
qr/.*Can't locate.*_known_fields/,
'Subroutine _known_fields missing',
);
is(
exception { MetaCPAN::Client::FakeEntityFull->new( data => {} ) },
undef,
'data available, not causing exception',
);
my $fe = MetaCPAN::Client::FakeEntityFull->new_from_request(
{ that => 'this', this => 'that' }
);
isa_ok( $fe, 'MetaCPAN::Client::FakeEntityFull' );
is_deeply( $fe->{'data'}, { this => 'that' }, 'Correct data' );
|