Search code examples
phprspecphpspec

PHPSpec - checking that a method has been called with a class instance argument


I have the following test in RSpec:

it { is_expected.to respond_to(:dock).with(1).argument }

I need to replicate this test but using PHPSpec. My code is below:

function it_should_dock_a_bike()
{
    $bike = new \Bike();
    $this->dock($bike)->shouldReturnAnInstanceOf('Bike');
}

This code works, and it does fail when I exclude the $bike argument, but is there a better way to explicitly write the test similar to the example in RSpec?


Solution

  • $this->dock(Argument::any())->shouldReturnAnInstanceOf(Bike::class);
    

    is what you're looking for