Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F2750609
StructureTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
StructureTest.php
View Options
<?php
use
SebastianBergmann\FileIterator\Facade
;
/**
* The tests here verify the structure of the code. This is for outright bugs,
* not just style issues.
* @coversNothing
*/
class
StructureTest
extends
\PHPUnit\Framework\TestCase
{
/**
* Verify all files that appear to be tests have file names ending in
* Test. If the file names do not end in Test, they will not be run.
* @group medium
*/
public
function
testUnitTestFileNamesEndWithTest
()
{
// realpath() also normalizes directory separator on windows for prefix compares
$rootPath
=
realpath
(
__DIR__
.
'/..'
);
$suitesPath
=
realpath
(
__DIR__
.
'/../suites/'
);
$testClassRegex
=
'/^(final )?class .* extends [
\S
]*(TestCase|TestBase)
\\
b/m'
;
$results
=
$this
->
recurseFiles
(
$rootPath
);
$results
=
array_filter
(
$results
,
static
function
(
$filename
)
use
(
$testClassRegex
,
$suitesPath
)
{
// Remove testUnitTestFileNamesEndWithTest false positives
if
(
str_starts_with
(
$filename
,
$suitesPath
)
||
str_ends_with
(
$filename
,
'Test.php'
)
)
{
return
false
;
}
$contents
=
file_get_contents
(
$filename
);
return
preg_match
(
$testClassRegex
,
$contents
);
}
);
$strip
=
strlen
(
$rootPath
)
+
1
;
foreach
(
$results
as
$k
=>
$v
)
{
$results
[
$k
]
=
substr
(
$v
,
$strip
);
}
// Normalize indexes to make failure output less confusing
$results
=
array_values
(
$results
);
$this
->
assertEquals
(
[],
$results
,
"Unit test file in $rootPath must end with Test."
);
}
private
function
recurseFiles
(
$dir
)
{
return
(
new
Facade
()
)->
getFilesAsArray
(
$dir
,
[
'.php'
]
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Jul 3, 16:49 (7 h, 44 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
d3/8a/70f39b8b739cd8309046851a5b96
Default Alt Text
StructureTest.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment