PHPSpec saying mock object's method is not found

279 views
Skip to first unread message

James Higgins

unread,
Jul 15, 2013, 12:31:59 PM7/15/13
to phpsp...@googlegroups.com
Hello!

Been trawling the forums / google for an answer to this but can't see any, so would appreciate a pointer!

We have a Repository object, which has a Storage object and a Repository object passed in through the constructor. The method I need to test, saves a collection of entities in the following method:

public function saveCollection(Collection $currencies)
{
    $this->getStorage()->saveCollection($currencies);
    if (isset($this->repository)) {
        $this->getRepository()->saveCollection($currencies);
    }
}

For some reason, my test throws, "method Double\blahblah\Db\P51e421061b7b4::saveCollection()` not found.

function it_should_save_collections($collections, $db)
{
    $db->saveCollection()->willReturn(null);
    $this->setStorage($db);
    $this->saveCollection($collections)
           ->shouldReturn(null);
}

Tried pretty much every combination of willReturns and tweaks to get around it but no luck. Any suggestions? I'm testing $db->saveCollection separately and that's working perfectly fine.

Cheers, 

J





Luis Cordova

unread,
Jul 16, 2013, 12:36:32 AM7/16/13
to phpsp...@googlegroups.com
your double clearly does not have the save method because you need to stub this too


--
You received this message because you are subscribed to the Google Groups "PHPSpec - Behavior Driven Design (BDD) for PHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phpspec-dev...@googlegroups.com.
To post to this group, send email to phpsp...@googlegroups.com.
Visit this group at http://groups.google.com/group/phpspec-dev.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

James Higgins

unread,
Jul 16, 2013, 4:12:01 AM7/16/13
to phpsp...@googlegroups.com, cord...@gmail.com
Cheers Luis, I've tried stubbing it pretty much every manner I can think but it's not picking it up. The class it should be representing definitely has it but I can't see how to stub it. Any suggestions?

Luis Cordova

unread,
Jul 16, 2013, 5:12:44 AM7/16/13
to phpsp...@googlegroups.com
you removed the body below the email, i have 0 context to help

can you please gist this?

James Higgins

unread,
Jul 16, 2013, 5:21:10 AM7/16/13
to phpsp...@googlegroups.com, cord...@gmail.com

Konstantin Kudryashov

unread,
Jul 17, 2013, 4:08:55 AM7/17/13
to phpsp...@googlegroups.com
Prophecy explicitly tells you that class or interface "blahblah\Db" doesn't have "saveCollection()" method.
--
You received this message because you are subscribed to the Google Groups "PHPSpec - Behavior Driven Design (BDD) for PHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phpspec-dev...@googlegroups.com.
To post to this group, send email to phpsp...@googlegroups.com.
Visit this group at http://groups.google.com/group/phpspec-dev.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


--

---

Konstantin Kudryashov

--- PHP developer, BDD evangelist, Scrum master

a: http://about.me/everzet/bio

b: http://everzet.com

c: https://github.com/everzet


Reply all
Reply to author
Forward
0 new messages