Actuellement, je suis en utilisant des chaînes de spécifie où mon test échoue, comme ceci:Comment obtenir le numéro d'un déterminé appelé à la méthode dans PHPUnit
Dans le premier appel à la méthode « XY », le premier paramètre :
Ainsi, vous voulez obtenir le numéro d'appel avec phpunit.
En bref, je veux un nombre cardinal au lieu de first, second, third ...
, mais étant donné pour PHPUnit (mieux)
public function testExample()
{
$test = $this;
$this->myClass
->expects($this->exactly(2))
->method('methodOne')
->withConsecutive(
[
$this->callback(function ($arg) use ($test) {
$part = 'In the first call to methodOne method, the first parameter: ';
$test->assertThat(
$arg,
$this->logicalAnd($this->equalTo('example1')),
$part . 'is not equal to "example1" '
);
return true;
}),
],
[
$this->callback(function ($arg) use ($test) {
$part = 'In the first call to methodOne method, the first parameter: ';
$test->assertThat(
$arg,
$this->logicalAnd($this->equalTo('example2')),
$part . 'is not equal to "example2"'
);
return true;
}),
]
)
->will($this->returnSelf());
}
Pouvez-vous partager le code de production? Peut-être qu'il y a une meilleure façon d'affirmer son comportement. – localheinz