0
votes

I am using Mockery to test a class that creates calendar events. It passes timestamps of the start and end date to my EventRepository's create() method. There is other data included as arguments, but I only care that the timestamps are correct for this test.

This code works fine for testing the creation of one event:

$this->repo->shouldReceive('create')->once()
           ->with(Mockery::contains(1466460000, 1466467200));

However when I extend the Mock to the create() method being called twice, it fails.

$this->repo->shouldReceive('create')->twice()
           ->with(Mockery::contains(1466460000, 1466467200),
                 Mockery::contains(1466632800, 1466640000));

Doesn't Mockery use the syntax ->with(args1, args2) for specifying the arguments for multiple calls to the same function?

1

1 Answers

1
votes

The syntax with the multiple arguments are used when the method under test has multiple arguments.

For your use case you'll need to do as follows:

$this->repo->shouldReceive('create')->once()
          ->with(Mockery::contains(1466460000, 1466467200));
$this->repo->shouldReceive('create')->once()
          ->with(Mockery::contains(1466632800, 1466640000));