Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPUnit prophesize a method without exact arguments

I'm mocking a UserRepository class using prophecy to ensure that when a POST request to /user is sent, that the create() method on UserRepository is fired.

$repository = $this->prophesize(UserRepository::class);

$repository->create()->shouldBeCalled()

The only problem is that the create() method sends Request data as an argument to the repository for some serious tweaking of the inputs before doing anything. How do I mock the create() call without telling prophecy what the arguments will be?

Or is this just really bad practice on my end and the Request data should never be passed to the repository?

like image 989
dargue3 Avatar asked Jun 22 '16 21:06

dargue3


2 Answers

use Prophecy\Argument;

$repository->create(Argument::cetera())->shouldBeCalled()

any() matches any single value where cetera matches all values to the rest of the signature.

like image 112
chx Avatar answered Nov 03 '22 20:11

chx


use Prophecy\Argument;

$repository->create(Argument::any())->shouldBeCalled()
like image 21
akond Avatar answered Nov 03 '22 19:11

akond