wiki.techinc.nl/tests/phpunit/MediaWikiTestCaseTrait.php
mainframe98 4941f2de91 Permit destructors in MediaWikiTestCaseTrait::createNoOpMock
709773ab57 introduced this method, but its implementation
does not permit calls to __destruct. PHP documentation on destructors
says that they'll be called unconditionally, which makes using the
mock created with this method unusable for classes that implement
__destruct.

Bug: T231656
Change-Id: Icb4f978c78e726401d75627128c9c76f6f9afc87
2019-08-30 15:27:38 +00:00

32 lines
959 B
PHP

<?php
/**
* For code common to both MediaWikiUnitTestCase and MediaWikiIntegrationTestCase.
*/
trait MediaWikiTestCaseTrait {
/**
* Returns a PHPUnit constraint that matches anything other than a fixed set of values. This can
* be used to whitelist values, e.g.
* $mock->expects( $this->never() )->method( $this->anythingBut( 'foo', 'bar' ) );
* which will throw if any unexpected method is called.
*
* @param mixed ...$values Values that are not matched
*/
protected function anythingBut( ...$values ) {
return $this->logicalNot( $this->logicalOr(
...array_map( [ $this, 'matches' ], $values )
) );
}
/**
* Return a PHPUnit mock that is expected to never have any methods called on it.
*
* @param string $type
* @return object
*/
protected function createNoOpMock( $type ) {
$mock = $this->createMock( $type );
$mock->expects( $this->never() )->method( $this->anythingBut( '__destruct' ) );
return $mock;
}
}