- 
                Notifications
    
You must be signed in to change notification settings  - Fork 0
 
Sitelink refactor #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
| 
     | 
||
| declare( strict_types = 1 ); | ||
| 
     | 
||
| namespace ProfessionalWiki\WikibaseFacetedSearch\Persistence; | ||
| 
     | 
||
| use ProfessionalWiki\WikibaseFacetedSearch\Application\Config; | ||
| use Wikibase\Repo\WikibaseRepo; | ||
| 
     | 
||
| class ItemPageLookupFactory { | ||
| 
     | 
||
| public function __construct( | ||
| private readonly Config $config | ||
| ) { | ||
| } | ||
| 
     | 
||
| public function newItemPageLookup(): ItemPageLookup { | ||
| if ( $this->config->linkTargetSitelinkSiteId !== null ) { | ||
| return new SiteLinkItemPageLookup( | ||
| WikibaseRepo::getStore()->newSiteLinkStore(), | ||
| $this->config->linkTargetSitelinkSiteId | ||
| ); | ||
| } | ||
| 
     | 
||
| return new NullItemPageLookup(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?php | ||
| 
     | 
||
| declare( strict_types = 1 ); | ||
| 
     | 
||
| namespace ProfessionalWiki\WikibaseFacetedSearch\Persistence; | ||
| 
     | 
||
| use Title; | ||
| use Wikibase\DataModel\Entity\ItemId; | ||
| 
     | 
||
| class NullItemPageLookup implements ItemPageLookup { | ||
| 
     | 
||
| public function getPageTitle( ItemId $itemId ): ?Title { | ||
| return null; | ||
| } | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if the call to  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In which case, this code could go into its own method: $pageTitle = self::getItemPage( $itemId );
		if ( $pageTitle === null ) {
			return;
		}
		$title = $pageTitle;
		```There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
 When you override  In the end if   | 
||
| 
     | 
||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?php | ||
| 
     | 
||
| declare( strict_types = 1 ); | ||
| 
     | 
||
| namespace ProfessionalWiki\WikibaseFacetedSearch\Tests\Persistence; | ||
| 
     | 
||
| use PHPUnit\Framework\TestCase; | ||
| use ProfessionalWiki\WikibaseFacetedSearch\Application\Config; | ||
| use ProfessionalWiki\WikibaseFacetedSearch\Persistence\ItemPageLookupFactory; | ||
| use ProfessionalWiki\WikibaseFacetedSearch\Persistence\NullItemPageLookup; | ||
| use ProfessionalWiki\WikibaseFacetedSearch\Persistence\SiteLinkItemPageLookup; | ||
| 
     | 
||
| /** | ||
| * @covers \ProfessionalWiki\WikibaseFacetedSearch\Persistence\ItemPageLookupFactory | ||
| */ | ||
| class ItemPageLookupFactoryTest extends TestCase { | ||
| 
     | 
||
| public function testReturnsNullItemPageLookupWhenNoSiteIdIsConfigured(): void { | ||
| $factory = new ItemPageLookupFactory( | ||
| new Config() | ||
| ); | ||
| 
     | 
||
| $this->assertInstanceOf( NullItemPageLookup::class, $factory->newItemPageLookup() ); | ||
| } | ||
| 
     | 
||
| public function testReturnsSiteLinkItemPageLookupWhenSiteIdIsConfigured(): void { | ||
| $factory = new ItemPageLookupFactory( | ||
| new Config( | ||
| linkTargetSitelinkSiteId: 'enwiki' | ||
| ) | ||
| ); | ||
| 
     | 
||
| $this->assertInstanceOf( SiteLinkItemPageLookup::class, $factory->newItemPageLookup() ); | ||
| } | ||
| 
     | 
||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?php | ||
| 
     | 
||
| declare( strict_types = 1 ); | ||
| 
     | 
||
| namespace ProfessionalWiki\WikibaseFacetedSearch\Tests\Persistence; | ||
| 
     | 
||
| use PHPUnit\Framework\TestCase; | ||
| use ProfessionalWiki\WikibaseFacetedSearch\Persistence\NullItemPageLookup; | ||
| use Wikibase\DataModel\Entity\ItemId; | ||
| 
     | 
||
| /** | ||
| * @covers \ProfessionalWiki\WikibaseFacetedSearch\Persistence\NullItemPageLookup | ||
| */ | ||
| class NullItemPageLookupTest extends TestCase { | ||
| 
     | 
||
| public function testReturnsNull(): void { | ||
| $this->assertNull( | ||
| ( new NullItemPageLookup() )->getPageTitle( new ItemId( 'Q42' ) ) | ||
| ); | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Someone wants their 100% code coverage :D  | 
||
| } | ||
| 
     | 
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What motivated you to put this factory logic into a dedicated class? (I'm not objecting)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured it would be slightly more testable than being directly in the extension factory (where we don't typically expect, and test, logic). But then again it's also slightly YAGNI since there are no other Lookups at the moment.