* @ingroup FileAbstraction
*/
class ForeignDBFile extends LocalFile {
- /**
- * @param Title $title
- * @param FileRepo $repo
- * @param null $unused
- * @return ForeignDBFile
- */
- static function newFromTitle( $title, $repo, $unused = null ) {
- return new self( $title, $repo );
- }
-
- /**
- * Create a ForeignDBFile from a title
- * Do not call this except from inside a repo class.
- *
- * @param stdClass $row
- * @param FileRepo $repo
- * @return ForeignDBFile
- */
- static function newFromRow( $row, $repo ) {
- $title = Title::makeTitle( NS_FILE, $row->img_name );
- $file = new self( $title, $repo );
- $file->loadFromRow( $row );
-
- return $file;
- }
/**
* @param string $srcPath
* @param FileRepo $repo
* @param null $unused
*
- * @return self
+ * @return static
*/
static function newFromTitle( $title, $repo, $unused = null ) {
- return new self( $title, $repo );
+ return new static( $title, $repo );
}
/**
* @param stdClass $row
* @param FileRepo $repo
*
- * @return self
+ * @return static
*/
static function newFromRow( $row, $repo ) {
$title = Title::makeTitle( NS_FILE, $row->img_name );
- $file = new self( $title, $repo );
+ $file = new static( $title, $repo );
$file->loadFromRow( $row );
return $file;
$conds['img_timestamp'] = $dbr->timestamp( $timestamp );
}
- $fileQuery = self::getQueryInfo();
+ $fileQuery = static::getQueryInfo();
$row = $dbr->selectRow(
$fileQuery['tables'], $fileQuery['fields'], $conds, __METHOD__, [], $fileQuery['joins']
);
if ( $row ) {
- return self::newFromRow( $row, $repo );
+ return static::newFromRow( $row, $repo );
} else {
return false;
}
* @param Title $title
* @param FileRepo $repo
* @param string|int|null $time
- * @return self
+ * @return static
* @throws MWException
*/
static function newFromTitle( $title, $repo, $time = null ) {
throw new MWException( __METHOD__ . ' got null for $time parameter' );
}
- return new self( $title, $repo, $time, null );
+ return new static( $title, $repo, $time, null );
}
/**
* @param Title $title
* @param FileRepo $repo
* @param string $archiveName
- * @return self
+ * @return static
*/
static function newFromArchiveName( $title, $repo, $archiveName ) {
- return new self( $title, $repo, null, $archiveName );
+ return new static( $title, $repo, null, $archiveName );
}
/**
* @param stdClass $row
* @param FileRepo $repo
- * @return self
+ * @return static
*/
static function newFromRow( $row, $repo ) {
$title = Title::makeTitle( NS_FILE, $row->oi_name );
- $file = new self( $title, $repo, null, $row->oi_archive_name );
+ $file = new static( $title, $repo, null, $row->oi_archive_name );
$file->loadFromRow( $row, 'oi_' );
return $file;
$conds['oi_timestamp'] = $dbr->timestamp( $timestamp );
}
- $fileQuery = self::getQueryInfo();
+ $fileQuery = static::getQueryInfo();
$row = $dbr->selectRow(
$fileQuery['tables'], $fileQuery['fields'], $conds, __METHOD__, [], $fileQuery['joins']
);
if ( $row ) {
- return self::newFromRow( $row, $repo );
+ return static::newFromRow( $row, $repo );
} else {
return false;
}
/**
* @param string $path Storage path
* @param string $mime
- * @return UnregisteredLocalFile
+ * @return static
*/
static function newFromPath( $path, $mime ) {
- return new self( false, false, $path, $mime );
+ return new static( false, false, $path, $mime );
}
/**
* @param Title $title
* @param FileRepo $repo
- * @return UnregisteredLocalFile
+ * @return static
*/
static function newFromTitle( $title, $repo ) {
- return new self( $title, $repo, false, false );
+ return new static( $title, $repo, false, false );
}
/**
--- /dev/null
+<?php
+
+/** @covers ForeignDBFile */
+class ForeignDBFileTest extends \PHPUnit\Framework\TestCase {
+
+ use PHPUnit4And6Compat;
+
+ public function testShouldConstructCorrectInstanceFromTitle() {
+ $title = Title::makeTitle( NS_FILE, 'Awesome_file' );
+ $repoMock = $this->createMock( LocalRepo::class );
+
+ $file = ForeignDBFile::newFromTitle( $title, $repoMock );
+
+ $this->assertInstanceOf( ForeignDBFile::class, $file );
+ }
+}