StructureTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * The tests here verify the structure of the code. This is for outright bugs,
  4. * not just style issues.
  5. */
  6. class StructureTest extends MediaWikiTestCase {
  7. /**
  8. * Verify all files that appear to be tests have file names ending in
  9. * Test. If the file names do not end in Test, they will not be run.
  10. * @group medium
  11. */
  12. public function testUnitTestFileNamesEndWithTest() {
  13. if ( wfIsWindows() ) {
  14. $this->markTestSkipped( 'This test does not work on Windows' );
  15. }
  16. $rootPath = escapeshellarg( __DIR__ . '/..' );
  17. $testClassRegex = implode( '|', array(
  18. 'ApiFormatTestBase',
  19. 'ApiTestCase',
  20. 'ApiQueryTestBase',
  21. 'ApiQueryContinueTestBase',
  22. 'MediaWikiLangTestCase',
  23. 'MediaWikiTestCase',
  24. 'ResourceLoaderTestCase',
  25. 'PHPUnit_Framework_TestCase',
  26. 'DumpTestCase',
  27. ) );
  28. $testClassRegex = "^class .* extends ($testClassRegex)";
  29. $finder = "find $rootPath -name '*.php' '!' -name '*Test.php'" .
  30. " | xargs grep -El '$testClassRegex|function suite\('";
  31. $results = null;
  32. $exitCode = null;
  33. exec( $finder, $results, $exitCode );
  34. $this->assertEquals(
  35. 0,
  36. $exitCode,
  37. 'Verify find/grep command succeeds.'
  38. );
  39. $results = array_filter(
  40. $results,
  41. array( $this, 'filterSuites' )
  42. );
  43. $strip = strlen( $rootPath ) - 1;
  44. foreach ( $results as $k => $v ) {
  45. $results[$k] = substr( $v, $strip );
  46. }
  47. $this->assertEquals(
  48. array(),
  49. $results,
  50. "Unit test file in $rootPath must end with Test."
  51. );
  52. }
  53. /**
  54. * Filter to remove testUnitTestFileNamesEndWithTest false positives.
  55. */
  56. public function filterSuites( $filename ) {
  57. return strpos( $filename, __DIR__ . '/../suites/' ) !== 0;
  58. }
  59. }