dépôts
/
lhc
/
web
/
wiklou.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
tests: Use a fancy generator provider in ReleaseNotesTest
[lhc/web/wiklou.git]
/
tests
/
phpunit
/
documentation
/
ReleaseNotesTest.php
diff --git
a/tests/phpunit/documentation/ReleaseNotesTest.php
b/tests/phpunit/documentation/ReleaseNotesTest.php
index
019a13e
..
acbb04a
100644
(file)
--- a/
tests/phpunit/documentation/ReleaseNotesTest.php
+++ b/
tests/phpunit/documentation/ReleaseNotesTest.php
@@
-32,34
+32,60
@@
class ReleaseNotesTest extends MediaWikiTestCase {
foreach ( $notesFiles as $index => $fileName ) {
$this->assertFileLength( "Release Notes", $fileName );
}
foreach ( $notesFiles as $index => $fileName ) {
$this->assertFileLength( "Release Notes", $fileName );
}
+ }
+
+ public static function provideFilesAtRoot() {
+ global $IP;
- // Also test the README and similar files
- $otherFiles = [ "$IP/COPYING", "$IP/FAQ", "$IP/INSTALL", "$IP/README", "$IP/SECURITY" ];
+ $rootFiles = [
+ "COPYING",
+ "FAQ",
+ "HISTORY",
+ "INSTALL",
+ "README",
+ "SECURITY",
+ ];
- foreach ( $
otherFiles as $index => $fileNam
e ) {
-
$this->assertFileLength( "Help", $fileName )
;
+ foreach ( $
rootFiles as $rootFil
e ) {
+
yield "$rootFile file" => [ "$IP/$rootFile" ]
;
}
}
}
}
+ /**
+ * @dataProvider provideFilesAtRoot
+ * @coversNothing
+ */
+ public function testRootFilesHaveProperLineLength( $fileName ) {
+ $this->assertFileLength( "Help", $fileName );
+ }
+
private function assertFileLength( $type, $fileName ) {
private function assertFileLength( $type, $fileName ) {
- $
file
= file( $fileName, FILE_IGNORE_NEW_LINES );
+ $
lines
= file( $fileName, FILE_IGNORE_NEW_LINES );
- $this->assertFalse(
-
!$file
,
+ $this->assert
Not
False(
+
$lines
,
"$type file '$fileName' is inaccessible."
);
"$type file '$fileName' is inaccessible."
);
- $lines = count( $file );
+ $errors = [];
+ foreach ( $lines as $i => $line ) {
+ $num = $i + 1;
- for ( $i = 0; $i < $lines; $i++ ) {
- $
line = $file[$i]
;
+ // FILE_IGNORE_NEW_LINES drops the \n at the EOL, so max length is 80 not 81.
+ $
max_length = 80
;
- $this->assertLessThanOrEqual(
- // FILE_IGNORE_NEW_LINES drops the \n at the EOL, so max length is 80 not 81.
- 80,
- mb_strlen( $line ),
- "$type file '$fileName' line $i is longer than 80 chars:\n\t'$line'"
- );
+ $length = mb_strlen( $line );
+ if ( $length <= $max_length ) {
+ continue;
+ }
+ $errors[] = "line $num: length $length > $max_length:\n$line";
}
}
+ # Use assertSame() instead of assertEqual(), to show the full line in the diff
+ $this->assertSame(
+ [],
+ $errors,
+ "$type file '$fileName' lines " .
+ "have at most $max_length characters"
+ );
}
}
}
}