Hello,<br><br>I have a model (MyApp/Models/Bar.pm) which retrieves data from the db using the generated schema files (in MyApp/Schema/Result/*.pm).<br><br>My plan is to mock the classes which are called when retrieving data from the database.<br>
<br>BEGIN {<br> my $resultset_mock = Test::MockObject->new();<br> $resultset_mock->fake_module('DBIx::Class::ResultSet' => ( 'count' => sub { 0 } ));<br><br> my $pin_attempt_mock = Test::MockObject->new();<br>
$pin_attempt_mock->fake_module('MyApp::Schema::Result::Foo' => ('search' => sub { bless $resultset_mock, 'DBIx::Class::ResultSet' }));<br>}<br><br><br>BEGIN { use_ok 'MyApp::Model::Bar' }<br>
<br>is (MyApp::Model::Bar->_get_failed_challenges('test', 'test'),<br> 0,<br> 'get failed challenges'<br> );<br><br>MyApp::Model::Bar->_get_failed_challenges contains calls to search and count (shown below) <br>
<br>my $result = $c->model('Foo')->search({...});<br>$result->count();<br><br>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.<br>
<br>"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"<br><br>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.<br><br>Any help would be appreciated!<br><br>Thanks,<br><br clear="all">-- Frank <br>