vendredi 5 juin 2015

phpunit with mockery - how to test a mocked object is constructed with proper arguments

So I'm writing tests for a php api consumer library. In one of the main libraries main functions I have:

public function __call($name, $args) {
    return new Schema($name, $this);
}

In my test I'm using mockery and doing something like:

$schemaMock = m::mock('overload:Mynamespace\Schema');

this is properly overloading my Schema class with a mock. So later when I do:

$myclass->movies()

It should call the __call method, thus calling the mocked Schema class. This all seems good so far, but I would like to assert that the $schemaMock is being constructed with the name of the function, in this case movies as well as the instance of the class being passed in. What I've tried is:

$schemaMock->shouldReceive('__construct')->with('movies');

However my tests pass regardless of what the "with" function argument states. IE I can change movies to foobar and tests still pass. I'm sure I'm missing something simple about how to run these assertions. Thanks for any help!

Aucun commentaire:

Enregistrer un commentaire