Debian Codegraph @

tests/phpunit/maintenance/FindClassesTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Maintenance;
4
5 use FindClasses;
6 use PHPUnit\Framework\ExpectationFailedException;
7
8 /**
9 * Mock for the input/output of FindClasses
10 *
11 * FindClasses internally tries to access stdin and stdout. We mock those aspects
12 * for testing.
13 */
14 class SemiMockedFindClasses extends FindClasses {
15
16 /**
17 * @var string|null Text to pass as stdin
18 */
19 private ?string $mockStdinText = null;
20
21 /**
22 * Data for the fake stdin
23 *
24 * @param string $stdin The string to be used instead of stdin
25 */
26 public function mockStdin( $stdin ) {
27 $this->mockStdinText = $stdin;
28 }
29
30 public function getStdin( $len = null ) {
31 if ( $len !== null ) {
32 throw new ExpectationFailedException( "Tried to get stdin with non null parameter" );
33 }
34
35 return fopen( 'data://text/plain,' . $this->mockStdinText, 'r' );
36 }
37 }
38
39 /**
40 * @covers \FindClasses
41 * @group Database
42 * @author Dreamy Jazz
43 */
44 class FindClassesTest extends MaintenanceBaseTestCase {
45
46 protected function getMaintenanceClass() {
47 return SemiMockedFindClasses::class;
48 }
49
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" );
54 }
55 }