I use a dataProvider and need a variable numbers of executed queries that i can use to populate my provider, i want to provide an array of the queries that should be executed.
The problem with withConsecutive
is that it takes a variable number of arrays, each one an array of arguments.
I solved it using the follwing code, this feels "hacky" but is working :
$withConsecutiveArgs = [
[$this->equalTo($title_query)],
[$this->equalTo($desc_query)],
...,
N queries
];
$withConsecutiveReturns = [
$title_stmt,
$desc_stmt,
...,
N returns
];
$methodMock = $pdo->expects($this->exactly(count($args))->method('prepare');
$methodMock->getMatcher()->parametersMatcher = new \PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters($withConsecutiveArgs);
$methodMock->will(new \PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls($withConsecutiveReturns));
$title_stmt = $pdo->prepare($title_query);
$desc_stmt = $pdo->prepare($desc_query);
...
$N_s_stmt = $pdo->prepare($N_s_query);
I hope it evolves correctly with future versions of PhpUnit (which is unsure, since i rely on internals of the lib, but that's the whole point of doing unit test, i may have to refactor it but production will not suffer from that)