jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/386597 )

Change subject: Fix sorting of NullResults
......................................................................


Fix sorting of NullResults

Commit a4c1832358 (change I60ad838dda) introduced the NullResult type,
which is a fake result holding no constraint to ensure that certain
contexts still appear in the API response even if they have no
constraints defined on them. However, the DelegatingConstraintChecker
sometimes look at the constraint of a result: when sorting the results,
it first sorts by status, then by snak, but if those are identical, then
it looks at the constraint type. If there are two identical statements
on an entity included in a constraint check, they will both add a
NullResult to the result list, and the comparer will blow up trying to
compare the two NullResults, since the snaks are identical.

Bug: T179038
Change-Id: I48ac2d947020f4dbf3c6c87ec5c098a4114de373
---
M includes/ConstraintCheck/DelegatingConstraintChecker.php
M tests/phpunit/DelegatingConstraintCheckerTest.php
2 files changed, 29 insertions(+), 0 deletions(-)

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



diff --git a/includes/ConstraintCheck/DelegatingConstraintChecker.php 
b/includes/ConstraintCheck/DelegatingConstraintChecker.php
index 198fef6..869381f 100644
--- a/includes/ConstraintCheck/DelegatingConstraintChecker.php
+++ b/includes/ConstraintCheck/DelegatingConstraintChecker.php
@@ -19,6 +19,7 @@
 use WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\LoggingHelper;
 use 
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\SparqlHelperException;
 use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResult;
+use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\NullResult;
 use WikibaseQuality\ConstraintReport\ConstraintLookup;
 use WikibaseQuality\ConstraintReport\Constraint;
 use Wikibase\DataModel\Entity\EntityId;
@@ -573,6 +574,13 @@
                                        $hashB = 
$b->getContext()->getSnak()->getHash();
 
                                        if ( $hashA === $hashB ) {
+                                               if ( $a instanceof NullResult ) 
{
+                                                       return $b instanceof 
NullResult ? 0 : -1;
+                                               }
+                                               if ( $b instanceof NullResult ) 
{
+                                                       return $a instanceof 
NullResult ? 0 : 1;
+                                               }
+
                                                $typeA = 
$a->getConstraint()->getConstraintTypeItemId();
                                                $typeB = 
$b->getConstraint()->getConstraintTypeItemId();
 
diff --git a/tests/phpunit/DelegatingConstraintCheckerTest.php 
b/tests/phpunit/DelegatingConstraintCheckerTest.php
index eafa1c8..72b9a60 100644
--- a/tests/phpunit/DelegatingConstraintCheckerTest.php
+++ b/tests/phpunit/DelegatingConstraintCheckerTest.php
@@ -14,6 +14,7 @@
 use Wikibase\Repo\Tests\NewStatement;
 use 
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintParameterException;
 use 
WikibaseQuality\ConstraintReport\ConstraintCheck\DelegatingConstraintChecker;
+use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\NullResult;
 use WikibaseQuality\ConstraintReport\ConstraintReportFactory;
 use WikibaseQuality\ConstraintReport\Tests\ConstraintParameters;
 use WikibaseQuality\ConstraintReport\Tests\ResultAssertions;
@@ -364,6 +365,26 @@
                $this->assertEmpty( $result );
        }
 
+       public function testCheckOnEntityIdNullResult() {
+               $statement = NewStatement::forProperty( 'P2' )
+                       ->withValue( 'foo' );
+               $entity = NewItem::withId( 'Q2' )
+                       ->andStatement( $statement )
+                       ->andStatement( $statement )
+                       ->build();
+               $this->lookup->addEntity( $entity );
+
+               $result = 
$this->constraintChecker->checkAgainstConstraintsOnEntityId(
+                       $entity->getId(),
+                       null,
+                       function( $context ) {
+                               return [ new NullResult( $context ) ];
+                       }
+               );
+
+               $this->assertCount( 2, $result );
+       }
+
        public function testCheckOnEntityIdUnknownConstraint() {
                $entity = NewItem::withId( 'Q3' )
                        ->andStatement(

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I48ac2d947020f4dbf3c6c87ec5c098a4114de373
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <lucas.werkmeis...@wikimedia.de>
Gerrit-Reviewer: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de>
Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Lucas Werkmeister (WMDE) <lucas.werkmeis...@wikimedia.de>
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