Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4117105
MaintenanceRunnerTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
MaintenanceRunnerTest.php
View Options
<?php
use
MediaWiki\Extension\FakeExtension\Maintenance\FakeScript
;
use
MediaWiki\Maintenance\MaintenanceRunner
;
use
MediaWiki\Maintenance\Version
;
use
PHPUnit\Framework\TestCase
;
/**
* @covers \MediaWiki\Maintenance\MaintenanceRunner
*/
class
MaintenanceRunnerTest
extends
TestCase
{
public
const
FIXTURE_DIRECTORY
=
MW_INSTALL_PATH
.
'/tests/phpunit/data/MaintenanceRunner'
;
/** @var string */
private
$oldWorkDir
;
/**
* @before
*/
public
function
workDirSetUp
()
{
// Needed for testing the resolution of paths relative to CWD
$this
->
oldWorkDir
=
getcwd
();
chdir
(
self
::
FIXTURE_DIRECTORY
);
}
/**
* @after
*/
public
function
workDirTearDown
()
{
chdir
(
$this
->
oldWorkDir
);
}
public
static
function
provideFindScriptClass
()
{
// NOTE: We must use a different class for each test case,
// otherwise we may trigger a "cannot re-declare class" error.
yield
'plain name'
=>
[
'fakeScript'
,
EditCLI
::
class
];
yield
'name with suffix'
=>
[
'fakeScript.php'
,
EditCLI
::
class
];
yield
'name with path but no suffix'
=>
[
'storage/fakeScript'
,
DumpRev
::
class
];
yield
'name with path and suffix'
=>
[
'storage/fakeScript.php'
,
DumpRev
::
class
];
yield
'relative path with "./"'
=>
[
'./maintenance/storage/fakeScript.php'
,
DumpRev
::
class
];
$dir
=
basename
(
self
::
FIXTURE_DIRECTORY
);
yield
'relative path with "../"'
=>
[
"../$dir/maintenance/fakeScriptThatReturnsName.php"
,
CleanupImages
::
class
];
yield
'absolute path'
=>
[
self
::
FIXTURE_DIRECTORY
.
'/maintenance/fakeScript.php'
,
EditCLI
::
class
];
yield
'class name'
=>
[
'MediaWiki
\M
aintenance
\V
ersion'
,
Version
::
class
];
yield
'extension script path, using prefix'
=>
[
'FakeExtension:fakeScript.php'
,
FakeScript
::
class
];
// NOTE: assumes the class has been loaded by the previous test case!
yield
'extension class, using prefix'
=>
[
'FakeExtension:FakeScript'
,
FakeScript
::
class
];
yield
'extension class'
=>
[
'MediaWiki
\E
xtension
\F
akeExtension
\M
aintenance
\F
akeScript'
,
FakeScript
::
class
];
yield
'extension class, using dots'
=>
[
'MediaWiki.Extension.FakeExtension.Maintenance.FakeScript'
,
FakeScript
::
class
];
}
private
function
newRunner
():
MaintenanceRunner
{
return
new
class
()
extends
MaintenanceRunner
{
public
function
getScriptClass
():
string
{
return
parent
::
getScriptClass
();
}
public
function
findScriptClass
(
string
$script
):
string
{
return
parent
::
findScriptClass
(
$script
);
}
public
function
preloadScriptFile
(
string
$script
):
void
{
parent
::
preloadScriptFile
(
$script
);
}
protected
function
fatalError
(
$msg
,
$exitCode
=
1
)
{
$this
->
error
(
$msg
);
throw
new
UnexpectedValueException
(
$msg
);
}
protected
function
error
(
string
$msg
)
{
echo
$msg
;
}
protected
function
getMwInstallPath
():
string
{
// Fake the install path as the current directory, so that the fake maintenance scripts are found
// when providing a php file name in the tests.
return
MaintenanceRunnerTest
::
FIXTURE_DIRECTORY
;
}
protected
function
getExtensionInfo
(
string
$extName
):
?
array
{
return
[
'namespace'
=>
"MediaWiki
\\
Extension
\\
$extName"
,
'path'
=>
MaintenanceRunnerTest
::
FIXTURE_DIRECTORY
.
'/FakeExtension/extension.json'
,
];
}
};
}
/**
* @dataProvider provideFindScriptClass
*/
public
function
testFindScriptClass
(
$script
,
$expected
)
{
$runner
=
$this
->
newRunner
();
$class
=
$runner
->
findScriptClass
(
$script
);
if
(
str_starts_with
(
$class
,
'
\\
'
)
)
{
$class
=
substr
(
$class
,
1
);
}
$this
->
assertSame
(
$expected
,
$class
);
}
public
static
function
providePreloadScriptFile
()
{
// NOTE: We must use a different class for each test case,
// otherwise we may trigger a "cannot re-declare class" error.
yield
'plain name'
=>
[
'fakeScript'
,
EditCLI
::
class
];
yield
'name with suffix'
=>
[
'fakeScriptThatReturnsName.php'
,
CleanupImages
::
class
];
yield
'class name'
=>
[
'FindOrphanedFiles'
,
FindOrphanedFiles
::
class
];
}
/**
* @dataProvider providePreloadScriptFile
*/
public
function
testPreloadScriptFile
(
$script
,
$expected
)
{
$runner
=
$this
->
newRunner
();
$runner
->
preloadScriptFile
(
$script
);
$class
=
$runner
->
getScriptClass
();
if
(
str_starts_with
(
$class
,
'
\\
'
)
)
{
$class
=
substr
(
$class
,
1
);
}
$this
->
assertSame
(
$expected
,
$class
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 19, 02:01 (2 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
57/f1/4e9b5aa19b33f3f3c46d4fd68e96
Default Alt Text
MaintenanceRunnerTest.php (4 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment