I occasionally need the list of method parameter matchers when setting assertions via mocks using with()
. A completely useless example:
$foo->expects($this->once()) ->method('setter') ->with($this->isType('string'));
I can see a few documented in the examples but the most conclusive list I’ve come across is from slide 11 of these Advanced PHPUnit Testing slides. So I am posting them here, if only for my own use:
$this->anything() $this->contains($value) $this->arrayHasKey($key) $this->equalTo($value, $delta, $maxDepth) $this->classHasAttribute($attribute) $this->greaterThan($value) $this->isInstanceOf($className) $this->isType($type) $this->matchesRegularExpression($pattern) $this->stringContains($string, $case)Tweet
comments
Thanks !
Thanks +!
Also you can use:
$this->logicalAnd();
$this->logicalOr();
$this->logicalNot();
$this->logicalXor();
Cheers
a full List is available in the source code itself:
https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/Assert.php