test: refactor/speed up release note file test
authorAntoine Musso <hashar@free.fr>
Tue, 2 Jul 2019 10:07:50 +0000 (12:07 +0200)
committerAntoine Musso <hashar@free.fr>
Tue, 2 Jul 2019 10:12:19 +0000 (12:12 +0200)
commitffc23ee333fffb6fbf26605facea6d1134be7d39
tree0eab6667699f40f2348534ac5a0428fa78799e1e
parent512ed8d0b97d2405e5e06e78ca0bca62ff5a166e
test: refactor/speed up release note file test

The test ReleaseNotesTest:testReleaseNotesFilesExistAndAreNotMalformed
takes 4 seconds on my machine. That is due to assertLessThanOrEqual
being invoked for each lines of various files at the root of the
repository. HISTORY has more than 20000 lines and assert functions are
rather slow.

Refactor the test:
* extract the logic to verify the file length of various files to a
  standalone test and with a dataprovider.
* flip the boolean logic ensuring whether the file exists. When it does
  not, PHP emit a warning which breaks the test anyway.
* Check the line lenght and collect errors in an array, then for each
  file run a single assertion to ensure the array of errors is empty.
  That effectively get rid of assertLessThanOrEqual overhead.
* Use assertSame() to show the full faulty line. assertEqual() shorten
  the arrays content.

Running tests went from 4 seconds to 700 ms on my machine.

Bug: T227067
Change-Id: I9bbbc6647ba9732b462e331e4b6d4acffe35e7cd
tests/phpunit/documentation/ReleaseNotesTest.php