0

I am writing a PHPspec test where want to test if a method was called with the correct argument (in the case an object).

I am doing something like this (pseudo code), inside my spec:

function it_some_test(MyService $myservice) {
    $object = new MyDomainObject();
    $object->setPropertyX("some value")

    $myservice->getSomething($object)->shouldBeCalled();

}

The object is just a DTO created inside my service. Its created exactly the same way in the original Service. Just the value of some properties change based on same logic. thats what I want to test.

The problem is my test is always failing because it says the $object is different from what it was excepting but they have exactly the same properties values.

How does PHPspec compares objects? If I pass Argument::any() instead it works but I need to test the object passed as a property with a specific value.

brpaz
  • 3,618
  • 9
  • 48
  • 75
  • checkout this answer that could help you as well: http://stackoverflow.com/questions/42307939/how-to-get-property-from-stub-function-argument However, if values are ALL the same, it should pass even if this not recommended to keep in the same class an object implementation and its usage – DonCallisto Feb 28 '17 at 17:52

1 Answers1

0

I found the issue. I was calling the method ->shouldBeCalled() before calling the real method under test. Change the order and it works now.

brpaz
  • 3,618
  • 9
  • 48
  • 75