Skip to content

Instantly share code, notes, and snippets.

@divyanshikathuria
Created October 12, 2014 13:01
Show Gist options
  • Save divyanshikathuria/e5a09b50f65779f92c69 to your computer and use it in GitHub Desktop.
Save divyanshikathuria/e5a09b50f65779f92c69 to your computer and use it in GitHub Desktop.
I have incorporated dataproviders in the test.
<?php
/**
* The tests here verify the structure of the code. This is for outright bugs,
* not just style issues.
*/
class StructureTest extends MediaWikiTestCase {
/**
* 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
*/
/**
* @dataProvider Provider
*/
public function testUnitTestFileNamesEndWithTest($array) {
if ( wfIsWindows() ) {
$this->markTestSkipped( 'This test does not work on Windows' );
}
$rootPath = escapeshellarg( __DIR__ . '/..' );
$testClassRegex = implode( '|', $array) );
$testClassRegex = "^class .* extends ($testClassRegex)";
$finder = "find $rootPath -name '*.php' '!' -name '*Test.php'" .
" | xargs grep -El '$testClassRegex|function suite\('";
$results = null;
$exitCode = null;
exec( $finder, $results, $exitCode );
$this->assertEquals(
0,
$exitCode,
'Verify find/grep command succeeds.'
);
$results = array_filter(
$results,
array( $this, 'filterSuites' )
);
$strip = strlen( $rootPath ) - 1;
foreach ( $results as $k => $v ) {
$results[$k] = substr( $v, $strip );
}
$this->assertEquals(
array(),
$results,
"Unit test file in $rootPath must end with Test."
);
}
/**
* Filter to remove testUnitTestFileNamesEndWithTest false positives.
* @param string $filename
* @return bool
*/
public function filterSuites( $filename ) {
return strpos( $filename, __DIR__ . '/../suites/' ) !== 0;
}
public function phpfilesProvider()
{
$dir = '/tests';
return array( scandir ($dir));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment