repoGroup = $this->getMockBuilder( '\RepoGroup' ) ->disableOriginalConstructor() ->getMock(); } public function testCanConstruct() { $this->assertInstanceOf( FileRepoFinder::class, new FileRepoFinder( $this->repoGroup ) ); } public function testFindFile() { $file = $this->getMockBuilder( '\File' ) ->disableOriginalConstructor() ->getMock(); $this->repoGroup->expects( $this->once() ) ->method( 'findFile' ) ->willReturn( $file ); $title = $this->getMockBuilder( '\MediaWiki\Title\Title' ) ->disableOriginalConstructor() ->getMock(); $instance = new FileRepoFinder( $this->repoGroup ); $this->assertInstanceOf( '\File', $instance->findFile( $title ) ); } public function testFindFromArchive() { $file = $this->getMockBuilder( '\File' ) ->disableOriginalConstructor() ->getMock(); if ( version_compare( MW_VERSION, '1.41', '>=' ) ) { // Mock the IReadableDatabase interface $db = $this->getMockBuilder( \Wikimedia\Rdbms\IReadableDatabase::class ) ->disableOriginalConstructor() ->getMock(); } else { $db = $this->getMockBuilder( '\Database' ) ->disableOriginalConstructor() ->getMock(); } $localRepo = $this->getMockBuilder( '\LocalRepo' ) ->disableOriginalConstructor() ->getMock(); // Ensure getReplicaDB returns a mock of IReadableDatabase $localRepo->expects( $this->any() ) ->method( 'getReplicaDB' ) ->willReturn( $db ); $this->repoGroup->expects( $this->any() ) ->method( 'getLocalRepo' ) ->willReturn( $localRepo ); $localRepo->expects( $this->once() ) ->method( 'findBySha1' ) ->willReturn( [ $file ] ); $instance = new FileRepoFinder( $this->repoGroup ); $this->assertInstanceOf( '\File', $instance->findFromArchive( '42', '1970010101010' ) ); } }