r102719 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102718‎ | r102719 | r102720 >
Date:23:45, 10 November 2011
Author:gicode
Status:ok (Comments)
Tags:todo 
Comment:
Add test to catch the problem fixed in r102595.

Confirmed the test works by removing "Test" from one of the test file names.
Modified paths:
  • /trunk/phase3/tests/phpunit/structureTest.php (added) (history)
  • /trunk/phase3/tests/phpunit/suite.xml (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/structureTest.php
@@ -0,0 +1,53 @@
 2+<?php
 3+/**
 4+ * The tests here verify the structure of the code. This is for outright bugs,
 5+ * not just style issues.
 6+ */
 7+
 8+class structureTest extends MediaWikiTestCase {
 9+ /**
 10+ * Verify all files that appear to be tests have file names ending in
 11+ * Test. If the file names do not end in Test, they will not be run.
 12+ */
 13+ public function testUnitTestFileNamesEndWithTest() {
 14+ $rootPath = escapeshellarg( __DIR__ );
 15+ $testClassRegex = implode( '|', array(
 16+ 'ApiFormatTestBase',
 17+ 'ApiTestCase',
 18+ 'MediaWikiLangTestCase',
 19+ 'MediaWikiTestCase',
 20+ 'PHPUnit_Framework_TestCase',
 21+ ) );
 22+ $testClassRegex = "^class .* extends ($testClassRegex)";
 23+ $finder = "find $rootPath -name '*.php' '!' -name '*Test.php'" .
 24+ " | xargs grep -El '$testClassRegex|function suite\('";
 25+
 26+ $results = null;
 27+ $exitCode = null;
 28+ exec($finder, $results, $exitCode);
 29+
 30+ $this->assertEquals(
 31+ 0,
 32+ $exitCode,
 33+ 'Verify find/grep command succeeds.'
 34+ );
 35+
 36+ $results = array_filter(
 37+ $results,
 38+ array( $this, 'filterSuites' )
 39+ );
 40+
 41+ $this->assertEquals(
 42+ array(),
 43+ $results,
 44+ 'Unit test file names must end with Test.'
 45+ );
 46+ }
 47+
 48+ /**
 49+ * Filter to remove testUnitTestFileNamesEndWithTest false positives.
 50+ */
 51+ public function filterSuites( $filename ) {
 52+ return strpos( $filename, __DIR__ . '/suites/' ) !== 0;
 53+ }
 54+}
Index: trunk/phase3/tests/phpunit/suite.xml
@@ -20,6 +20,9 @@
2121 <testsuite name="skins">
2222 <directory>skins</directory>
2323 </testsuite>
 24+ <testsuite name="structure">
 25+ <file>structureTest.php</file>
 26+ </testsuite>
2427 <testsuite name="uploadfromurl">
2528 <file>suites/UploadFromUrlTestSuite.php</file>
2629 </testsuite>

Follow-up revisions

RevisionCommit summaryAuthorDate
r102720Fix file name and class case....gicode23:52, 10 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r102595Move tests that have likely never been executed. Now they will be executed....gicode23:11, 9 November 2011

Comments

#Comment by 😂 (talk | contribs)   21:39, 12 November 2011

Rather than doing an exec(), how about using something like RecursiveDirectoryIterator?

#Comment by GICodeWarrior (talk | contribs)   21:50, 12 November 2011

Ah, that shouldn't be too bad (and will work on win32). My searching only turned up the file function APIs and the exec was much easier than building traversal code by hand. :-/

Do you know a good replacement for the grep off-hand? file_get_contents would be easy to use but feels dirty.

#Comment by 😂 (talk | contribs)   21:59, 12 November 2011

The other option is making sure all of the classes are loaded and then do something with ReflectionClass.

Status & tagging log