Hello,
I have a model (MyApp/Models/Bar.pm) which retrieves data from the db using
the generated schema files (in MyApp/Schema/Result/*.pm).
My plan is to mock the classes which are called when retrieving data from
the database.
BEGIN {
my $resultset_mock = Test::MockObject->new();
$resultset_mock->fake_module('DBIx::Class::ResultSet' => ( 'count' =>
sub { 0 } ));
my $pin_attempt_mock = Test::MockObject->new();
$pin_attempt_mock->fake_module('MyApp::Schema::Result::Foo' =>
('search' => sub { bless $resultset_mock, 'DBIx::Class::ResultSet' }));
}
BEGIN { use_ok 'MyApp::Model::Bar' }
is (MyApp::Model::Bar->_get_failed_challenges('test', 'test'),
0,
'get failed challenges'
);
MyApp::Model::Bar->_get_failed_challenges contains calls to search and count
(shown below)
my $result = $c->model('Foo')->search({...});
$result->count();
If I call MyApp::Schema::Result::Foo->search()->count() the mock returns 0
(and other values that I tested). However when I attempt to use test the Bar
model the following error is returned.
"You must pass a package name and it cannot be blessed at
/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/Class/MOP/Class.pm
line 41"
Also if I follow the stack trace down into the MyApp files, it points to the
line in MyApp::Model::Bar->_get_failed_challenges which calls search.
Any help would be appreciated!
Thanks,
-- Frank
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/