2
votes

I'm using Mockery to define an expectation that a function on my mock should be called with an object as its argument. I am declaring the expected object in my test. The problem is the object in the test isn't the same object by reference as the object in my code - is there way to assert the equality of the two objects rather than the exact reference?

Test Fragment

$resource = new Resource("Test");

$this->aThing
   ->shouldReceive('call')
   ->with($resource)
   ->andReturn(true)
   ->once();

Code Fragment

public function respondWithString()
{
    // assume $this->aThing is the injected mock

    $resource = new Resource("Test");
    $response = $this->aThing->call($resource);
    return $response;
}
1

1 Answers

0
votes

This should work:

$resource = new Resource("Test");

$this->aThing
   ->shouldReceive('call')
   ->with(Mockery::mustBe($resource))
   ->andReturn(true)
   ->once();