jeudi 23 juin 2016

Checking Mockery arguments using Mockery::contains( )

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?

Aucun commentaire:

Enregistrer un commentaire