summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/filebackend/FileBackendTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes/filebackend/FileBackendTest.php')
-rw-r--r--tests/phpunit/includes/filebackend/FileBackendTest.php251
1 files changed, 184 insertions, 67 deletions
diff --git a/tests/phpunit/includes/filebackend/FileBackendTest.php b/tests/phpunit/includes/filebackend/FileBackendTest.php
index 9fbf7bb0..fcfa724f 100644
--- a/tests/phpunit/includes/filebackend/FileBackendTest.php
+++ b/tests/phpunit/includes/filebackend/FileBackendTest.php
@@ -6,14 +6,21 @@
* @group medium
*/
class FileBackendTest extends MediaWikiTestCase {
- private $backend, $multiBackend;
+
+ /** @var FileBackend */
+ private $backend;
+ /** @var FileBackendMultiWrite */
+ private $multiBackend;
+ /** @var FSFileBackend */
+ public $singleBackend;
private $filesToPrune = array();
private static $backendToUse;
protected function setUp() {
global $wgFileBackends;
parent::setUp();
- $tmpPrefix = wfTempDir() . '/filebackend-unittest-' . time() . '-' . mt_rand();
+ $uniqueId = time() . '-' . mt_rand();
+ $tmpPrefix = wfTempDir() . '/filebackend-unittest-' . $uniqueId;
if ( $this->getCliArg( 'use-filebackend=' ) ) {
if ( self::$backendToUse ) {
$this->singleBackend = self::$backendToUse;
@@ -36,32 +43,34 @@ class FileBackendTest extends MediaWikiTestCase {
}
} else {
$this->singleBackend = new FSFileBackend( array(
- 'name' => 'localtesting',
+ 'name' => 'localtesting',
'lockManager' => 'fsLockManager',
#'parallelize' => 'implicit',
+ 'wikiId' => wfWikiID() . $uniqueId,
'containerPaths' => array(
'unittest-cont1' => "{$tmpPrefix}-localtesting-cont1",
'unittest-cont2' => "{$tmpPrefix}-localtesting-cont2" )
) );
}
$this->multiBackend = new FileBackendMultiWrite( array(
- 'name' => 'localtesting',
+ 'name' => 'localtesting',
'lockManager' => 'fsLockManager',
'parallelize' => 'implicit',
- 'backends' => array(
+ 'wikiId' => wfWikiId() . $uniqueId,
+ 'backends' => array(
array(
- 'name' => 'localmultitesting1',
- 'class' => 'FSFileBackend',
- 'lockManager' => 'nullLockManager',
+ 'name' => 'localmultitesting1',
+ 'class' => 'FSFileBackend',
+ 'lockManager' => 'nullLockManager',
'containerPaths' => array(
'unittest-cont1' => "{$tmpPrefix}-localtestingmulti1-cont1",
'unittest-cont2' => "{$tmpPrefix}-localtestingmulti1-cont2" ),
'isMultiMaster' => false
),
array(
- 'name' => 'localmultitesting2',
- 'class' => 'FSFileBackend',
- 'lockManager' => 'nullLockManager',
+ 'name' => 'localmultitesting2',
+ 'class' => 'FSFileBackend',
+ 'lockManager' => 'nullLockManager',
'containerPaths' => array(
'unittest-cont1' => "{$tmpPrefix}-localtestingmulti2-cont1",
'unittest-cont2' => "{$tmpPrefix}-localtestingmulti2-cont2" ),
@@ -82,13 +91,14 @@ class FileBackendTest extends MediaWikiTestCase {
/**
* @dataProvider provider_testIsStoragePath
+ * @covers FileBackend::isStoragePath
*/
public function testIsStoragePath( $path, $isStorePath ) {
$this->assertEquals( $isStorePath, FileBackend::isStoragePath( $path ),
"FileBackend::isStoragePath on path '$path'" );
}
- function provider_testIsStoragePath() {
+ public static function provider_testIsStoragePath() {
return array(
array( 'mwstore://', true ),
array( 'mwstore://backend', true ),
@@ -106,13 +116,14 @@ class FileBackendTest extends MediaWikiTestCase {
/**
* @dataProvider provider_testSplitStoragePath
+ * @covers FileBackend::splitStoragePath
*/
public function testSplitStoragePath( $path, $res ) {
$this->assertEquals( $res, FileBackend::splitStoragePath( $path ),
"FileBackend::splitStoragePath on path '$path'" );
}
- function provider_testSplitStoragePath() {
+ public static function provider_testSplitStoragePath() {
return array(
array( 'mwstore://backend/container', array( 'backend', 'container', '' ) ),
array( 'mwstore://backend/container/', array( 'backend', 'container', '' ) ),
@@ -130,13 +141,14 @@ class FileBackendTest extends MediaWikiTestCase {
/**
* @dataProvider provider_normalizeStoragePath
+ * @covers FileBackend::normalizeStoragePath
*/
public function testNormalizeStoragePath( $path, $res ) {
$this->assertEquals( $res, FileBackend::normalizeStoragePath( $path ),
"FileBackend::normalizeStoragePath on path '$path'" );
}
- function provider_normalizeStoragePath() {
+ public static function provider_normalizeStoragePath() {
return array(
array( 'mwstore://backend/container', 'mwstore://backend/container' ),
array( 'mwstore://backend/container/', 'mwstore://backend/container' ),
@@ -156,13 +168,14 @@ class FileBackendTest extends MediaWikiTestCase {
/**
* @dataProvider provider_testParentStoragePath
+ * @covers FileBackend::parentStoragePath
*/
public function testParentStoragePath( $path, $res ) {
$this->assertEquals( $res, FileBackend::parentStoragePath( $path ),
"FileBackend::parentStoragePath on path '$path'" );
}
- function provider_testParentStoragePath() {
+ public static function provider_testParentStoragePath() {
return array(
array( 'mwstore://backend/container/path/to/obj', 'mwstore://backend/container/path/to' ),
array( 'mwstore://backend/container/path/to', 'mwstore://backend/container/path' ),
@@ -177,6 +190,7 @@ class FileBackendTest extends MediaWikiTestCase {
/**
* @dataProvider provider_testExtensionFromPath
+ * @covers FileBackend::extensionFromPath
*/
public function testExtensionFromPath( $path, $res ) {
$this->assertEquals( $res, FileBackend::extensionFromPath( $path ),
@@ -210,6 +224,9 @@ class FileBackendTest extends MediaWikiTestCase {
$this->tearDownFiles();
}
+ /**
+ * @covers FileBackend::doOperation
+ */
private function doTestStore( $op ) {
$backendName = $this->backendClass();
@@ -281,6 +298,7 @@ class FileBackendTest extends MediaWikiTestCase {
/**
* @dataProvider provider_testCopy
+ * @covers FileBackend::doOperation
*/
public function testCopy( $op ) {
$this->backend = $this->singleBackend;
@@ -312,6 +330,7 @@ class FileBackendTest extends MediaWikiTestCase {
"Source file $source does not exist ($backendName)." );
$this->assertEquals( false, $this->backend->fileExists( array( 'src' => $dest ) ),
"Destination file $dest does not exist ($backendName)." );
+
return; // done
}
@@ -400,6 +419,7 @@ class FileBackendTest extends MediaWikiTestCase {
/**
* @dataProvider provider_testMove
+ * @covers FileBackend::doOperation
*/
public function testMove( $op ) {
$this->backend = $this->singleBackend;
@@ -431,6 +451,7 @@ class FileBackendTest extends MediaWikiTestCase {
"Source file $source does not exist ($backendName)." );
$this->assertEquals( false, $this->backend->fileExists( array( 'src' => $dest ) ),
"Destination file $dest does not exist ($backendName)." );
+
return; // done
}
@@ -520,6 +541,7 @@ class FileBackendTest extends MediaWikiTestCase {
/**
* @dataProvider provider_testDelete
+ * @covers FileBackend::doOperation
*/
public function testDelete( $op, $withSource, $okStatus ) {
$this->backend = $this->singleBackend;
@@ -611,6 +633,7 @@ class FileBackendTest extends MediaWikiTestCase {
/**
* @dataProvider provider_testDescribe
+ * @covers FileBackend::doOperation
*/
public function testDescribe( $op, $withSource, $okStatus ) {
$this->backend = $this->singleBackend;
@@ -678,6 +701,7 @@ class FileBackendTest extends MediaWikiTestCase {
/**
* @dataProvider provider_testCreate
+ * @covers FileBackend::doOperation
*/
public function testCreate( $op, $alreadyExists, $okStatus, $newSize ) {
$this->backend = $this->singleBackend;
@@ -798,6 +822,9 @@ class FileBackendTest extends MediaWikiTestCase {
return $cases;
}
+ /**
+ * @covers FileBackend::doQuickOperations
+ */
public function testDoQuickOperations() {
$this->backend = $this->singleBackend;
$this->doTestDoQuickOperations();
@@ -817,32 +844,66 @@ class FileBackendTest extends MediaWikiTestCase {
"$base/unittest-cont1/e/fileB.a",
"$base/unittest-cont1/e/fileC.a"
);
- $ops = array();
+ $createOps = array();
$purgeOps = array();
foreach ( $files as $path ) {
$status = $this->prepare( array( 'dir' => dirname( $path ) ) );
$this->assertGoodStatus( $status,
"Preparing $path succeeded without warnings ($backendName)." );
- $ops[] = array( 'op' => 'create', 'dst' => $path, 'content' => mt_rand(0, 50000) );
+ $createOps[] = array( 'op' => 'create', 'dst' => $path, 'content' => mt_rand( 0, 50000 ) );
+ $copyOps[] = array( 'op' => 'copy', 'src' => $path, 'dst' => "$path-2" );
+ $moveOps[] = array( 'op' => 'move', 'src' => "$path-2", 'dst' => "$path-3" );
$purgeOps[] = array( 'op' => 'delete', 'src' => $path );
+ $purgeOps[] = array( 'op' => 'delete', 'src' => "$path-3" );
}
$purgeOps[] = array( 'op' => 'null' );
- $status = $this->backend->doQuickOperations( $ops );
- $this->assertGoodStatus( $status,
- "Creation of source files succeeded ($backendName)." );
+ $this->assertGoodStatus(
+ $this->backend->doQuickOperations( $createOps ),
+ "Creation of source files succeeded ($backendName)." );
foreach ( $files as $file ) {
$this->assertTrue( $this->backend->fileExists( array( 'src' => $file ) ),
"File $file exists." );
}
- $status = $this->backend->doQuickOperations( $purgeOps );
- $this->assertGoodStatus( $status,
- "Quick deletion of source files succeeded ($backendName)." );
+ $this->assertGoodStatus(
+ $this->backend->doQuickOperations( $copyOps ),
+ "Quick copy of source files succeeded ($backendName)." );
+ foreach ( $files as $file ) {
+ $this->assertTrue( $this->backend->fileExists( array( 'src' => "$file-2" ) ),
+ "File $file-2 exists." );
+ }
+ $this->assertGoodStatus(
+ $this->backend->doQuickOperations( $moveOps ),
+ "Quick move of source files succeeded ($backendName)." );
+ foreach ( $files as $file ) {
+ $this->assertTrue( $this->backend->fileExists( array( 'src' => "$file-3" ) ),
+ "File $file-3 move in." );
+ $this->assertFalse( $this->backend->fileExists( array( 'src' => "$file-2" ) ),
+ "File $file-2 moved away." );
+ }
+
+ $this->assertGoodStatus(
+ $this->backend->quickCopy( array( 'src' => $files[0], 'dst' => $files[0] ) ),
+ "Copy of file {$files[0]} over itself succeeded ($backendName)." );
+ $this->assertTrue( $this->backend->fileExists( array( 'src' => $files[0] ) ),
+ "File {$files[0]} still exists." );
+
+ $this->assertGoodStatus(
+ $this->backend->quickMove( array( 'src' => $files[0], 'dst' => $files[0] ) ),
+ "Move of file {$files[0]} over itself succeeded ($backendName)." );
+ $this->assertTrue( $this->backend->fileExists( array( 'src' => $files[0] ) ),
+ "File {$files[0]} still exists." );
+
+ $this->assertGoodStatus(
+ $this->backend->doQuickOperations( $purgeOps ),
+ "Quick deletion of source files succeeded ($backendName)." );
foreach ( $files as $file ) {
$this->assertFalse( $this->backend->fileExists( array( 'src' => $file ) ),
"File $file purged." );
+ $this->assertFalse( $this->backend->fileExists( array( 'src' => "$file-3" ) ),
+ "File $file-3 purged." );
}
}
@@ -855,6 +916,7 @@ class FileBackendTest extends MediaWikiTestCase {
$this->backend = $this->singleBackend;
$this->tearDownFiles();
$this->doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus );
+ $this->filesToPrune[] = $op['dst']; # avoid file leaking
$this->tearDownFiles();
$this->backend = $this->multiBackend;
@@ -873,8 +935,8 @@ class FileBackendTest extends MediaWikiTestCase {
foreach ( $srcs as $i => $source ) {
$this->prepare( array( 'dir' => dirname( $source ) ) );
$ops[] = array(
- 'op' => 'create', // operation
- 'dst' => $source, // source
+ 'op' => 'create', // operation
+ 'dst' => $source, // source
'content' => $srcsContent[$i]
);
$expContent .= $srcsContent[$i];
@@ -927,7 +989,7 @@ class FileBackendTest extends MediaWikiTestCase {
}
}
- function provider_testConcatenate() {
+ public static function provider_testConcatenate() {
$cases = array();
$rand = mt_rand( 0, 2000000000 ) . time();
@@ -979,6 +1041,7 @@ class FileBackendTest extends MediaWikiTestCase {
/**
* @dataProvider provider_testGetFileStat
+ * @covers FileBackend::getFileStat
*/
public function testGetFileStat( $path, $content, $alreadyExists ) {
$this->backend = $this->singleBackend;
@@ -1041,7 +1104,7 @@ class FileBackendTest extends MediaWikiTestCase {
}
}
- function provider_testGetFileStat() {
+ public static function provider_testGetFileStat() {
$cases = array();
$base = self::baseStorePath();
@@ -1054,6 +1117,8 @@ class FileBackendTest extends MediaWikiTestCase {
/**
* @dataProvider provider_testGetFileContents
+ * @covers FileBackend::getFileContents
+ * @covers FileBackend::getFileContentsMulti
*/
public function testGetFileContents( $source, $content ) {
$this->backend = $this->singleBackend;
@@ -1096,7 +1161,7 @@ class FileBackendTest extends MediaWikiTestCase {
}
}
- function provider_testGetFileContents() {
+ public static function provider_testGetFileContents() {
$cases = array();
$base = self::baseStorePath();
@@ -1113,6 +1178,7 @@ class FileBackendTest extends MediaWikiTestCase {
/**
* @dataProvider provider_testGetLocalCopy
+ * @covers FileBackend::getLocalCopy
*/
public function testGetLocalCopy( $source, $content ) {
$this->backend = $this->singleBackend;
@@ -1164,7 +1230,7 @@ class FileBackendTest extends MediaWikiTestCase {
$tmpFile->bind( $obj );
}
- function provider_testGetLocalCopy() {
+ public static function provider_testGetLocalCopy() {
$cases = array();
$base = self::baseStorePath();
@@ -1182,6 +1248,7 @@ class FileBackendTest extends MediaWikiTestCase {
/**
* @dataProvider provider_testGetLocalReference
+ * @covers FileBackend::getLocalReference
*/
public function testGetLocalReference( $source, $content ) {
$this->backend = $this->singleBackend;
@@ -1230,7 +1297,7 @@ class FileBackendTest extends MediaWikiTestCase {
}
}
- function provider_testGetLocalReference() {
+ public static function provider_testGetLocalReference() {
$cases = array();
$base = self::baseStorePath();
@@ -1246,6 +1313,10 @@ class FileBackendTest extends MediaWikiTestCase {
return $cases;
}
+ /**
+ * @covers FileBackend::getLocalCopy
+ * @covers FileBackend::getLocalReference
+ */
public function testGetLocalCopyAndReference404() {
$this->backend = $this->singleBackend;
$this->tearDownFiles();
@@ -1274,6 +1345,7 @@ class FileBackendTest extends MediaWikiTestCase {
/**
* @dataProvider provider_testGetFileHttpUrl
+ * @covers FileBackend::getFileHttpUrl
*/
public function testGetFileHttpUrl( $source, $content ) {
$this->backend = $this->singleBackend;
@@ -1305,7 +1377,7 @@ class FileBackendTest extends MediaWikiTestCase {
}
}
- function provider_testGetFileHttpUrl() {
+ public static function provider_testGetFileHttpUrl() {
$cases = array();
$base = self::baseStorePath();
@@ -1318,6 +1390,8 @@ class FileBackendTest extends MediaWikiTestCase {
/**
* @dataProvider provider_testPrepareAndClean
+ * @covers FileBackend::prepare
+ * @covers FileBackend::clean
*/
public function testPrepareAndClean( $path, $isOK ) {
$this->backend = $this->singleBackend;
@@ -1329,8 +1403,9 @@ class FileBackendTest extends MediaWikiTestCase {
$this->tearDownFiles();
}
- function provider_testPrepareAndClean() {
+ public static function provider_testPrepareAndClean() {
$base = self::baseStorePath();
+
return array(
array( "$base/unittest-cont1/e/a/z/some_file1.txt", true ),
array( "$base/unittest-cont2/a/z/some_file2.txt", true ),
@@ -1375,6 +1450,9 @@ class FileBackendTest extends MediaWikiTestCase {
$this->tearDownFiles();
}
+ /**
+ * @covers FileBackend::clean
+ */
private function doTestRecursiveClean() {
$backendName = $this->backendClass();
@@ -1419,8 +1497,11 @@ class FileBackendTest extends MediaWikiTestCase {
}
}
- // @TODO: testSecure
+ // @todo testSecure
+ /**
+ * @covers FileBackend::doOperations
+ */
public function testDoOperations() {
$this->backend = $this->singleBackend;
$this->tearDownFiles();
@@ -1508,6 +1589,9 @@ class FileBackendTest extends MediaWikiTestCase {
"Correct file SHA-1 of $fileC" );
}
+ /**
+ * @covers FileBackend::doOperations
+ */
public function testDoOperationsPipeline() {
$this->backend = $this->singleBackend;
$this->tearDownFiles();
@@ -1607,6 +1691,9 @@ class FileBackendTest extends MediaWikiTestCase {
"Correct file SHA-1 of $fileC" );
}
+ /**
+ * @covers FileBackend::doOperations
+ */
public function testDoOperationsFailing() {
$this->backend = $this->singleBackend;
$this->tearDownFiles();
@@ -1681,6 +1768,9 @@ class FileBackendTest extends MediaWikiTestCase {
"Correct file SHA-1 of $fileA" );
}
+ /**
+ * @covers FileBackend::getFileList
+ */
public function testGetFileList() {
$this->backend = $this->singleBackend;
$this->tearDownFiles();
@@ -1729,7 +1819,7 @@ class FileBackendTest extends MediaWikiTestCase {
$this->assertEquals( true, $status->isOK(),
"Creation of files succeeded with OK status ($backendName)." );
- // Expected listing
+ // Expected listing at root
$expected = array(
"e/test1.txt",
"e/test2.txt",
@@ -1748,27 +1838,28 @@ class FileBackendTest extends MediaWikiTestCase {
);
sort( $expected );
- // Actual listing (no trailing slash)
- $list = array();
+ // Actual listing (no trailing slash) at root
$iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1" ) );
- foreach ( $iter as $file ) {
- $list[] = $file;
- }
+ $list = $this->listToArray( $iter );
sort( $list );
+ $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
+ // Actual listing (no trailing slash) at root with advise
+ $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1", 'adviseStat' => 1 ) );
+ $list = $this->listToArray( $iter );
+ sort( $list );
$this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
- // Actual listing (with trailing slash)
+ // Actual listing (with trailing slash) at root
$list = array();
$iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/" ) );
foreach ( $iter as $file ) {
$list[] = $file;
}
sort( $list );
-
$this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
- // Expected listing
+ // Expected listing at subdir
$expected = array(
"test1.txt",
"test2.txt",
@@ -1780,36 +1871,39 @@ class FileBackendTest extends MediaWikiTestCase {
);
sort( $expected );
- // Actual listing (no trailing slash)
- $list = array();
+ // Actual listing (no trailing slash) at subdir
$iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir" ) );
- foreach ( $iter as $file ) {
- $list[] = $file;
- }
+ $list = $this->listToArray( $iter );
sort( $list );
+ $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
+ // Actual listing (no trailing slash) at subdir with advise
+ $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir", 'adviseStat' => 1 ) );
+ $list = $this->listToArray( $iter );
+ sort( $list );
$this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
- // Actual listing (with trailing slash)
+ // Actual listing (with trailing slash) at subdir
$list = array();
$iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir/" ) );
foreach ( $iter as $file ) {
$list[] = $file;
}
sort( $list );
-
$this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
// Actual listing (using iterator second time)
- $list = array();
- foreach ( $iter as $file ) {
- $list[] = $file;
- }
+ $list = $this->listToArray( $iter );
sort( $list );
-
$this->assertEquals( $expected, $list, "Correct file listing ($backendName), second iteration." );
- // Expected listing (top files only)
+ // Actual listing (top files only) at root
+ $iter = $this->backend->getTopFileList( array( 'dir' => "$base/unittest-cont1" ) );
+ $list = $this->listToArray( $iter );
+ sort( $list );
+ $this->assertEquals( array(), $list, "Correct top file listing ($backendName)." );
+
+ // Expected listing (top files only) at subdir
$expected = array(
"test1.txt",
"test2.txt",
@@ -1819,14 +1913,16 @@ class FileBackendTest extends MediaWikiTestCase {
);
sort( $expected );
- // Actual listing (top files only)
- $list = array();
+ // Actual listing (top files only) at subdir
$iter = $this->backend->getTopFileList( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir" ) );
- foreach ( $iter as $file ) {
- $list[] = $file;
- }
+ $list = $this->listToArray( $iter );
sort( $list );
+ $this->assertEquals( $expected, $list, "Correct top file listing ($backendName)." );
+ // Actual listing (top files only) at subdir with advise
+ $iter = $this->backend->getTopFileList( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir", 'adviseStat' => 1 ) );
+ $list = $this->listToArray( $iter );
+ sort( $list );
$this->assertEquals( $expected, $list, "Correct top file listing ($backendName)." );
foreach ( $files as $file ) { // clean up
@@ -1834,9 +1930,15 @@ class FileBackendTest extends MediaWikiTestCase {
}
$iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/not/exists" ) );
- foreach ( $iter as $iter ) {} // no errors
+ foreach ( $iter as $iter ) {
+ // no errors
+ }
}
+ /**
+ * @covers FileBackend::getTopDirectoryList
+ * @covers FileBackend::getDirectoryList
+ */
public function testGetDirectoryList() {
$this->backend = $this->singleBackend;
$this->tearDownFiles();
@@ -2023,7 +2125,7 @@ class FileBackendTest extends MediaWikiTestCase {
$this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
$iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/e/subdir1" ) );
- $items = is_array( $iter ) ? $iter : iterator_to_array( $iter );
+ $items = $this->listToArray( $iter );
$this->assertEquals( array(), $items, "Directory listing is empty." );
foreach ( $files as $file ) { // clean up
@@ -2031,15 +2133,22 @@ class FileBackendTest extends MediaWikiTestCase {
}
$iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/not/exists" ) );
- foreach ( $iter as $file ) {} // no errors
- $items = is_array( $iter ) ? $iter : iterator_to_array( $iter );
+ foreach ( $iter as $file ) {
+ // no errors
+ }
+
+ $items = $this->listToArray( $iter );
$this->assertEquals( array(), $items, "Directory listing is empty." );
$iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/e/not/exists" ) );
- $items = is_array( $iter ) ? $iter : iterator_to_array( $iter );
+ $items = $this->listToArray( $iter );
$this->assertEquals( array(), $items, "Directory listing is empty." );
}
+ /**
+ * @covers FileBackend::lockFiles
+ * @covers FileBackend::unlockFiles
+ */
public function testLockCalls() {
$this->backend = $this->singleBackend;
$this->doTestLockCalls();
@@ -2071,7 +2180,7 @@ class FileBackendTest extends MediaWikiTestCase {
"subdir2/subdir/sub/120-px-file.txt",
);
- for ( $i=0; $i<25; $i++ ) {
+ for ( $i = 0; $i < 25; $i++ ) {
$status = $this->backend->lockFiles( $paths, LockManager::LOCK_EX );
$this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ),
"Locking of files succeeded ($backendName) ($i)." );
@@ -2141,6 +2250,11 @@ class FileBackendTest extends MediaWikiTestCase {
"Scoped unlocking of files succeeded with OK status ($backendName)." );
}
+ // helper function
+ private function listToArray( $iter ) {
+ return is_array( $iter ) ? $iter : iterator_to_array( $iter );
+ }
+
// test helper wrapper for backend prepare() function
private function prepare( array $params ) {
return $this->backend->prepare( $params );
@@ -2149,12 +2263,15 @@ class FileBackendTest extends MediaWikiTestCase {
// test helper wrapper for backend prepare() function
private function create( array $params ) {
$params['op'] = 'create';
+
return $this->backend->doQuickOperations( array( $params ) );
}
function tearDownFiles() {
foreach ( $this->filesToPrune as $file ) {
- @unlink( $file );
+ if ( is_file( $file ) ) {
+ unlink( $file );
+ }
}
$containers = array( 'unittest-cont1', 'unittest-cont2' );
foreach ( $containers as $container ) {