[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Fix assertions and reduce complexity of LexemeViewTest
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/329615 ) Change subject: Fix assertions and reduce complexity of LexemeViewTest .. Fix assertions and reduce complexity of LexemeViewTest * I'm reducing the complexity of provideTestGetHtmlForLexicalCategoryAndLanguage very much. The test does have a single (logical) assertion now: Is the rendered headline exactly the expected one? Plus a lot of inlining and removing unused complexity. For example, the alternative language did not do anything. Change-Id: I1f567a36cd01992bdaa6ebad941b2ac3dccdab8f --- M tests/phpunit/mediawiki/View/LexemeViewTest.php 1 file changed, 52 insertions(+), 115 deletions(-) Approvals: WMDE-leszek: Looks good to me, approved jenkins-bot: Verified diff --git a/tests/phpunit/mediawiki/View/LexemeViewTest.php b/tests/phpunit/mediawiki/View/LexemeViewTest.php index 5b3f451..b1293e5 100644 --- a/tests/phpunit/mediawiki/View/LexemeViewTest.php +++ b/tests/phpunit/mediawiki/View/LexemeViewTest.php @@ -31,16 +31,26 @@ * * @license GPL-2.0+ * @author Amir Sarabadani + * @author Thiemo Mättig */ class LexemeViewTest extends PHPUnit_Framework_TestCase { /** +* @param StatementList|null $expectedStatements +* * @return StatementSectionsView */ - private function newStatementSectionsViewMock() { - return $this->getMockBuilder( StatementSectionsView::class ) + private function newStatementSectionsViewMock( StatementList $expectedStatements = null ) { + $statementSectionsView = $this->getMockBuilder( StatementSectionsView::class ) ->disableOriginalConstructor() ->getMock(); + + $statementSectionsView->expects( $expectedStatements ? $this->once() : $this->never() ) + ->method( 'getHtml' ) + ->with( $expectedStatements ) + ->will( $this->returnValue( 'statementSectionsView->getHtml' ) ); + + return $statementSectionsView; } /** @@ -57,7 +67,7 @@ if ( $itemId->getSerialization() === 'Q1' ) { return null; } - return new Term( 'en', 'getSerialization() . '>' ); + return new Term( 'en', 'getSerialization() . '>' ); } ) ); @@ -68,9 +78,17 @@ * @return EntityTermsView */ private function newEntityTermsViewMock() { - return $this->getMockBuilder( EntityTermsView::class ) + $entityTermsView = $this->getMockBuilder( EntityTermsView::class ) ->disableOriginalConstructor() ->getMock(); + + $entityTermsView->expects( $this->never() ) + ->method( 'getHtml' ); + + $entityTermsView->expects( $this->never() ) + ->method( 'getTitleHtml' ); + + return $entityTermsView; } /** @@ -84,37 +102,22 @@ return $languageDirectionalityLookup; } - private function newLexemeView( - $contentLanguageCode = 'en', - EntityTermsView $entityTermsView = null, - StatementSectionsView $statementSectionsView = null - ) { - $templateFactory = TemplateFactory::getDefaultInstance(); - - if ( !$entityTermsView ) { - $entityTermsView = $this->newEntityTermsViewMock(); - } - - if ( !$statementSectionsView ) { - $statementSectionsView = $this->newStatementSectionsViewMock(); - } - + private function newLexemeView( StatementList $expectedStatements = null ) { $languageDirectionalityLookup = $this->newLanguageDirectionalityLookupMock(); + $htmlTermRenderer = new FallbackHintHtmlTermRenderer( $languageDirectionalityLookup, - new LanguageNameLookup( $contentLanguageCode ) + new LanguageNameLookup( 'en' ) ); - $labelDescriptionLookup = $this->newLabelDescriptionLookup(); - return new LexemeView( - $templateFactory, - $entityTermsView, - $statementSectionsView, + TemplateFactory::getDefaultInstance(), + $this->newEntityTermsViewMock(), + $this->newStatementSectionsViewMock( $expectedStatements ), $languageDirectionalityLookup, $htmlTermRen
[MediaWiki-commits] [Gerrit] mediawiki...WikibaseLexeme[master]: Fix assertions and reduce complexity of LexemeViewTest
Thiemo Mättig (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/329615 ) Change subject: Fix assertions and reduce complexity of LexemeViewTest .. Fix assertions and reduce complexity of LexemeViewTest Two main things are happening here: * testGetHtml was not asserting anything. * I'm reducing the complexity of provideTestGetHtmlForLexicalCategoryAndLanguage very much. The test does have a single (logical) assertion now: Is the rendered headline exactly the expected one? Plus a lot of inlining and removing unused complexity. For example, the alternative language did not do anything. Change-Id: I1f567a36cd01992bdaa6ebad941b2ac3dccdab8f --- M tests/phpunit/mediawiki/View/LexemeViewTest.php 1 file changed, 49 insertions(+), 116 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme refs/changes/15/329615/1 diff --git a/tests/phpunit/mediawiki/View/LexemeViewTest.php b/tests/phpunit/mediawiki/View/LexemeViewTest.php index 5b3f451..ebdc07b 100644 --- a/tests/phpunit/mediawiki/View/LexemeViewTest.php +++ b/tests/phpunit/mediawiki/View/LexemeViewTest.php @@ -31,16 +31,26 @@ * * @license GPL-2.0+ * @author Amir Sarabadani + * @author Thiemo Mättig */ class LexemeViewTest extends PHPUnit_Framework_TestCase { /** +* @param StatementList|null $expectedStatements +* * @return StatementSectionsView */ - private function newStatementSectionsViewMock() { - return $this->getMockBuilder( StatementSectionsView::class ) + private function newStatementSectionsViewMock( StatementList $expectedStatements = null ) { + $statementSectionsView = $this->getMockBuilder( StatementSectionsView::class ) ->disableOriginalConstructor() ->getMock(); + + $statementSectionsView->expects( $expectedStatements ? $this->once() : $this->never() ) + ->method( 'getHtml' ) + ->with( $expectedStatements ) + ->will( $this->returnValue( 'statementSectionsView->getHtml' ) ); + + return $statementSectionsView; } /** @@ -57,7 +67,7 @@ if ( $itemId->getSerialization() === 'Q1' ) { return null; } - return new Term( 'en', 'getSerialization() . '>' ); + return new Term( 'en', 'getSerialization() . '>' ); } ) ); @@ -68,9 +78,17 @@ * @return EntityTermsView */ private function newEntityTermsViewMock() { - return $this->getMockBuilder( EntityTermsView::class ) + $entityTermsView = $this->getMockBuilder( EntityTermsView::class ) ->disableOriginalConstructor() ->getMock(); + + $entityTermsView->expects( $this->never() ) + ->method( 'getHtml' ); + + $entityTermsView->expects( $this->never() ) + ->method( 'getTitleHtml' ); + + return $entityTermsView; } /** @@ -84,37 +102,22 @@ return $languageDirectionalityLookup; } - private function newLexemeView( - $contentLanguageCode = 'en', - EntityTermsView $entityTermsView = null, - StatementSectionsView $statementSectionsView = null - ) { - $templateFactory = TemplateFactory::getDefaultInstance(); - - if ( !$entityTermsView ) { - $entityTermsView = $this->newEntityTermsViewMock(); - } - - if ( !$statementSectionsView ) { - $statementSectionsView = $this->newStatementSectionsViewMock(); - } - + private function newLexemeView( StatementList $expectedStatements = null ) { $languageDirectionalityLookup = $this->newLanguageDirectionalityLookupMock(); + $htmlTermRenderer = new FallbackHintHtmlTermRenderer( $languageDirectionalityLookup, - new LanguageNameLookup( $contentLanguageCode ) + new LanguageNameLookup( 'en' ) ); - $labelDescriptionLookup = $this->newLabelDescriptionLookup(); - return new LexemeView( - $templateFactory, - $entityTermsView, - $statementSectionsView, + TemplateFactory::getDefaultInstance(), + $this->newEntityTermsViewMock(), + $this->newStatementSectionsViewMock( $expect