Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / tests / phpunit / documentation / ReleaseNotesTest.php
1 <?php
2
3 /**
4 * James doesn't like having to manually fix these things.
5 */
6 class ReleaseNotesTest extends MediaWikiTestCase {
7 /**
8 * Verify that at least one Release Notes file exists, have content, and
9 * aren't overly long.
10 *
11 * @group documentation
12 * @coversNothing
13 */
14 public function testReleaseNotesFilesExistAndAreNotMalformed() {
15 global $wgVersion, $IP;
16
17 $notesFiles = glob( "$IP/RELEASE-NOTES-*" );
18
19 $this->assertGreaterThanOrEqual(
20 1,
21 count( $notesFiles ),
22 'Repo has at least one Release Notes file.'
23 );
24
25 $versionParts = explode( '.', explode( '-', $wgVersion )[0] );
26 $this->assertContains(
27 "$IP/RELEASE-NOTES-$versionParts[0].$versionParts[1]",
28 $notesFiles,
29 'Repo has a Release Notes file for the current $wgVersion.'
30 );
31
32 foreach ( $notesFiles as $index => $fileName ) {
33 $this->assertFileLength( "Release Notes", $fileName );
34 }
35 }
36
37 public static function provideFilesAtRoot() {
38 global $IP;
39
40 $rootFiles = [
41 "COPYING",
42 "FAQ",
43 "HISTORY",
44 "INSTALL",
45 "README",
46 "SECURITY",
47 ];
48
49 foreach ( $rootFiles as $rootFile ) {
50 yield "$rootFile file" => [ "$IP/$rootFile" ];
51 }
52 }
53
54 /**
55 * @dataProvider provideFilesAtRoot
56 * @coversNothing
57 */
58 public function testRootFilesHaveProperLineLength( $fileName ) {
59 $this->assertFileLength( "Help", $fileName );
60 }
61
62 private function assertFileLength( $type, $fileName ) {
63 $lines = file( $fileName, FILE_IGNORE_NEW_LINES );
64
65 $this->assertNotFalse(
66 $lines,
67 "$type file '$fileName' is inaccessible."
68 );
69
70 $errors = [];
71 foreach ( $lines as $i => $line ) {
72 $num = $i + 1;
73
74 // FILE_IGNORE_NEW_LINES drops the \n at the EOL, so max length is 80 not 81.
75 $max_length = 80;
76
77 $length = mb_strlen( $line );
78 if ( $length <= $max_length ) {
79 continue;
80 }
81 $errors[] = "line $num: length $length > $max_length:\n$line";
82 }
83 # Use assertSame() instead of assertEqual(), to show the full line in the diff
84 $this->assertSame(
85 [],
86 $errors,
87 "$type file '$fileName' lines " .
88 "have at most $max_length characters"
89 );
90 }
91 }