Better way to update expected test outputs

Use an environment variable "DISCUSSIONTOOLS_OVERWRITE_TESTS".

Change-Id: I017112b7d6b1df9497f01f3f97f34e0935ca16f8
This commit is contained in:
Bartosz Dziewoński 2020-10-19 22:51:43 +02:00
parent 83b6f3b6ce
commit a29c49ae70
5 changed files with 27 additions and 11 deletions

View file

@ -1,4 +1,10 @@
The HTML files were saved from:
To update the expected outputs, run the PHP tests with the environment variable
"DISCUSSIONTOOLS_OVERWRITE_TESTS" set to any value, e.g.:
DISCUSSIONTOOLS_OVERWRITE_TESTS=1 php tests/phpunit/phpunit.php extensions/DiscussionTools/tests/phpunit/
The input HTML files were saved from:
pl-big:
https://pl.wikipedia.org/w/index.php?action=render&title=Wikipedia:Kawiarenka/Artyku%C5%82y_dyskusja/Archiwum/2018-pa%C5%BAdziernik&oldid=55171451

View file

@ -43,8 +43,10 @@ class CommentModifierTest extends CommentTestCase {
$expectedDoc = self::createDocument( $expected );
// Uncomment this to write updated content to the "modified HTML" files:
// self::overwriteHtmlFile( $expectedPath, $doc, $origPath );
// Optionally write updated content to the "modified HTML" files
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) {
self::overwriteHtmlFile( $expectedPath, $doc, $origPath );
}
// saveHtml is not dirty-diff safe, but for testing it is probably faster than DOMCompat::getOuterHTML
self::assertEquals( $expectedDoc->saveHtml(), $doc->saveHtml(), $name );
@ -87,8 +89,10 @@ class CommentModifierTest extends CommentTestCase {
$expectedDoc = self::createDocument( $expected );
// Uncomment this to write updated content to the "reply HTML" files:
// self::overwriteHtmlFile( $expectedPath, $doc, $origPath );
// Optionally write updated content to the "reply HTML" files
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) {
self::overwriteHtmlFile( $expectedPath, $doc, $origPath );
}
// saveHtml is not dirty-diff safe, but for testing it is probably faster than DOMCompat::getOuterHTML
self::assertEquals( $expectedDoc->saveHtml(), $doc->saveHtml(), $name );

View file

@ -203,8 +203,10 @@ class CommentParserTest extends CommentTestCase {
$processedThreads[] = $thread;
}
// Uncomment this to write updated content to the JSON files:
// self::overwriteJsonFile( $expectedPath, $processedThreads );
// Optionally write updated content to the JSON files
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) {
self::overwriteJsonFile( $expectedPath, $processedThreads );
}
foreach ( $threads as $i => $thread ) {
self::assertEquals( $expected[$i], $processedThreads[$i], $name . ' section ' . $i );

View file

@ -24,8 +24,10 @@ class DataTest extends CommentTestCase {
$data = Data::getLocalData( null, $conf, $langCode );
// Uncomment this to write updated content to the JSON files:
// self::overwriteJsonFile( $expectedPath, $data );
// Optionally write updated content to the JSON files
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) {
self::overwriteJsonFile( $expectedPath, $data );
}
self::assertEquals( $expectedData, $data );
}

View file

@ -74,8 +74,10 @@ class ThreadItemTest extends CommentTestCase {
$transcludedFrom[ $comment->getId() ] = $comment->getTranscludedFrom();
}
// Uncomment this to write updated content to the JSON files:
// self::overwriteJsonFile( $expectedPath, $transcludedFrom );
// Optionally write updated content to the JSON files
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) {
self::overwriteJsonFile( $expectedPath, $transcludedFrom );
}
self::assertEquals(
$expected,