3 namespace MediaWiki\Tests\Maintenance
;
6 use PHPUnit\Framework\ExpectationFailedException
;
9 * Mock for the input/output of FindClasses
11 * FindClasses internally tries to access stdin and stdout. We mock those aspects
14 class SemiMockedFindClasses
extends FindClasses
{
17 * @var string|null Text to pass as stdin
19 private ?
string $mockStdinText = null;
22 * Data for the fake stdin
24 * @param string $stdin The string to be used instead of stdin
26 public function mockStdin( $stdin ) {
27 $this->mockStdinText
= $stdin;
30 public function getStdin( $len = null ) {
31 if ( $len !== null ) {
32 throw new ExpectationFailedException( "Tried to get stdin with non null parameter" );
35 return fopen( 'data://text/plain,' . $this->mockStdinText
, 'r' );
40 * @covers \FindClasses
44 class FindClassesTest
extends MaintenanceBaseTestCase
{
46 protected function getMaintenanceClass() {
47 return SemiMockedFindClasses
::class;
50 public function testExecute() {
51 $this->maintenance
->mockStdin( "MediaWiki\Maintenance\Version\n" );
52 $this->maintenance
->execute();
53 $this->expectOutputString( MW_INSTALL_PATH
. "/maintenance/Version.php\n" );