You only need to mock the members of the SOAP::Lite interface that you are actually using. Consider:
use strict; use warnings; use Test::MockObject; use Test::More; my $mockSOAP = Test::MockObject->new(); $mockSOAP->fake_module('SOAP::Lite', new => sub {SOAP_new ($mockSOAP, +@_)},); $mockSOAP->mock(soapversion => \&SOAP_soapversion); use_ok('SOAP::Lite'); my $client = SOAP::Lite->new(proxy => 'blah'); is($client->soapversion(), 1.2, 'Version ok'); eval {$client->soapversion(1.3)}; my $result = $@; is($result, "Can't set SOAP version to 1.3\n", 'Bad version rejected') +; done_testing(); sub SOAP_new { my ($mock, $class, %params) = @_; $params{version} ||= 1.2; $mock->{newParams} = \%params; $mock->{newClass} = $class; return $mock; } sub SOAP_soapversion { my ($self, $version) = @_; die "Can't set SOAP version to $version\n" if defined $version && $version != 1.2 && $version != 1.1; $self->{newParams}{version} = $version if defined $version; return $self->{newParams}{version}; }
Prints:
ok 1 - use SOAP::Lite; ok 2 - Version ok ok 3 - Bad version rejected 1..3
In reply to Re: Unit tests with MockObjects
by GrandFather
in thread Unit tests with MockObjects
by rovingeyes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |