mediawiki-extensions-Echo/tests/phpunit/mapper/EchoExecuteFirstArgumentStub.php
Daimona Eaytoy c19c88567b Hack: back-compat for PHPUnit's Stub interface
Until PHPUnit7, the Stub interface came from phpunit-mock-object, and it
was at PHPUnit\Framework\MockObject\Stub. Then, phpunit-mock-object was
merged into PHPUnit, and:
 - The interface above was moved to PHPUnit\Framework\MockObject\Stub\Stub
 - The FQSEN above started pointing at a completely different interface
 
This is a temporary hack to allow upgrading to PHPUnit 8, and MUST be
removed as soon as the upgrade is complete.

The :string typehint is also necessary in PHPUnit8, and it will work
with PHPUnit 6 as well.

Bug: T192167
Change-Id: I07cebd07088bced5c5ddc62936f0098dfa39e151
2019-11-18 16:58:18 +00:00

34 lines
987 B
PHP

<?php
// @codingStandardsIgnoreStart
use PHPUnit\Framework\MockObject\Invocation;
use PHPUnit\Framework\MockObject\Invocation\StaticInvocation;
if ( !interface_exists( PHPUnit\Framework\MockObject\Stub\Stub::class ) ) {
// PHPUnit < 8
interface StubCompatTemp extends PHPUnit\Framework\MockObject\Stub {
}
} else {
// PHPUnit 8+
interface StubCompatTemp extends PHPUnit\Framework\MockObject\Stub\Stub {
}
}
class EchoExecuteFirstArgumentStub implements StubCompatTemp {
public function invoke( Invocation $invocation ) {
if ( !$invocation instanceof StaticInvocation ) {
throw new PHPUnit\Framework\Exception( 'wrong invocation type' );
}
if ( !$invocation->arguments ) {
throw new PHPUnit\Framework\Exception( 'Method call must have an argument' );
}
return call_user_func( reset( $invocation->arguments ) );
}
public function toString() : string {
return 'return result of call_user_func on first invocation argument';
}
}
// @codingStandardsIgnoreEnd