The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!perl

# test basic usage, no callbacks, in record mode

use strict;
use warnings;

use Test::More;

BEGIN {
    $ENV{LWP_UA_MOCK}      = 'playback';
    $ENV{LWP_UA_MOCK_FILE} = 'basic.mockdata';

    # prevent failures if tests run in parallel
    plan skip_all => 'basic.mockdata missing' unless -e 'basic.mockdata';
}

use LWP;
use LWP::UserAgent::Mockable;

my $ua = LWP::UserAgent->new;
is( ref $ua, 'LWP::UserAgent', 'mocked LWP::UA is still a LWP::UA' );

$ua->env_proxy;

my $get = $ua->get( "http://www.google.com" );
is( ref $get, 'HTTP::Response', 'and responses from requests are as per LWP::UA' );
ok( defined $get->code, "...which respond to LWP methods in an expected manner" );

my @methods = qw(
    code
    protocol
    as_string
);

foreach my $method ( @methods ) {
    ok ( defined $get->$method, "$method method returns expected value" );
}

# not doing much with this, just here so that can ensure that multiple
# requests work, and that can support methods other than get.
my $post = $ua->post( "http://www.google.com" );
is( ref $post, "HTTP::Response", 'post returns an HTTP::Response object' );

END {
    LWP::UserAgent::Mockable->finished;
}

done_testing();