jenkins-bot has submitted this change and it was merged.

Change subject: Use mocks in QuantityDetailsFormatterTest
......................................................................


Use mocks in QuantityDetailsFormatterTest

This makes the test independent from the BasicQuantityUnitFormatter
class. I'm doing this in preparation for T108808 but submitting it
as a separate patch for easier review.

Bug: T108808
Change-Id: I74ec577610ec6846ee0fc7fcbfce5d30d109068f
---
M lib/tests/phpunit/formatters/QuantityDetailsFormatterTest.php
1 file changed, 16 insertions(+), 9 deletions(-)

Approvals:
  Bene: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/tests/phpunit/formatters/QuantityDetailsFormatterTest.php 
b/lib/tests/phpunit/formatters/QuantityDetailsFormatterTest.php
index 93b6050..8c5e4f0 100644
--- a/lib/tests/phpunit/formatters/QuantityDetailsFormatterTest.php
+++ b/lib/tests/phpunit/formatters/QuantityDetailsFormatterTest.php
@@ -5,7 +5,6 @@
 use DataValues\NumberValue;
 use DataValues\QuantityValue;
 use ValueFormatters\BasicNumberLocalizer;
-use ValueFormatters\BasicQuantityUnitFormatter;
 use ValueFormatters\FormatterOptions;
 use ValueFormatters\ValueFormatter;
 use Wikibase\Lib\QuantityDetailsFormatter;
@@ -19,15 +18,23 @@
  *
  * @licence GNU GPL v2+
  * @author Daniel Kinzler
+ * @author Thiemo Mättig
  */
 class QuantityDetailsFormatterTest extends \PHPUnit_Framework_TestCase {
 
        private function newFormatter( FormatterOptions $options = null ) {
                $numberLocalizer = new BasicNumberLocalizer();
-               $unitFormatter = new BasicQuantityUnitFormatter();
-               $formatter = new QuantityDetailsFormatter( $numberLocalizer, 
$unitFormatter, $options );
 
-               return $formatter;
+               $unitFormatter = $this->getMockBuilder( 
'ValueFormatters\QuantityUnitFormatter' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+               $unitFormatter->expects( $this->any() )
+                       ->method( 'applyUnit' )
+                       ->will( $this->returnCallback( function( $unit, 
$numberText ) {
+                               return $numberText . ' ' . $unit;
+                       } ) );
+
+               return new QuantityDetailsFormatter( $numberLocalizer, 
$unitFormatter, $options );
        }
 
        /**
@@ -51,11 +58,11 @@
                                $options,
                                '@' . implode( '.*',
                                        array(
-                                               
'<h4[^<>]*>[^<>]*5[^<>]*1[^<>]*</h4>',
-                                               '<td[^<>]*>[^<>]*5[^<>]*</td>',
-                                               '<td[^<>]*>[^<>]*6[^<>]*</td>',
-                                               '<td[^<>]*>[^<>]*4[^<>]*</td>',
-                                               '<td[^<>]*>[^<>]*1[^<>]*</td>',
+                                               
'<h4[^<>]*>[^<>]*\b5\b[^<>]*1[^<>]*</h4>',
+                                               
'<td[^<>]*>[^<>]*\b5\b[^<>]*</td>',
+                                               
'<td[^<>]*>[^<>]*\b6\b[^<>]*</td>',
+                                               
'<td[^<>]*>[^<>]*\b4\b[^<>]*</td>',
+                                               
'<td[^<>]*>[^<>]*\b1\b[^<>]*</td>',
                                        )
                                ) . '@s'
                        ),

-- 
To view, visit https://gerrit.wikimedia.org/r/236510
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I74ec577610ec6846ee0fc7fcbfce5d30d109068f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: Bene <benestar.wikime...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to