X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Ffilebackend%2FFileBackendTest.php;h=f259c0f171f6cc0d9c0557131990a9610fc9bbd6;hb=1834ee3d8e2f6a8ef2067ee7925c4f561209b12f;hp=0763a2e02317890a3cfa9284bdc65204af968709;hpb=b18803d1c52ce6d508dfa9cc20be9edce76926a7;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/filebackend/FileBackendTest.php b/tests/phpunit/includes/filebackend/FileBackendTest.php index 0763a2e023..f259c0f171 100644 --- a/tests/phpunit/includes/filebackend/FileBackendTest.php +++ b/tests/phpunit/includes/filebackend/FileBackendTest.php @@ -24,7 +24,7 @@ class FileBackendTest extends MediaWikiTestCase { $this->singleBackend = self::$backendToUse; } else { $name = $this->getCliArg( 'use-filebackend' ); - $useConfig = array(); + $useConfig = []; foreach ( $wgFileBackends as $conf ) { if ( $conf['name'] == $name ) { $useConfig = $conf; @@ -32,9 +32,9 @@ class FileBackendTest extends MediaWikiTestCase { } } $useConfig['name'] = 'localtesting'; // swap name - $useConfig['shardViaHashLevels'] = array( // test sharding - 'unittest-cont1' => array( 'levels' => 1, 'base' => 16, 'repeat' => 1 ) - ); + $useConfig['shardViaHashLevels'] = [ // test sharding + 'unittest-cont1' => [ 'levels' => 1, 'base' => 16, 'repeat' => 1 ] + ]; if ( isset( $useConfig['fileJournal'] ) ) { $useConfig['fileJournal'] = FileJournal::factory( $useConfig['fileJournal'], $name ); } @@ -44,39 +44,39 @@ class FileBackendTest extends MediaWikiTestCase { $this->singleBackend = self::$backendToUse; } } else { - $this->singleBackend = new FSFileBackend( array( + $this->singleBackend = new FSFileBackend( [ 'name' => 'localtesting', 'lockManager' => LockManagerGroup::singleton()->get( 'fsLockManager' ), 'wikiId' => wfWikiID(), - 'containerPaths' => array( + 'containerPaths' => [ 'unittest-cont1' => "{$tmpDir}/localtesting-cont1", - 'unittest-cont2' => "{$tmpDir}/localtesting-cont2" ) - ) ); + 'unittest-cont2' => "{$tmpDir}/localtesting-cont2" ] + ] ); } - $this->multiBackend = new FileBackendMultiWrite( array( + $this->multiBackend = new FileBackendMultiWrite( [ 'name' => 'localtesting', 'lockManager' => LockManagerGroup::singleton()->get( 'fsLockManager' ), 'parallelize' => 'implicit', - 'wikiId' => wfWikiId() . wfRandomString(), - 'backends' => array( - array( + 'wikiId' => wfWikiID() . wfRandomString(), + 'backends' => [ + [ 'name' => 'localmultitesting1', 'class' => 'FSFileBackend', - 'containerPaths' => array( + 'containerPaths' => [ 'unittest-cont1' => "{$tmpDir}/localtestingmulti1-cont1", - 'unittest-cont2' => "{$tmpDir}/localtestingmulti1-cont2" ), + 'unittest-cont2' => "{$tmpDir}/localtestingmulti1-cont2" ], 'isMultiMaster' => false - ), - array( + ], + [ 'name' => 'localmultitesting2', 'class' => 'FSFileBackend', - 'containerPaths' => array( + 'containerPaths' => [ 'unittest-cont1' => "{$tmpDir}/localtestingmulti2-cont1", - 'unittest-cont2' => "{$tmpDir}/localtestingmulti2-cont2" ), + 'unittest-cont2' => "{$tmpDir}/localtestingmulti2-cont2" ], 'isMultiMaster' => true - ) - ) - ) ); + ] + ] + ] ); } private static function baseStorePath() { @@ -97,19 +97,19 @@ class FileBackendTest extends MediaWikiTestCase { } public static function provider_testIsStoragePath() { - return array( - array( 'mwstore://', true ), - array( 'mwstore://backend', true ), - array( 'mwstore://backend/container', true ), - array( 'mwstore://backend/container/', true ), - array( 'mwstore://backend/container/path', true ), - array( 'mwstore://backend//container/', true ), - array( 'mwstore://backend//container//', true ), - array( 'mwstore://backend//container//path', true ), - array( 'mwstore:///', true ), - array( 'mwstore:/', false ), - array( 'mwstore:', false ), - ); + return [ + [ 'mwstore://', true ], + [ 'mwstore://backend', true ], + [ 'mwstore://backend/container', true ], + [ 'mwstore://backend/container/', true ], + [ 'mwstore://backend/container/path', true ], + [ 'mwstore://backend//container/', true ], + [ 'mwstore://backend//container//', true ], + [ 'mwstore://backend//container//path', true ], + [ 'mwstore:///', true ], + [ 'mwstore:/', false ], + [ 'mwstore:', false ], + ]; } /** @@ -122,19 +122,19 @@ class FileBackendTest extends MediaWikiTestCase { } public static function provider_testSplitStoragePath() { - return array( - array( 'mwstore://backend/container', array( 'backend', 'container', '' ) ), - array( 'mwstore://backend/container/', array( 'backend', 'container', '' ) ), - array( 'mwstore://backend/container/path', array( 'backend', 'container', 'path' ) ), - array( 'mwstore://backend/container//path', array( 'backend', 'container', '/path' ) ), - array( 'mwstore://backend//container/path', array( null, null, null ) ), - array( 'mwstore://backend//container//path', array( null, null, null ) ), - array( 'mwstore://', array( null, null, null ) ), - array( 'mwstore://backend', array( null, null, null ) ), - array( 'mwstore:///', array( null, null, null ) ), - array( 'mwstore:/', array( null, null, null ) ), - array( 'mwstore:', array( null, null, null ) ) - ); + return [ + [ 'mwstore://backend/container', [ 'backend', 'container', '' ] ], + [ 'mwstore://backend/container/', [ 'backend', 'container', '' ] ], + [ 'mwstore://backend/container/path', [ 'backend', 'container', 'path' ] ], + [ 'mwstore://backend/container//path', [ 'backend', 'container', '/path' ] ], + [ 'mwstore://backend//container/path', [ null, null, null ] ], + [ 'mwstore://backend//container//path', [ null, null, null ] ], + [ 'mwstore://', [ null, null, null ] ], + [ 'mwstore://backend', [ null, null, null ] ], + [ 'mwstore:///', [ null, null, null ] ], + [ 'mwstore:/', [ null, null, null ] ], + [ 'mwstore:', [ null, null, null ] ] + ]; } /** @@ -147,24 +147,24 @@ class FileBackendTest extends MediaWikiTestCase { } public static function provider_normalizeStoragePath() { - return array( - array( 'mwstore://backend/container', 'mwstore://backend/container' ), - array( 'mwstore://backend/container/', 'mwstore://backend/container' ), - array( 'mwstore://backend/container/path', 'mwstore://backend/container/path' ), - array( 'mwstore://backend/container//path', 'mwstore://backend/container/path' ), - array( 'mwstore://backend/container///path', 'mwstore://backend/container/path' ), - array( + return [ + [ 'mwstore://backend/container', 'mwstore://backend/container' ], + [ 'mwstore://backend/container/', 'mwstore://backend/container' ], + [ 'mwstore://backend/container/path', 'mwstore://backend/container/path' ], + [ 'mwstore://backend/container//path', 'mwstore://backend/container/path' ], + [ 'mwstore://backend/container///path', 'mwstore://backend/container/path' ], + [ 'mwstore://backend/container///path//to///obj', 'mwstore://backend/container/path/to/obj' - ), - array( 'mwstore://', null ), - array( 'mwstore://backend', null ), - array( 'mwstore://backend//container/path', null ), - array( 'mwstore://backend//container//path', null ), - array( 'mwstore:///', null ), - array( 'mwstore:/', null ), - array( 'mwstore:', null ), - ); + ], + [ 'mwstore://', null ], + [ 'mwstore://backend', null ], + [ 'mwstore://backend//container/path', null ], + [ 'mwstore://backend//container//path', null ], + [ 'mwstore:///', null ], + [ 'mwstore:/', null ], + [ 'mwstore:', null ], + ]; } /** @@ -177,16 +177,16 @@ class FileBackendTest extends MediaWikiTestCase { } 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' ), - array( 'mwstore://backend/container/path', 'mwstore://backend/container' ), - array( 'mwstore://backend/container', null ), - array( 'mwstore://backend/container/path/to/obj/', 'mwstore://backend/container/path/to' ), - array( 'mwstore://backend/container/path/to/', 'mwstore://backend/container/path' ), - array( 'mwstore://backend/container/path/', 'mwstore://backend/container' ), - array( 'mwstore://backend/container/', null ), - ); + return [ + [ 'mwstore://backend/container/path/to/obj', 'mwstore://backend/container/path/to' ], + [ 'mwstore://backend/container/path/to', 'mwstore://backend/container/path' ], + [ 'mwstore://backend/container/path', 'mwstore://backend/container' ], + [ 'mwstore://backend/container', null ], + [ 'mwstore://backend/container/path/to/obj/', 'mwstore://backend/container/path/to' ], + [ 'mwstore://backend/container/path/to/', 'mwstore://backend/container/path' ], + [ 'mwstore://backend/container/path/', 'mwstore://backend/container' ], + [ 'mwstore://backend/container/', null ], + ]; } /** @@ -199,12 +199,12 @@ class FileBackendTest extends MediaWikiTestCase { } public static function provider_testExtensionFromPath() { - return array( - array( 'mwstore://backend/container/path.txt', 'txt' ), - array( 'mwstore://backend/container/path.svg.png', 'png' ), - array( 'mwstore://backend/container/path', '' ), - array( 'mwstore://backend/container/path.', '' ), - ); + return [ + [ 'mwstore://backend/container/path.txt', 'txt' ], + [ 'mwstore://backend/container/path.svg.png', 'png' ], + [ 'mwstore://backend/container/path', '' ], + [ 'mwstore://backend/container/path.', '' ], + ]; } /** @@ -232,7 +232,7 @@ class FileBackendTest extends MediaWikiTestCase { $source = $op['src']; $dest = $op['dst']; - $this->prepare( array( 'dir' => dirname( $dest ) ) ); + $this->prepare( [ 'dir' => dirname( $dest ) ] ); file_put_contents( $source, "Unit test file" ); @@ -246,40 +246,40 @@ class FileBackendTest extends MediaWikiTestCase { "Store from $source to $dest succeeded without warnings ($backendName)." ); $this->assertEquals( true, $status->isOK(), "Store from $source to $dest succeeded ($backendName)." ); - $this->assertEquals( array( 0 => true ), $status->success, + $this->assertEquals( [ 0 => true ], $status->success, "Store from $source to $dest has proper 'success' field in Status ($backendName)." ); $this->assertEquals( true, file_exists( $source ), "Source file $source still exists ($backendName)." ); - $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ), + $this->assertEquals( true, $this->backend->fileExists( [ 'src' => $dest ] ), "Destination file $dest exists ($backendName)." ); $this->assertEquals( filesize( $source ), - $this->backend->getFileSize( array( 'src' => $dest ) ), + $this->backend->getFileSize( [ 'src' => $dest ] ), "Destination file $dest has correct size ($backendName)." ); $props1 = FSFile::getPropsFromPath( $source ); - $props2 = $this->backend->getFileProps( array( 'src' => $dest ) ); + $props2 = $this->backend->getFileProps( [ 'src' => $dest ] ); $this->assertEquals( $props1, $props2, "Source and destination have the same props ($backendName)." ); - $this->assertBackendPathsConsistent( array( $dest ) ); + $this->assertBackendPathsConsistent( [ $dest ] ); } public static function provider_testStore() { - $cases = array(); + $cases = []; $tmpName = TempFSFile::factory( "unittests_", 'txt' )->getPath(); $toPath = self::baseStorePath() . '/unittest-cont1/e/fun/obj1.txt'; - $op = array( 'op' => 'store', 'src' => $tmpName, 'dst' => $toPath ); - $cases[] = array( $op ); + $op = [ 'op' => 'store', 'src' => $tmpName, 'dst' => $toPath ]; + $cases[] = [ $op ]; $op2 = $op; $op2['overwrite'] = true; - $cases[] = array( $op2 ); + $cases[] = [ $op2 ]; $op3 = $op; $op3['overwriteSame'] = true; - $cases[] = array( $op3 ); + $cases[] = [ $op3 ]; return $cases; } @@ -305,25 +305,25 @@ class FileBackendTest extends MediaWikiTestCase { $source = $op['src']; $dest = $op['dst']; - $this->prepare( array( 'dir' => dirname( $source ) ) ); - $this->prepare( array( 'dir' => dirname( $dest ) ) ); + $this->prepare( [ 'dir' => dirname( $source ) ] ); + $this->prepare( [ 'dir' => dirname( $dest ) ] ); if ( isset( $op['ignoreMissingSource'] ) ) { $status = $this->backend->doOperation( $op ); $this->assertGoodStatus( $status, "Move from $source to $dest succeeded without warnings ($backendName)." ); - $this->assertEquals( array( 0 => true ), $status->success, + $this->assertEquals( [ 0 => true ], $status->success, "Move from $source to $dest has proper 'success' field in Status ($backendName)." ); - $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $source ) ), + $this->assertEquals( false, $this->backend->fileExists( [ 'src' => $source ] ), "Source file $source does not exist ($backendName)." ); - $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $dest ) ), + $this->assertEquals( false, $this->backend->fileExists( [ 'src' => $dest ] ), "Destination file $dest does not exist ($backendName)." ); return; // done } $status = $this->backend->doOperation( - array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) ); + [ 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ] ); $this->assertGoodStatus( $status, "Creation of file at $source succeeded ($backendName)." ); @@ -337,70 +337,70 @@ class FileBackendTest extends MediaWikiTestCase { "Copy from $source to $dest succeeded without warnings ($backendName)." ); $this->assertEquals( true, $status->isOK(), "Copy from $source to $dest succeeded ($backendName)." ); - $this->assertEquals( array( 0 => true ), $status->success, + $this->assertEquals( [ 0 => true ], $status->success, "Copy from $source to $dest has proper 'success' field in Status ($backendName)." ); - $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $source ) ), + $this->assertEquals( true, $this->backend->fileExists( [ 'src' => $source ] ), "Source file $source still exists ($backendName)." ); - $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ), + $this->assertEquals( true, $this->backend->fileExists( [ 'src' => $dest ] ), "Destination file $dest exists after copy ($backendName)." ); $this->assertEquals( - $this->backend->getFileSize( array( 'src' => $source ) ), - $this->backend->getFileSize( array( 'src' => $dest ) ), + $this->backend->getFileSize( [ 'src' => $source ] ), + $this->backend->getFileSize( [ 'src' => $dest ] ), "Destination file $dest has correct size ($backendName)." ); - $props1 = $this->backend->getFileProps( array( 'src' => $source ) ); - $props2 = $this->backend->getFileProps( array( 'src' => $dest ) ); + $props1 = $this->backend->getFileProps( [ 'src' => $source ] ); + $props2 = $this->backend->getFileProps( [ 'src' => $dest ] ); $this->assertEquals( $props1, $props2, "Source and destination have the same props ($backendName)." ); - $this->assertBackendPathsConsistent( array( $source, $dest ) ); + $this->assertBackendPathsConsistent( [ $source, $dest ] ); } public static function provider_testCopy() { - $cases = array(); + $cases = []; $source = self::baseStorePath() . '/unittest-cont1/e/file.txt'; $dest = self::baseStorePath() . '/unittest-cont2/a/fileMoved.txt'; - $op = array( 'op' => 'copy', 'src' => $source, 'dst' => $dest ); - $cases[] = array( + $op = [ 'op' => 'copy', 'src' => $source, 'dst' => $dest ]; + $cases[] = [ $op, // operation $source, // source $dest, // dest - ); + ]; $op2 = $op; $op2['overwrite'] = true; - $cases[] = array( + $cases[] = [ $op2, // operation $source, // source $dest, // dest - ); + ]; $op2 = $op; $op2['overwriteSame'] = true; - $cases[] = array( + $cases[] = [ $op2, // operation $source, // source $dest, // dest - ); + ]; $op2 = $op; $op2['ignoreMissingSource'] = true; - $cases[] = array( + $cases[] = [ $op2, // operation $source, // source $dest, // dest - ); + ]; $op2 = $op; $op2['ignoreMissingSource'] = true; - $cases[] = array( + $cases[] = [ $op2, // operation self::baseStorePath() . '/unittest-cont-bad/e/file.txt', // source $dest, // dest - ); + ]; return $cases; } @@ -426,25 +426,25 @@ class FileBackendTest extends MediaWikiTestCase { $source = $op['src']; $dest = $op['dst']; - $this->prepare( array( 'dir' => dirname( $source ) ) ); - $this->prepare( array( 'dir' => dirname( $dest ) ) ); + $this->prepare( [ 'dir' => dirname( $source ) ] ); + $this->prepare( [ 'dir' => dirname( $dest ) ] ); if ( isset( $op['ignoreMissingSource'] ) ) { $status = $this->backend->doOperation( $op ); $this->assertGoodStatus( $status, "Move from $source to $dest succeeded without warnings ($backendName)." ); - $this->assertEquals( array( 0 => true ), $status->success, + $this->assertEquals( [ 0 => true ], $status->success, "Move from $source to $dest has proper 'success' field in Status ($backendName)." ); - $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $source ) ), + $this->assertEquals( false, $this->backend->fileExists( [ 'src' => $source ] ), "Source file $source does not exist ($backendName)." ); - $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $dest ) ), + $this->assertEquals( false, $this->backend->fileExists( [ 'src' => $dest ] ), "Destination file $dest does not exist ($backendName)." ); return; // done } $status = $this->backend->doOperation( - array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) ); + [ 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ] ); $this->assertGoodStatus( $status, "Creation of file at $source succeeded ($backendName)." ); @@ -457,72 +457,72 @@ class FileBackendTest extends MediaWikiTestCase { "Move from $source to $dest succeeded without warnings ($backendName)." ); $this->assertEquals( true, $status->isOK(), "Move from $source to $dest succeeded ($backendName)." ); - $this->assertEquals( array( 0 => true ), $status->success, + $this->assertEquals( [ 0 => true ], $status->success, "Move from $source to $dest has proper 'success' field in Status ($backendName)." ); - $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $source ) ), + $this->assertEquals( false, $this->backend->fileExists( [ 'src' => $source ] ), "Source file $source does not still exists ($backendName)." ); - $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ), + $this->assertEquals( true, $this->backend->fileExists( [ 'src' => $dest ] ), "Destination file $dest exists after move ($backendName)." ); $this->assertNotEquals( - $this->backend->getFileSize( array( 'src' => $source ) ), - $this->backend->getFileSize( array( 'src' => $dest ) ), + $this->backend->getFileSize( [ 'src' => $source ] ), + $this->backend->getFileSize( [ 'src' => $dest ] ), "Destination file $dest has correct size ($backendName)." ); - $props1 = $this->backend->getFileProps( array( 'src' => $source ) ); - $props2 = $this->backend->getFileProps( array( 'src' => $dest ) ); + $props1 = $this->backend->getFileProps( [ 'src' => $source ] ); + $props2 = $this->backend->getFileProps( [ 'src' => $dest ] ); $this->assertEquals( false, $props1['fileExists'], "Source file does not exist accourding to props ($backendName)." ); $this->assertEquals( true, $props2['fileExists'], "Destination file exists accourding to props ($backendName)." ); - $this->assertBackendPathsConsistent( array( $source, $dest ) ); + $this->assertBackendPathsConsistent( [ $source, $dest ] ); } public static function provider_testMove() { - $cases = array(); + $cases = []; $source = self::baseStorePath() . '/unittest-cont1/e/file.txt'; $dest = self::baseStorePath() . '/unittest-cont2/a/fileMoved.txt'; - $op = array( 'op' => 'move', 'src' => $source, 'dst' => $dest ); - $cases[] = array( + $op = [ 'op' => 'move', 'src' => $source, 'dst' => $dest ]; + $cases[] = [ $op, // operation $source, // source $dest, // dest - ); + ]; $op2 = $op; $op2['overwrite'] = true; - $cases[] = array( + $cases[] = [ $op2, // operation $source, // source $dest, // dest - ); + ]; $op2 = $op; $op2['overwriteSame'] = true; - $cases[] = array( + $cases[] = [ $op2, // operation $source, // source $dest, // dest - ); + ]; $op2 = $op; $op2['ignoreMissingSource'] = true; - $cases[] = array( + $cases[] = [ $op2, // operation $source, // source $dest, // dest - ); + ]; $op2 = $op; $op2['ignoreMissingSource'] = true; - $cases[] = array( + $cases[] = [ $op2, // operation self::baseStorePath() . '/unittest-cont-bad/e/file.txt', // source $dest, // dest - ); + ]; return $cases; } @@ -547,11 +547,11 @@ class FileBackendTest extends MediaWikiTestCase { $backendName = $this->backendClass(); $source = $op['src']; - $this->prepare( array( 'dir' => dirname( $source ) ) ); + $this->prepare( [ 'dir' => dirname( $source ) ] ); if ( $withSource ) { $status = $this->backend->doOperation( - array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) ); + [ 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ] ); $this->assertGoodStatus( $status, "Creation of file at $source succeeded ($backendName)." ); } @@ -562,59 +562,59 @@ class FileBackendTest extends MediaWikiTestCase { "Deletion of file at $source succeeded without warnings ($backendName)." ); $this->assertEquals( true, $status->isOK(), "Deletion of file at $source succeeded ($backendName)." ); - $this->assertEquals( array( 0 => true ), $status->success, + $this->assertEquals( [ 0 => true ], $status->success, "Deletion of file at $source has proper 'success' field in Status ($backendName)." ); } else { $this->assertEquals( false, $status->isOK(), "Deletion of file at $source failed ($backendName)." ); } - $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $source ) ), + $this->assertEquals( false, $this->backend->fileExists( [ 'src' => $source ] ), "Source file $source does not exist after move ($backendName)." ); $this->assertFalse( - $this->backend->getFileSize( array( 'src' => $source ) ), + $this->backend->getFileSize( [ 'src' => $source ] ), "Source file $source has correct size (false) ($backendName)." ); - $props1 = $this->backend->getFileProps( array( 'src' => $source ) ); + $props1 = $this->backend->getFileProps( [ 'src' => $source ] ); $this->assertFalse( $props1['fileExists'], "Source file $source does not exist according to props ($backendName)." ); - $this->assertBackendPathsConsistent( array( $source ) ); + $this->assertBackendPathsConsistent( [ $source ] ); } public static function provider_testDelete() { - $cases = array(); + $cases = []; $source = self::baseStorePath() . '/unittest-cont1/e/myfacefile.txt'; - $op = array( 'op' => 'delete', 'src' => $source ); - $cases[] = array( + $op = [ 'op' => 'delete', 'src' => $source ]; + $cases[] = [ $op, // operation true, // with source true // succeeds - ); + ]; - $cases[] = array( + $cases[] = [ $op, // operation false, // without source false // fails - ); + ]; $op['ignoreMissingSource'] = true; - $cases[] = array( + $cases[] = [ $op, // operation false, // without source true // succeeds - ); + ]; $op['ignoreMissingSource'] = true; $op['src'] = self::baseStorePath() . '/unittest-cont-bad/e/file.txt'; - $cases[] = array( + $cases[] = [ $op, // operation false, // without source true // succeeds - ); + ]; return $cases; } @@ -639,26 +639,26 @@ class FileBackendTest extends MediaWikiTestCase { $backendName = $this->backendClass(); $source = $op['src']; - $this->prepare( array( 'dir' => dirname( $source ) ) ); + $this->prepare( [ 'dir' => dirname( $source ) ] ); if ( $withSource ) { $status = $this->backend->doOperation( - array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source, - 'headers' => array( 'Content-Disposition' => 'xxx' ) ) ); + [ 'op' => 'create', 'content' => 'blahblah', 'dst' => $source, + 'headers' => [ 'Content-Disposition' => 'xxx' ] ] ); $this->assertGoodStatus( $status, "Creation of file at $source succeeded ($backendName)." ); if ( $this->backend->hasFeatures( FileBackend::ATTR_HEADERS ) ) { - $attr = $this->backend->getFileXAttributes( array( 'src' => $source ) ); - $this->assertHasHeaders( array( 'Content-Disposition' => 'xxx' ), $attr ); + $attr = $this->backend->getFileXAttributes( [ 'src' => $source ] ); + $this->assertHasHeaders( [ 'Content-Disposition' => 'xxx' ], $attr ); } - $status = $this->backend->describe( array( 'src' => $source, - 'headers' => array( 'Content-Disposition' => '' ) ) ); // remove + $status = $this->backend->describe( [ 'src' => $source, + 'headers' => [ 'Content-Disposition' => '' ] ] ); // remove $this->assertGoodStatus( $status, "Removal of header for $source succeeded ($backendName)." ); if ( $this->backend->hasFeatures( FileBackend::ATTR_HEADERS ) ) { - $attr = $this->backend->getFileXAttributes( array( 'src' => $source ) ); + $attr = $this->backend->getFileXAttributes( [ 'src' => $source ] ); $this->assertFalse( isset( $attr['headers']['content-disposition'] ), "File 'Content-Disposition' header removed." ); } @@ -670,10 +670,10 @@ class FileBackendTest extends MediaWikiTestCase { "Describe of file at $source succeeded without warnings ($backendName)." ); $this->assertEquals( true, $status->isOK(), "Describe of file at $source succeeded ($backendName)." ); - $this->assertEquals( array( 0 => true ), $status->success, + $this->assertEquals( [ 0 => true ], $status->success, "Describe of file at $source has proper 'success' field in Status ($backendName)." ); if ( $this->backend->hasFeatures( FileBackend::ATTR_HEADERS ) ) { - $attr = $this->backend->getFileXAttributes( array( 'src' => $source ) ); + $attr = $this->backend->getFileXAttributes( [ 'src' => $source ] ); $this->assertHasHeaders( $op['headers'], $attr ); } } else { @@ -681,7 +681,7 @@ class FileBackendTest extends MediaWikiTestCase { "Describe of file at $source failed ($backendName)." ); } - $this->assertBackendPathsConsistent( array( $source ) ); + $this->assertBackendPathsConsistent( [ $source ] ); } private function assertHasHeaders( array $headers, array $attr ) { @@ -699,23 +699,23 @@ class FileBackendTest extends MediaWikiTestCase { } public static function provider_testDescribe() { - $cases = array(); + $cases = []; $source = self::baseStorePath() . '/unittest-cont1/e/myfacefile.txt'; - $op = array( 'op' => 'describe', 'src' => $source, - 'headers' => array( 'Content-Disposition' => 'inline' ), ); - $cases[] = array( + $op = [ 'op' => 'describe', 'src' => $source, + 'headers' => [ 'Content-Disposition' => 'inline' ], ]; + $cases[] = [ $op, // operation true, // with source true // succeeds - ); + ]; - $cases[] = array( + $cases[] = [ $op, // operation false, // without source false // fails - ); + ]; return $cases; } @@ -740,12 +740,12 @@ class FileBackendTest extends MediaWikiTestCase { $backendName = $this->backendClass(); $dest = $op['dst']; - $this->prepare( array( 'dir' => dirname( $dest ) ) ); + $this->prepare( [ 'dir' => dirname( $dest ) ] ); $oldText = 'blah...blah...waahwaah'; if ( $alreadyExists ) { $status = $this->backend->doOperation( - array( 'op' => 'create', 'content' => $oldText, 'dst' => $dest ) ); + [ 'op' => 'create', 'content' => $oldText, 'dst' => $dest ] ); $this->assertGoodStatus( $status, "Creation of file at $dest succeeded ($backendName)." ); } @@ -756,89 +756,89 @@ class FileBackendTest extends MediaWikiTestCase { "Creation of file at $dest succeeded without warnings ($backendName)." ); $this->assertEquals( true, $status->isOK(), "Creation of file at $dest succeeded ($backendName)." ); - $this->assertEquals( array( 0 => true ), $status->success, + $this->assertEquals( [ 0 => true ], $status->success, "Creation of file at $dest has proper 'success' field in Status ($backendName)." ); } else { $this->assertEquals( false, $status->isOK(), "Creation of file at $dest failed ($backendName)." ); } - $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ), + $this->assertEquals( true, $this->backend->fileExists( [ 'src' => $dest ] ), "Destination file $dest exists after creation ($backendName)." ); - $props1 = $this->backend->getFileProps( array( 'src' => $dest ) ); + $props1 = $this->backend->getFileProps( [ 'src' => $dest ] ); $this->assertEquals( true, $props1['fileExists'], "Destination file $dest exists according to props ($backendName)." ); if ( $okStatus ) { // file content is what we saved $this->assertEquals( $newSize, $props1['size'], "Destination file $dest has expected size according to props ($backendName)." ); $this->assertEquals( $newSize, - $this->backend->getFileSize( array( 'src' => $dest ) ), + $this->backend->getFileSize( [ 'src' => $dest ] ), "Destination file $dest has correct size ($backendName)." ); } else { // file content is some other previous text $this->assertEquals( strlen( $oldText ), $props1['size'], "Destination file $dest has original size according to props ($backendName)." ); $this->assertEquals( strlen( $oldText ), - $this->backend->getFileSize( array( 'src' => $dest ) ), + $this->backend->getFileSize( [ 'src' => $dest ] ), "Destination file $dest has original size according to props ($backendName)." ); } - $this->assertBackendPathsConsistent( array( $dest ) ); + $this->assertBackendPathsConsistent( [ $dest ] ); } /** * @dataProvider provider_testCreate */ public static function provider_testCreate() { - $cases = array(); + $cases = []; $dest = self::baseStorePath() . '/unittest-cont2/a/myspacefile.txt'; - $op = array( 'op' => 'create', 'content' => 'test test testing', 'dst' => $dest ); - $cases[] = array( + $op = [ 'op' => 'create', 'content' => 'test test testing', 'dst' => $dest ]; + $cases[] = [ $op, // operation false, // no dest already exists true, // succeeds strlen( $op['content'] ) - ); + ]; $op2 = $op; $op2['content'] = "\n"; - $cases[] = array( + $cases[] = [ $op2, // operation false, // no dest already exists true, // succeeds strlen( $op2['content'] ) - ); + ]; $op2 = $op; $op2['content'] = "fsf\n waf 3kt"; - $cases[] = array( + $cases[] = [ $op2, // operation true, // dest already exists false, // fails strlen( $op2['content'] ) - ); + ]; $op2 = $op; $op2['content'] = "egm'g gkpe gpqg eqwgwqg"; $op2['overwrite'] = true; - $cases[] = array( + $cases[] = [ $op2, // operation true, // dest already exists true, // succeeds strlen( $op2['content'] ) - ); + ]; $op2 = $op; $op2['content'] = "39qjmg3-qg"; $op2['overwriteSame'] = true; - $cases[] = array( + $cases[] = [ $op2, // operation true, // dest already exists false, // succeeds strlen( $op2['content'] ) - ); + ]; return $cases; } @@ -860,30 +860,30 @@ class FileBackendTest extends MediaWikiTestCase { $backendName = $this->backendClass(); $base = self::baseStorePath(); - $files = array( + $files = [ "$base/unittest-cont1/e/fileA.a", "$base/unittest-cont1/e/fileB.a", "$base/unittest-cont1/e/fileC.a" - ); - $createOps = array(); - $purgeOps = array(); + ]; + $createOps = []; + $purgeOps = []; foreach ( $files as $path ) { - $status = $this->prepare( array( 'dir' => dirname( $path ) ) ); + $status = $this->prepare( [ 'dir' => dirname( $path ) ] ); $this->assertGoodStatus( $status, "Preparing $path succeeded without warnings ($backendName)." ); - $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" ); + $createOps[] = [ 'op' => 'create', 'dst' => $path, 'content' => mt_rand( 0, 50000 ) ]; + $copyOps[] = [ 'op' => 'copy', 'src' => $path, 'dst' => "$path-2" ]; + $moveOps[] = [ 'op' => 'move', 'src' => "$path-2", 'dst' => "$path-3" ]; + $purgeOps[] = [ 'op' => 'delete', 'src' => $path ]; + $purgeOps[] = [ 'op' => 'delete', 'src' => "$path-3" ]; } - $purgeOps[] = array( 'op' => 'null' ); + $purgeOps[] = [ 'op' => 'null' ]; $this->assertGoodStatus( $this->backend->doQuickOperations( $createOps ), "Creation of source files succeeded ($backendName)." ); foreach ( $files as $file ) { - $this->assertTrue( $this->backend->fileExists( array( 'src' => $file ) ), + $this->assertTrue( $this->backend->fileExists( [ 'src' => $file ] ), "File $file exists." ); } @@ -891,7 +891,7 @@ class FileBackendTest extends MediaWikiTestCase { $this->backend->doQuickOperations( $copyOps ), "Quick copy of source files succeeded ($backendName)." ); foreach ( $files as $file ) { - $this->assertTrue( $this->backend->fileExists( array( 'src' => "$file-2" ) ), + $this->assertTrue( $this->backend->fileExists( [ 'src' => "$file-2" ] ), "File $file-2 exists." ); } @@ -899,31 +899,31 @@ class FileBackendTest extends MediaWikiTestCase { $this->backend->doQuickOperations( $moveOps ), "Quick move of source files succeeded ($backendName)." ); foreach ( $files as $file ) { - $this->assertTrue( $this->backend->fileExists( array( 'src' => "$file-3" ) ), + $this->assertTrue( $this->backend->fileExists( [ 'src' => "$file-3" ] ), "File $file-3 move in." ); - $this->assertFalse( $this->backend->fileExists( array( 'src' => "$file-2" ) ), + $this->assertFalse( $this->backend->fileExists( [ 'src' => "$file-2" ] ), "File $file-2 moved away." ); } $this->assertGoodStatus( - $this->backend->quickCopy( array( 'src' => $files[0], 'dst' => $files[0] ) ), + $this->backend->quickCopy( [ 'src' => $files[0], 'dst' => $files[0] ] ), "Copy of file {$files[0]} over itself succeeded ($backendName)." ); - $this->assertTrue( $this->backend->fileExists( array( 'src' => $files[0] ) ), + $this->assertTrue( $this->backend->fileExists( [ 'src' => $files[0] ] ), "File {$files[0]} still exists." ); $this->assertGoodStatus( - $this->backend->quickMove( array( 'src' => $files[0], 'dst' => $files[0] ) ), + $this->backend->quickMove( [ 'src' => $files[0], 'dst' => $files[0] ] ), "Move of file {$files[0]} over itself succeeded ($backendName)." ); - $this->assertTrue( $this->backend->fileExists( array( 'src' => $files[0] ) ), + $this->assertTrue( $this->backend->fileExists( [ '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 ) ), + $this->assertFalse( $this->backend->fileExists( [ 'src' => $file ] ), "File $file purged." ); - $this->assertFalse( $this->backend->fileExists( array( 'src' => "$file-3" ) ), + $this->assertFalse( $this->backend->fileExists( [ 'src' => "$file-3" ] ), "File $file-3 purged." ); } } @@ -948,14 +948,14 @@ class FileBackendTest extends MediaWikiTestCase { $expContent = ''; // Create sources - $ops = array(); + $ops = []; foreach ( $srcs as $i => $source ) { - $this->prepare( array( 'dir' => dirname( $source ) ) ); - $ops[] = array( + $this->prepare( [ 'dir' => dirname( $source ) ] ); + $ops[] = [ 'op' => 'create', // operation 'dst' => $source, // source 'content' => $srcsContent[$i] - ); + ]; $expContent .= $srcsContent[$i]; } $status = $this->backend->doOperations( $ops ); @@ -1007,9 +1007,9 @@ class FileBackendTest extends MediaWikiTestCase { } public static function provider_testConcatenate() { - $cases = array(); + $cases = []; - $srcs = array( + $srcs = [ self::baseStorePath() . '/unittest-cont1/e/file1.txt', self::baseStorePath() . '/unittest-cont1/e/file2.txt', self::baseStorePath() . '/unittest-cont1/e/file3.txt', @@ -1020,8 +1020,8 @@ class FileBackendTest extends MediaWikiTestCase { self::baseStorePath() . '/unittest-cont1/e/file8.txt', self::baseStorePath() . '/unittest-cont1/e/file9.txt', self::baseStorePath() . '/unittest-cont1/e/file10.txt' - ); - $content = array( + ]; + $content = [ 'egfage', 'ageageag', 'rhokohlr', @@ -1032,24 +1032,24 @@ class FileBackendTest extends MediaWikiTestCase { 'g eak;g', 'lkaem;a', 'legma' - ); - $params = array( 'srcs' => $srcs ); + ]; + $params = [ 'srcs' => $srcs ]; - $cases[] = array( + $cases[] = [ $params, // operation $srcs, // sources $content, // content for each source false, // no dest already exists true, // succeeds - ); + ]; - $cases[] = array( + $cases[] = [ $params, // operation $srcs, // sources $content, // content for each source true, // dest already exists false, // succeeds - ); + ]; return $cases; } @@ -1074,14 +1074,14 @@ class FileBackendTest extends MediaWikiTestCase { $backendName = $this->backendClass(); if ( $alreadyExists ) { - $this->prepare( array( 'dir' => dirname( $path ) ) ); - $status = $this->create( array( 'dst' => $path, 'content' => $content ) ); + $this->prepare( [ 'dir' => dirname( $path ) ] ); + $status = $this->create( [ 'dst' => $path, 'content' => $content ] ); $this->assertGoodStatus( $status, "Creation of file at $path succeeded ($backendName)." ); - $size = $this->backend->getFileSize( array( 'src' => $path ) ); - $time = $this->backend->getFileTimestamp( array( 'src' => $path ) ); - $stat = $this->backend->getFileStat( array( 'src' => $path ) ); + $size = $this->backend->getFileSize( [ 'src' => $path ] ); + $time = $this->backend->getFileTimestamp( [ 'src' => $path ] ); + $stat = $this->backend->getFileStat( [ 'src' => $path ] ); $this->assertEquals( strlen( $content ), $size, "Correct file size of '$path'" ); @@ -1095,23 +1095,23 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertTrue( abs( time() - wfTimestamp( TS_UNIX, $time ) ) < 10, "Correct file timestamp of '$path'" ); - $this->backend->clearCache( array( $path ) ); + $this->backend->clearCache( [ $path ] ); - $size = $this->backend->getFileSize( array( 'src' => $path ) ); + $size = $this->backend->getFileSize( [ 'src' => $path ] ); $this->assertEquals( strlen( $content ), $size, "Correct file size of '$path'" ); - $this->backend->preloadCache( array( $path ) ); + $this->backend->preloadCache( [ $path ] ); - $size = $this->backend->getFileSize( array( 'src' => $path ) ); + $size = $this->backend->getFileSize( [ 'src' => $path ] ); $this->assertEquals( strlen( $content ), $size, "Correct file size of '$path'" ); } else { - $size = $this->backend->getFileSize( array( 'src' => $path ) ); - $time = $this->backend->getFileTimestamp( array( 'src' => $path ) ); - $stat = $this->backend->getFileStat( array( 'src' => $path ) ); + $size = $this->backend->getFileSize( [ 'src' => $path ] ); + $time = $this->backend->getFileTimestamp( [ 'src' => $path ] ); + $stat = $this->backend->getFileStat( [ 'src' => $path ] ); $this->assertFalse( $size, "Correct file size of '$path'" ); $this->assertFalse( $time, "Correct file timestamp of '$path'" ); @@ -1120,12 +1120,12 @@ class FileBackendTest extends MediaWikiTestCase { } public static function provider_testGetFileStat() { - $cases = array(); + $cases = []; $base = self::baseStorePath(); - $cases[] = array( "$base/unittest-cont1/e/b/z/some_file.txt", "some file contents", true ); - $cases[] = array( "$base/unittest-cont1/e/b/some-other_file.txt", "", true ); - $cases[] = array( "$base/unittest-cont1/e/b/some-diff_file.txt", null, false ); + $cases[] = [ "$base/unittest-cont1/e/b/z/some_file.txt", "some file contents", true ]; + $cases[] = [ "$base/unittest-cont1/e/b/some-other_file.txt", "", true ]; + $cases[] = [ "$base/unittest-cont1/e/b/some-diff_file.txt", null, false ]; return $cases; } @@ -1150,20 +1150,20 @@ class FileBackendTest extends MediaWikiTestCase { $method->setAccessible( true ); if ( $content !== null ) { - $this->prepare( array( 'dir' => dirname( $path ) ) ); - $status = $this->create( array( 'dst' => $path, 'content' => $content ) ); + $this->prepare( [ 'dir' => dirname( $path ) ] ); + $status = $this->create( [ 'dst' => $path, 'content' => $content ] ); $this->assertGoodStatus( $status, "Creation of file at $path succeeded ($backendName)." ); ob_start(); - $method->invokeArgs( $this->backend, array( array( 'src' => $path ) ) ); + $method->invokeArgs( $this->backend, [ [ 'src' => $path ] ] ); $data = ob_get_contents(); ob_end_clean(); $this->assertEquals( $content, $data, "Correct content streamed from '$path'" ); } else { // 404 case ob_start(); - $method->invokeArgs( $this->backend, array( array( 'src' => $path ) ) ); + $method->invokeArgs( $this->backend, [ [ 'src' => $path ] ] ); $data = ob_get_contents(); ob_end_clean(); @@ -1172,11 +1172,11 @@ class FileBackendTest extends MediaWikiTestCase { } public static function provider_testStreamFile() { - $cases = array(); + $cases = []; $base = self::baseStorePath(); - $cases[] = array( "$base/unittest-cont1/e/b/z/some_file.txt", "some file contents" ); - $cases[] = array( "$base/unittest-cont1/e/b/some-other_file.txt", null ); + $cases[] = [ "$base/unittest-cont1/e/b/z/some_file.txt", "some file contents" ]; + $cases[] = [ "$base/unittest-cont1/e/b/some-other_file.txt", null ]; return $cases; } @@ -1204,15 +1204,15 @@ class FileBackendTest extends MediaWikiTestCase { $srcs = (array)$source; $content = (array)$content; foreach ( $srcs as $i => $src ) { - $this->prepare( array( 'dir' => dirname( $src ) ) ); + $this->prepare( [ 'dir' => dirname( $src ) ] ); $status = $this->backend->doOperation( - array( 'op' => 'create', 'content' => $content[$i], 'dst' => $src ) ); + [ 'op' => 'create', 'content' => $content[$i], 'dst' => $src ] ); $this->assertGoodStatus( $status, "Creation of file at $src succeeded ($backendName)." ); } if ( is_array( $source ) ) { - $contents = $this->backend->getFileContentsMulti( array( 'srcs' => $source ) ); + $contents = $this->backend->getFileContentsMulti( [ 'srcs' => $source ] ); foreach ( $contents as $path => $data ) { $this->assertNotEquals( false, $data, "Contents of $path exists ($backendName)." ); $this->assertEquals( @@ -1233,23 +1233,23 @@ class FileBackendTest extends MediaWikiTestCase { "Contents array size correct ($backendName)." ); } else { - $data = $this->backend->getFileContents( array( 'src' => $source ) ); + $data = $this->backend->getFileContents( [ 'src' => $source ] ); $this->assertNotEquals( false, $data, "Contents of $source exists ($backendName)." ); $this->assertEquals( $content[0], $data, "Contents of $source is correct ($backendName)." ); } } public static function provider_testGetFileContents() { - $cases = array(); + $cases = []; $base = self::baseStorePath(); - $cases[] = array( "$base/unittest-cont1/e/b/z/some_file.txt", "some file contents" ); - $cases[] = array( "$base/unittest-cont1/e/b/some-other_file.txt", "more file contents" ); - $cases[] = array( - array( "$base/unittest-cont1/e/a/x.txt", "$base/unittest-cont1/e/a/y.txt", - "$base/unittest-cont1/e/a/z.txt" ), - array( "contents xx", "contents xy", "contents xz" ) - ); + $cases[] = [ "$base/unittest-cont1/e/b/z/some_file.txt", "some file contents" ]; + $cases[] = [ "$base/unittest-cont1/e/b/some-other_file.txt", "more file contents" ]; + $cases[] = [ + [ "$base/unittest-cont1/e/a/x.txt", "$base/unittest-cont1/e/a/y.txt", + "$base/unittest-cont1/e/a/z.txt" ], + [ "contents xx", "contents xy", "contents xz" ] + ]; return $cases; } @@ -1276,15 +1276,15 @@ class FileBackendTest extends MediaWikiTestCase { $srcs = (array)$source; $content = (array)$content; foreach ( $srcs as $i => $src ) { - $this->prepare( array( 'dir' => dirname( $src ) ) ); + $this->prepare( [ 'dir' => dirname( $src ) ] ); $status = $this->backend->doOperation( - array( 'op' => 'create', 'content' => $content[$i], 'dst' => $src ) ); + [ 'op' => 'create', 'content' => $content[$i], 'dst' => $src ] ); $this->assertGoodStatus( $status, "Creation of file at $src succeeded ($backendName)." ); } if ( is_array( $source ) ) { - $tmpFiles = $this->backend->getLocalCopyMulti( array( 'srcs' => $source ) ); + $tmpFiles = $this->backend->getLocalCopyMulti( [ 'srcs' => $source ] ); foreach ( $tmpFiles as $path => $tmpFile ) { $this->assertNotNull( $tmpFile, "Creation of local copy of $path succeeded ($backendName)." ); @@ -1308,7 +1308,7 @@ class FileBackendTest extends MediaWikiTestCase { "Local copies array size correct ($backendName)." ); } else { - $tmpFile = $this->backend->getLocalCopy( array( 'src' => $source ) ); + $tmpFile = $this->backend->getLocalCopy( [ 'src' => $source ] ); $this->assertNotNull( $tmpFile, "Creation of local copy of $source succeeded ($backendName)." ); $contents = file_get_contents( $tmpFile->getPath() ); @@ -1325,17 +1325,17 @@ class FileBackendTest extends MediaWikiTestCase { } public static function provider_testGetLocalCopy() { - $cases = array(); + $cases = []; $base = self::baseStorePath(); - $cases[] = array( "$base/unittest-cont1/e/a/z/some_file.txt", "some file contents" ); - $cases[] = array( "$base/unittest-cont1/e/a/some-other_file.txt", "more file contents" ); - $cases[] = array( "$base/unittest-cont1/e/a/\$odd&.txt", "test file contents" ); - $cases[] = array( - array( "$base/unittest-cont1/e/a/x.txt", "$base/unittest-cont1/e/a/y.txt", - "$base/unittest-cont1/e/a/z.txt" ), - array( "contents xx $", "contents xy 111", "contents xz" ) - ); + $cases[] = [ "$base/unittest-cont1/e/a/z/some_file.txt", "some file contents" ]; + $cases[] = [ "$base/unittest-cont1/e/a/some-other_file.txt", "more file contents" ]; + $cases[] = [ "$base/unittest-cont1/e/a/\$odd&.txt", "test file contents" ]; + $cases[] = [ + [ "$base/unittest-cont1/e/a/x.txt", "$base/unittest-cont1/e/a/y.txt", + "$base/unittest-cont1/e/a/z.txt" ], + [ "contents xx $", "contents xy 111", "contents xz" ] + ]; return $cases; } @@ -1362,15 +1362,15 @@ class FileBackendTest extends MediaWikiTestCase { $srcs = (array)$source; $content = (array)$content; foreach ( $srcs as $i => $src ) { - $this->prepare( array( 'dir' => dirname( $src ) ) ); + $this->prepare( [ 'dir' => dirname( $src ) ] ); $status = $this->backend->doOperation( - array( 'op' => 'create', 'content' => $content[$i], 'dst' => $src ) ); + [ 'op' => 'create', 'content' => $content[$i], 'dst' => $src ] ); $this->assertGoodStatus( $status, "Creation of file at $src succeeded ($backendName)." ); } if ( is_array( $source ) ) { - $tmpFiles = $this->backend->getLocalReferenceMulti( array( 'srcs' => $source ) ); + $tmpFiles = $this->backend->getLocalReferenceMulti( [ 'srcs' => $source ] ); foreach ( $tmpFiles as $path => $tmpFile ) { $this->assertNotNull( $tmpFile, "Creation of local copy of $path succeeded ($backendName)." ); @@ -1394,7 +1394,7 @@ class FileBackendTest extends MediaWikiTestCase { "Local refs array size correct ($backendName)." ); } else { - $tmpFile = $this->backend->getLocalReference( array( 'src' => $source ) ); + $tmpFile = $this->backend->getLocalReference( [ 'src' => $source ] ); $this->assertNotNull( $tmpFile, "Creation of local copy of $source succeeded ($backendName)." ); $contents = file_get_contents( $tmpFile->getPath() ); @@ -1404,17 +1404,17 @@ class FileBackendTest extends MediaWikiTestCase { } public static function provider_testGetLocalReference() { - $cases = array(); + $cases = []; $base = self::baseStorePath(); - $cases[] = array( "$base/unittest-cont1/e/a/z/some_file.txt", "some file contents" ); - $cases[] = array( "$base/unittest-cont1/e/a/some-other_file.txt", "more file contents" ); - $cases[] = array( "$base/unittest-cont1/e/a/\$odd&.txt", "test file contents" ); - $cases[] = array( - array( "$base/unittest-cont1/e/a/x.txt", "$base/unittest-cont1/e/a/y.txt", - "$base/unittest-cont1/e/a/z.txt" ), - array( "contents xx 1111", "contents xy %", "contents xz $" ) - ); + $cases[] = [ "$base/unittest-cont1/e/a/z/some_file.txt", "some file contents" ]; + $cases[] = [ "$base/unittest-cont1/e/a/some-other_file.txt", "more file contents" ]; + $cases[] = [ "$base/unittest-cont1/e/a/\$odd&.txt", "test file contents" ]; + $cases[] = [ + [ "$base/unittest-cont1/e/a/x.txt", "$base/unittest-cont1/e/a/y.txt", + "$base/unittest-cont1/e/a/z.txt" ], + [ "contents xx 1111", "contents xy %", "contents xz $" ] + ]; return $cases; } @@ -1440,12 +1440,12 @@ class FileBackendTest extends MediaWikiTestCase { $base = self::baseStorePath(); - $tmpFile = $this->backend->getLocalCopy( array( - 'src' => "$base/unittest-cont1/not-there" ) ); + $tmpFile = $this->backend->getLocalCopy( [ + 'src' => "$base/unittest-cont1/not-there" ] ); $this->assertEquals( null, $tmpFile, "Local copy of not existing file is null ($backendName)." ); - $tmpFile = $this->backend->getLocalReference( array( - 'src' => "$base/unittest-cont1/not-there" ) ); + $tmpFile = $this->backend->getLocalReference( [ + 'src' => "$base/unittest-cont1/not-there" ] ); $this->assertEquals( null, $tmpFile, "Local ref of not existing file is null ($backendName)." ); } @@ -1468,28 +1468,28 @@ class FileBackendTest extends MediaWikiTestCase { private function doTestGetFileHttpUrl( $source, $content ) { $backendName = $this->backendClass(); - $this->prepare( array( 'dir' => dirname( $source ) ) ); + $this->prepare( [ 'dir' => dirname( $source ) ] ); $status = $this->backend->doOperation( - array( 'op' => 'create', 'content' => $content, 'dst' => $source ) ); + [ 'op' => 'create', 'content' => $content, 'dst' => $source ] ); $this->assertGoodStatus( $status, "Creation of file at $source succeeded ($backendName)." ); - $url = $this->backend->getFileHttpUrl( array( 'src' => $source ) ); + $url = $this->backend->getFileHttpUrl( [ 'src' => $source ] ); if ( $url !== null ) { // supported - $data = Http::request( "GET", $url, array(), __METHOD__ ); + $data = Http::request( "GET", $url, [], __METHOD__ ); $this->assertEquals( $content, $data, "HTTP GET of URL has right contents ($backendName)." ); } } public static function provider_testGetFileHttpUrl() { - $cases = array(); + $cases = []; $base = self::baseStorePath(); - $cases[] = array( "$base/unittest-cont1/e/a/z/some_file.txt", "some file contents" ); - $cases[] = array( "$base/unittest-cont1/e/a/some-other_file.txt", "more file contents" ); - $cases[] = array( "$base/unittest-cont1/e/a/\$odd&.txt", "test file contents" ); + $cases[] = [ "$base/unittest-cont1/e/a/z/some_file.txt", "some file contents" ]; + $cases[] = [ "$base/unittest-cont1/e/a/some-other_file.txt", "more file contents" ]; + $cases[] = [ "$base/unittest-cont1/e/a/\$odd&.txt", "test file contents" ]; return $cases; } @@ -1512,18 +1512,18 @@ class FileBackendTest extends MediaWikiTestCase { 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 ), + return [ + [ "$base/unittest-cont1/e/a/z/some_file1.txt", true ], + [ "$base/unittest-cont2/a/z/some_file2.txt", true ], # Specific to FS backend with no basePath field set # array( "$base/unittest-cont3/a/z/some_file3.txt", false ), - ); + ]; } private function doTestPrepareAndClean( $path, $isOK ) { $backendName = $this->backendClass(); - $status = $this->prepare( array( 'dir' => dirname( $path ) ) ); + $status = $this->prepare( [ 'dir' => dirname( $path ) ] ); if ( $isOK ) { $this->assertGoodStatus( $status, "Preparing dir $path succeeded without warnings ($backendName)." ); @@ -1534,7 +1534,7 @@ class FileBackendTest extends MediaWikiTestCase { "Preparing dir $path failed ($backendName)." ); } - $status = $this->backend->secure( array( 'dir' => dirname( $path ) ) ); + $status = $this->backend->secure( [ 'dir' => dirname( $path ) ] ); if ( $isOK ) { $this->assertGoodStatus( $status, "Securing dir $path succeeded without warnings ($backendName)." ); @@ -1545,7 +1545,7 @@ class FileBackendTest extends MediaWikiTestCase { "Securing dir $path failed ($backendName)." ); } - $status = $this->backend->publish( array( 'dir' => dirname( $path ) ) ); + $status = $this->backend->publish( [ 'dir' => dirname( $path ) ] ); if ( $isOK ) { $this->assertGoodStatus( $status, "Publishing dir $path succeeded without warnings ($backendName)." ); @@ -1556,7 +1556,7 @@ class FileBackendTest extends MediaWikiTestCase { "Publishing dir $path failed ($backendName)." ); } - $status = $this->backend->clean( array( 'dir' => dirname( $path ) ) ); + $status = $this->backend->clean( [ 'dir' => dirname( $path ) ] ); if ( $isOK ) { $this->assertGoodStatus( $status, "Cleaning dir $path succeeded without warnings ($backendName)." ); @@ -1585,7 +1585,7 @@ class FileBackendTest extends MediaWikiTestCase { $backendName = $this->backendClass(); $base = self::baseStorePath(); - $dirs = array( + $dirs = [ "$base/unittest-cont1", "$base/unittest-cont1/e", "$base/unittest-cont1/e/a", @@ -1600,27 +1600,27 @@ class FileBackendTest extends MediaWikiTestCase { "$base/unittest-cont1/e/a/b/c/d1/4", "$base/unittest-cont1/e/a/b/c/d2/5", "$base/unittest-cont1/e/a/b/c/d2/6" - ); + ]; foreach ( $dirs as $dir ) { - $status = $this->prepare( array( 'dir' => $dir ) ); + $status = $this->prepare( [ 'dir' => $dir ] ); $this->assertGoodStatus( $status, "Preparing dir $dir succeeded without warnings ($backendName)." ); } if ( $this->backend instanceof FSFileBackend ) { foreach ( $dirs as $dir ) { - $this->assertEquals( true, $this->backend->directoryExists( array( 'dir' => $dir ) ), + $this->assertEquals( true, $this->backend->directoryExists( [ 'dir' => $dir ] ), "Dir $dir exists ($backendName)." ); } } $status = $this->backend->clean( - array( 'dir' => "$base/unittest-cont1", 'recursive' => 1 ) ); + [ 'dir' => "$base/unittest-cont1", 'recursive' => 1 ] ); $this->assertGoodStatus( $status, "Recursive cleaning of dir $dir succeeded without warnings ($backendName)." ); foreach ( $dirs as $dir ) { - $this->assertEquals( false, $this->backend->directoryExists( array( 'dir' => $dir ) ), + $this->assertEquals( false, $this->backend->directoryExists( [ 'dir' => $dir ] ), "Dir $dir no longer exists ($backendName)." ); } } @@ -1651,67 +1651,67 @@ class FileBackendTest extends MediaWikiTestCase { $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag'; $fileD = "$base/unittest-cont1/e/a/b/fileD.txt"; - $this->prepare( array( 'dir' => dirname( $fileA ) ) ); - $this->create( array( 'dst' => $fileA, 'content' => $fileAContents ) ); - $this->prepare( array( 'dir' => dirname( $fileB ) ) ); - $this->create( array( 'dst' => $fileB, 'content' => $fileBContents ) ); - $this->prepare( array( 'dir' => dirname( $fileC ) ) ); - $this->create( array( 'dst' => $fileC, 'content' => $fileCContents ) ); - $this->prepare( array( 'dir' => dirname( $fileD ) ) ); - - $status = $this->backend->doOperations( array( - array( 'op' => 'describe', 'src' => $fileA, - 'headers' => array( 'X-Content-Length' => '91.3' ), 'disposition' => 'inline' ), - array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ), + $this->prepare( [ 'dir' => dirname( $fileA ) ] ); + $this->create( [ 'dst' => $fileA, 'content' => $fileAContents ] ); + $this->prepare( [ 'dir' => dirname( $fileB ) ] ); + $this->create( [ 'dst' => $fileB, 'content' => $fileBContents ] ); + $this->prepare( [ 'dir' => dirname( $fileC ) ] ); + $this->create( [ 'dst' => $fileC, 'content' => $fileCContents ] ); + $this->prepare( [ 'dir' => dirname( $fileD ) ] ); + + $status = $this->backend->doOperations( [ + [ 'op' => 'describe', 'src' => $fileA, + 'headers' => [ 'X-Content-Length' => '91.3' ], 'disposition' => 'inline' ], + [ 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ], // Now: A:, B:, C:, D: (file:) - array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ), + [ 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ], // Now: A:, B:, C:, D: - array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ), + [ 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ], // Now: A:, B:, C:, D: - array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC ), + [ 'op' => 'move', 'src' => $fileB, 'dst' => $fileC ], // Now: A:, B:, C:, D: - array( 'op' => 'move', 'src' => $fileD, 'dst' => $fileA, 'overwriteSame' => 1 ), + [ 'op' => 'move', 'src' => $fileD, 'dst' => $fileA, 'overwriteSame' => 1 ], // Now: A:, B:, C:, D: - array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileA, 'overwrite' => 1 ), + [ 'op' => 'move', 'src' => $fileC, 'dst' => $fileA, 'overwrite' => 1 ], // Now: A:, B:, C:, D: - array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC ), + [ 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC ], // Now: A:, B:, C:, D: - array( 'op' => 'move', 'src' => $fileA, 'dst' => $fileC, 'overwriteSame' => 1 ), + [ 'op' => 'move', 'src' => $fileA, 'dst' => $fileC, 'overwriteSame' => 1 ], // Now: A:, B:, C:, D: - array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ), + [ 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ], // Does nothing - array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ), + [ 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ], // Does nothing - array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ), + [ 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ], // Does nothing - array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ), + [ 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ], // Does nothing - array( 'op' => 'null' ), + [ 'op' => 'null' ], // Does nothing - ) ); + ] ); $this->assertGoodStatus( $status, "Operation batch succeeded" ); $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" ); $this->assertEquals( 14, count( $status->success ), "Operation batch has correct success array" ); - $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileA ) ), + $this->assertEquals( false, $this->backend->fileExists( [ 'src' => $fileA ] ), "File does not exist at $fileA" ); - $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileB ) ), + $this->assertEquals( false, $this->backend->fileExists( [ 'src' => $fileB ] ), "File does not exist at $fileB" ); - $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileD ) ), + $this->assertEquals( false, $this->backend->fileExists( [ 'src' => $fileD ] ), "File does not exist at $fileD" ); - $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileC ) ), + $this->assertEquals( true, $this->backend->fileExists( [ 'src' => $fileC ] ), "File exists at $fileC" ); $this->assertEquals( $fileBContents, - $this->backend->getFileContents( array( 'src' => $fileC ) ), + $this->backend->getFileContents( [ 'src' => $fileC ] ), "Correct file contents of $fileC" ); $this->assertEquals( strlen( $fileBContents ), - $this->backend->getFileSize( array( 'src' => $fileC ) ), + $this->backend->getFileSize( [ 'src' => $fileC ] ), "Correct file size of $fileC" ); $this->assertEquals( Wikimedia\base_convert( sha1( $fileBContents ), 16, 36, 31 ), - $this->backend->getFileSha1Base36( array( 'src' => $fileC ) ), + $this->backend->getFileSha1Base36( [ 'src' => $fileC ] ), "Correct file SHA-1 of $fileC" ); } @@ -1741,7 +1741,7 @@ class FileBackendTest extends MediaWikiTestCase { $tmpNameA = TempFSFile::factory( "unittests_", 'txt' )->getPath(); $tmpNameB = TempFSFile::factory( "unittests_", 'txt' )->getPath(); $tmpNameC = TempFSFile::factory( "unittests_", 'txt' )->getPath(); - $this->addTmpFiles( array( $tmpNameA, $tmpNameB, $tmpNameC ) ); + $this->addTmpFiles( [ $tmpNameA, $tmpNameB, $tmpNameC ] ); file_put_contents( $tmpNameA, $fileAContents ); file_put_contents( $tmpNameB, $fileBContents ); file_put_contents( $tmpNameC, $fileCContents ); @@ -1751,66 +1751,66 @@ class FileBackendTest extends MediaWikiTestCase { $fileC = "$base/unittest-cont1/e/a/b/fileC.txt"; $fileD = "$base/unittest-cont1/e/a/b/fileD.txt"; - $this->prepare( array( 'dir' => dirname( $fileA ) ) ); - $this->create( array( 'dst' => $fileA, 'content' => $fileAContents ) ); - $this->prepare( array( 'dir' => dirname( $fileB ) ) ); - $this->prepare( array( 'dir' => dirname( $fileC ) ) ); - $this->prepare( array( 'dir' => dirname( $fileD ) ) ); - - $status = $this->backend->doOperations( array( - array( 'op' => 'store', 'src' => $tmpNameA, 'dst' => $fileA, 'overwriteSame' => 1 ), - array( 'op' => 'store', 'src' => $tmpNameB, 'dst' => $fileB, 'overwrite' => 1 ), - array( 'op' => 'store', 'src' => $tmpNameC, 'dst' => $fileC, 'overwrite' => 1 ), - array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ), + $this->prepare( [ 'dir' => dirname( $fileA ) ] ); + $this->create( [ 'dst' => $fileA, 'content' => $fileAContents ] ); + $this->prepare( [ 'dir' => dirname( $fileB ) ] ); + $this->prepare( [ 'dir' => dirname( $fileC ) ] ); + $this->prepare( [ 'dir' => dirname( $fileD ) ] ); + + $status = $this->backend->doOperations( [ + [ 'op' => 'store', 'src' => $tmpNameA, 'dst' => $fileA, 'overwriteSame' => 1 ], + [ 'op' => 'store', 'src' => $tmpNameB, 'dst' => $fileB, 'overwrite' => 1 ], + [ 'op' => 'store', 'src' => $tmpNameC, 'dst' => $fileC, 'overwrite' => 1 ], + [ 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ], // Now: A:, B:, C:, D: (file:) - array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ), + [ 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ], // Now: A:, B:, C:, D: - array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ), + [ 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ], // Now: A:, B:, C:, D: - array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC ), + [ 'op' => 'move', 'src' => $fileB, 'dst' => $fileC ], // Now: A:, B:, C:, D: - array( 'op' => 'move', 'src' => $fileD, 'dst' => $fileA, 'overwriteSame' => 1 ), + [ 'op' => 'move', 'src' => $fileD, 'dst' => $fileA, 'overwriteSame' => 1 ], // Now: A:, B:, C:, D: - array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileA, 'overwrite' => 1 ), + [ 'op' => 'move', 'src' => $fileC, 'dst' => $fileA, 'overwrite' => 1 ], // Now: A:, B:, C:, D: - array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC ), + [ 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC ], // Now: A:, B:, C:, D: - array( 'op' => 'move', 'src' => $fileA, 'dst' => $fileC, 'overwriteSame' => 1 ), + [ 'op' => 'move', 'src' => $fileA, 'dst' => $fileC, 'overwriteSame' => 1 ], // Now: A:, B:, C:, D: - array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ), + [ 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ], // Does nothing - array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ), + [ 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ], // Does nothing - array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ), + [ 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ], // Does nothing - array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ), + [ 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ], // Does nothing - array( 'op' => 'null' ), + [ 'op' => 'null' ], // Does nothing - ) ); + ] ); $this->assertGoodStatus( $status, "Operation batch succeeded" ); $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" ); $this->assertEquals( 16, count( $status->success ), "Operation batch has correct success array" ); - $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileA ) ), + $this->assertEquals( false, $this->backend->fileExists( [ 'src' => $fileA ] ), "File does not exist at $fileA" ); - $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileB ) ), + $this->assertEquals( false, $this->backend->fileExists( [ 'src' => $fileB ] ), "File does not exist at $fileB" ); - $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileD ) ), + $this->assertEquals( false, $this->backend->fileExists( [ 'src' => $fileD ] ), "File does not exist at $fileD" ); - $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileC ) ), + $this->assertEquals( true, $this->backend->fileExists( [ 'src' => $fileC ] ), "File exists at $fileC" ); $this->assertEquals( $fileBContents, - $this->backend->getFileContents( array( 'src' => $fileC ) ), + $this->backend->getFileContents( [ 'src' => $fileC ] ), "Correct file contents of $fileC" ); $this->assertEquals( strlen( $fileBContents ), - $this->backend->getFileSize( array( 'src' => $fileC ) ), + $this->backend->getFileSize( [ 'src' => $fileC ] ), "Correct file size of $fileC" ); $this->assertEquals( Wikimedia\base_convert( sha1( $fileBContents ), 16, 36, 31 ), - $this->backend->getFileSha1Base36( array( 'src' => $fileC ) ), + $this->backend->getFileSha1Base36( [ 'src' => $fileC ] ), "Correct file SHA-1 of $fileC" ); } @@ -1840,54 +1840,54 @@ class FileBackendTest extends MediaWikiTestCase { $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag'; $fileD = "$base/unittest-cont2/a/b/fileD.txt"; - $this->prepare( array( 'dir' => dirname( $fileA ) ) ); - $this->create( array( 'dst' => $fileA, 'content' => $fileAContents ) ); - $this->prepare( array( 'dir' => dirname( $fileB ) ) ); - $this->create( array( 'dst' => $fileB, 'content' => $fileBContents ) ); - $this->prepare( array( 'dir' => dirname( $fileC ) ) ); - $this->create( array( 'dst' => $fileC, 'content' => $fileCContents ) ); + $this->prepare( [ 'dir' => dirname( $fileA ) ] ); + $this->create( [ 'dst' => $fileA, 'content' => $fileAContents ] ); + $this->prepare( [ 'dir' => dirname( $fileB ) ] ); + $this->create( [ 'dst' => $fileB, 'content' => $fileBContents ] ); + $this->prepare( [ 'dir' => dirname( $fileC ) ] ); + $this->create( [ 'dst' => $fileC, 'content' => $fileCContents ] ); - $status = $this->backend->doOperations( array( - array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ), + $status = $this->backend->doOperations( [ + [ 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ], // Now: A:, B:, C:, D: (file:) - array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ), + [ 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ], // Now: A:, B:, C:, D: - array( 'op' => 'copy', 'src' => $fileB, 'dst' => $fileD, 'overwrite' => 1 ), + [ 'op' => 'copy', 'src' => $fileB, 'dst' => $fileD, 'overwrite' => 1 ], // Now: A:, B:, C:, D: - array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD ), + [ 'op' => 'move', 'src' => $fileC, 'dst' => $fileD ], // Now: A:, B:, C:, D: (failed) - array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC, 'overwriteSame' => 1 ), + [ 'op' => 'move', 'src' => $fileB, 'dst' => $fileC, 'overwriteSame' => 1 ], // Now: A:, B:, C:, D: (failed) - array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileA, 'overwrite' => 1 ), + [ 'op' => 'move', 'src' => $fileB, 'dst' => $fileA, 'overwrite' => 1 ], // Now: A:, B:, C:, D: - array( 'op' => 'delete', 'src' => $fileD ), + [ 'op' => 'delete', 'src' => $fileD ], // Now: A:, B:, C:, D: - array( 'op' => 'null' ), + [ 'op' => 'null' ], // Does nothing - ), array( 'force' => 1 ) ); + ], [ 'force' => 1 ] ); - $this->assertNotEquals( array(), $status->errors, "Operation had warnings" ); + $this->assertNotEquals( [], $status->errors, "Operation had warnings" ); $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" ); $this->assertEquals( 8, count( $status->success ), "Operation batch has correct success array" ); - $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileB ) ), + $this->assertEquals( false, $this->backend->fileExists( [ 'src' => $fileB ] ), "File does not exist at $fileB" ); - $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileD ) ), + $this->assertEquals( false, $this->backend->fileExists( [ 'src' => $fileD ] ), "File does not exist at $fileD" ); - $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileA ) ), + $this->assertEquals( true, $this->backend->fileExists( [ 'src' => $fileA ] ), "File does not exist at $fileA" ); - $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileC ) ), + $this->assertEquals( true, $this->backend->fileExists( [ 'src' => $fileC ] ), "File exists at $fileC" ); $this->assertEquals( $fileBContents, - $this->backend->getFileContents( array( 'src' => $fileA ) ), + $this->backend->getFileContents( [ 'src' => $fileA ] ), "Correct file contents of $fileA" ); $this->assertEquals( strlen( $fileBContents ), - $this->backend->getFileSize( array( 'src' => $fileA ) ), + $this->backend->getFileSize( [ 'src' => $fileA ] ), "Correct file size of $fileA" ); $this->assertEquals( Wikimedia\base_convert( sha1( $fileBContents ), 16, 36, 31 ), - $this->backend->getFileSha1Base36( array( 'src' => $fileA ) ), + $this->backend->getFileSha1Base36( [ 'src' => $fileA ] ), "Correct file SHA-1 of $fileA" ); } @@ -1911,9 +1911,9 @@ class FileBackendTest extends MediaWikiTestCase { $base = self::baseStorePath(); // Should have no errors - $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont-notexists" ) ); + $iter = $this->backend->getFileList( [ 'dir' => "$base/unittest-cont-notexists" ] ); - $files = array( + $files = [ "$base/unittest-cont1/e/test1.txt", "$base/unittest-cont1/e/test2.txt", "$base/unittest-cont1/e/test3.txt", @@ -1928,13 +1928,13 @@ class FileBackendTest extends MediaWikiTestCase { "$base/unittest-cont1/e/subdir2/subdir/test5.txt", "$base/unittest-cont1/e/subdir2/subdir/sub/test0.txt", "$base/unittest-cont1/e/subdir2/subdir/sub/120-px-file.txt", - ); + ]; // Add the files - $ops = array(); + $ops = []; foreach ( $files as $file ) { - $this->prepare( array( 'dir' => dirname( $file ) ) ); - $ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file ); + $this->prepare( [ 'dir' => dirname( $file ) ] ); + $ops[] = [ 'op' => 'create', 'content' => 'xxy', 'dst' => $file ]; } $status = $this->backend->doQuickOperations( $ops ); $this->assertGoodStatus( $status, @@ -1943,7 +1943,7 @@ class FileBackendTest extends MediaWikiTestCase { "Creation of files succeeded with OK status ($backendName)." ); // Expected listing at root - $expected = array( + $expected = [ "e/test1.txt", "e/test2.txt", "e/test3.txt", @@ -1958,27 +1958,27 @@ class FileBackendTest extends MediaWikiTestCase { "e/subdir2/subdir/test5.txt", "e/subdir2/subdir/sub/test0.txt", "e/subdir2/subdir/sub/120-px-file.txt", - ); + ]; sort( $expected ); // Actual listing (no trailing slash) at root - $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1" ) ); + $iter = $this->backend->getFileList( [ 'dir' => "$base/unittest-cont1" ] ); $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( + $iter = $this->backend->getFileList( [ '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) at root - $list = array(); - $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/" ) ); + $list = []; + $iter = $this->backend->getFileList( [ 'dir' => "$base/unittest-cont1/" ] ); foreach ( $iter as $file ) { $list[] = $file; } @@ -1986,7 +1986,7 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." ); // Expected listing at subdir - $expected = array( + $expected = [ "test1.txt", "test2.txt", "test3.txt", @@ -1994,27 +1994,27 @@ class FileBackendTest extends MediaWikiTestCase { "test5.txt", "sub/test0.txt", "sub/120-px-file.txt", - ); + ]; sort( $expected ); // Actual listing (no trailing slash) at subdir - $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir" ) ); + $iter = $this->backend->getFileList( [ 'dir' => "$base/unittest-cont1/e/subdir2/subdir" ] ); $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( + $iter = $this->backend->getFileList( [ '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) at subdir - $list = array(); - $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir/" ) ); + $list = []; + $iter = $this->backend->getFileList( [ 'dir' => "$base/unittest-cont1/e/subdir2/subdir/" ] ); foreach ( $iter as $file ) { $list[] = $file; } @@ -2027,43 +2027,43 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertEquals( $expected, $list, "Correct file listing ($backendName), second iteration." ); // Actual listing (top files only) at root - $iter = $this->backend->getTopFileList( array( 'dir' => "$base/unittest-cont1" ) ); + $iter = $this->backend->getTopFileList( [ 'dir' => "$base/unittest-cont1" ] ); $list = $this->listToArray( $iter ); sort( $list ); - $this->assertEquals( array(), $list, "Correct top file listing ($backendName)." ); + $this->assertEquals( [], $list, "Correct top file listing ($backendName)." ); // Expected listing (top files only) at subdir - $expected = array( + $expected = [ "test1.txt", "test2.txt", "test3.txt", "test4.txt", "test5.txt" - ); + ]; sort( $expected ); // Actual listing (top files only) at subdir $iter = $this->backend->getTopFileList( - array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir" ) + [ 'dir' => "$base/unittest-cont1/e/subdir2/subdir" ] ); $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( + $iter = $this->backend->getTopFileList( [ '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 - $this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) ); + $this->backend->doOperation( [ 'op' => 'delete', 'src' => $file ] ); } - $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/not/exists" ) ); + $iter = $this->backend->getFileList( [ 'dir' => "$base/unittest-cont1/not/exists" ] ); foreach ( $iter as $iter ) { // no errors } @@ -2089,7 +2089,7 @@ class FileBackendTest extends MediaWikiTestCase { $backendName = $this->backendClass(); $base = self::baseStorePath(); - $files = array( + $files = [ "$base/unittest-cont1/e/test1.txt", "$base/unittest-cont1/e/test2.txt", "$base/unittest-cont1/e/test3.txt", @@ -2104,13 +2104,13 @@ class FileBackendTest extends MediaWikiTestCase { "$base/unittest-cont1/e/subdir4/subdir/test5.txt", "$base/unittest-cont1/e/subdir4/subdir/sub/test0.txt", "$base/unittest-cont1/e/subdir4/subdir/sub/120-px-file.txt", - ); + ]; // Add the files - $ops = array(); + $ops = []; foreach ( $files as $file ) { - $this->prepare( array( 'dir' => dirname( $file ) ) ); - $ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file ); + $this->prepare( [ 'dir' => dirname( $file ) ] ); + $ops[] = [ 'op' => 'create', 'content' => 'xxy', 'dst' => $file ]; } $status = $this->backend->doQuickOperations( $ops ); $this->assertGoodStatus( $status, @@ -2119,24 +2119,24 @@ class FileBackendTest extends MediaWikiTestCase { "Creation of files succeeded with OK status ($backendName)." ); $this->assertEquals( true, - $this->backend->directoryExists( array( 'dir' => "$base/unittest-cont1/e/subdir1" ) ), + $this->backend->directoryExists( [ 'dir' => "$base/unittest-cont1/e/subdir1" ] ), "Directory exists in ($backendName)." ); $this->assertEquals( true, - $this->backend->directoryExists( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir" ) ), + $this->backend->directoryExists( [ 'dir' => "$base/unittest-cont1/e/subdir2/subdir" ] ), "Directory exists in ($backendName)." ); $this->assertEquals( false, - $this->backend->directoryExists( array( 'dir' => "$base/unittest-cont1/e/subdir2/test1.txt" ) ), + $this->backend->directoryExists( [ 'dir' => "$base/unittest-cont1/e/subdir2/test1.txt" ] ), "Directory does not exists in ($backendName)." ); // Expected listing - $expected = array( + $expected = [ "e", - ); + ]; sort( $expected ); // Actual listing (no trailing slash) - $list = array(); - $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1" ) ); + $list = []; + $iter = $this->backend->getTopDirectoryList( [ 'dir' => "$base/unittest-cont1" ] ); foreach ( $iter as $file ) { $list[] = $file; } @@ -2145,17 +2145,17 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." ); // Expected listing - $expected = array( + $expected = [ "subdir1", "subdir2", "subdir3", "subdir4", - ); + ]; sort( $expected ); // Actual listing (no trailing slash) - $list = array(); - $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/e" ) ); + $list = []; + $iter = $this->backend->getTopDirectoryList( [ 'dir' => "$base/unittest-cont1/e" ] ); foreach ( $iter as $file ) { $list[] = $file; } @@ -2164,8 +2164,8 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." ); // Actual listing (with trailing slash) - $list = array(); - $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/e/" ) ); + $list = []; + $iter = $this->backend->getTopDirectoryList( [ 'dir' => "$base/unittest-cont1/e/" ] ); foreach ( $iter as $file ) { $list[] = $file; } @@ -2174,14 +2174,14 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." ); // Expected listing - $expected = array( + $expected = [ "subdir", - ); + ]; sort( $expected ); // Actual listing (no trailing slash) - $list = array(); - $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/e/subdir2" ) ); + $list = []; + $iter = $this->backend->getTopDirectoryList( [ 'dir' => "$base/unittest-cont1/e/subdir2" ] ); foreach ( $iter as $file ) { $list[] = $file; } @@ -2190,9 +2190,9 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." ); // Actual listing (with trailing slash) - $list = array(); + $list = []; $iter = $this->backend->getTopDirectoryList( - array( 'dir' => "$base/unittest-cont1/e/subdir2/" ) + [ 'dir' => "$base/unittest-cont1/e/subdir2/" ] ); foreach ( $iter as $file ) { @@ -2203,7 +2203,7 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." ); // Actual listing (using iterator second time) - $list = array(); + $list = []; foreach ( $iter as $file ) { $list[] = $file; } @@ -2216,7 +2216,7 @@ class FileBackendTest extends MediaWikiTestCase { ); // Expected listing (recursive) - $expected = array( + $expected = [ "e", "e/subdir1", "e/subdir2", @@ -2226,12 +2226,12 @@ class FileBackendTest extends MediaWikiTestCase { "e/subdir3/subdir", "e/subdir4/subdir", "e/subdir4/subdir/sub", - ); + ]; sort( $expected ); // Actual listing (recursive) - $list = array(); - $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/" ) ); + $list = []; + $iter = $this->backend->getDirectoryList( [ 'dir' => "$base/unittest-cont1/" ] ); foreach ( $iter as $file ) { $list[] = $file; } @@ -2240,15 +2240,15 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." ); // Expected listing (recursive) - $expected = array( + $expected = [ "subdir", "subdir/sub", - ); + ]; sort( $expected ); // Actual listing (recursive) - $list = array(); - $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/e/subdir4" ) ); + $list = []; + $iter = $this->backend->getDirectoryList( [ 'dir' => "$base/unittest-cont1/e/subdir4" ] ); foreach ( $iter as $file ) { $list[] = $file; } @@ -2257,7 +2257,7 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." ); // Actual listing (recursive, second time) - $list = array(); + $list = []; foreach ( $iter as $file ) { $list[] = $file; } @@ -2265,25 +2265,25 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." ); - $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/e/subdir1" ) ); + $iter = $this->backend->getDirectoryList( [ 'dir' => "$base/unittest-cont1/e/subdir1" ] ); $items = $this->listToArray( $iter ); - $this->assertEquals( array(), $items, "Directory listing is empty." ); + $this->assertEquals( [], $items, "Directory listing is empty." ); foreach ( $files as $file ) { // clean up - $this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) ); + $this->backend->doOperation( [ 'op' => 'delete', 'src' => $file ] ); } - $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/not/exists" ) ); + $iter = $this->backend->getDirectoryList( [ 'dir' => "$base/unittest-cont1/not/exists" ] ); foreach ( $iter as $file ) { // no errors } $items = $this->listToArray( $iter ); - $this->assertEquals( array(), $items, "Directory listing is empty." ); + $this->assertEquals( [], $items, "Directory listing is empty." ); - $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/e/not/exists" ) ); + $iter = $this->backend->getDirectoryList( [ 'dir' => "$base/unittest-cont1/e/not/exists" ] ); $items = $this->listToArray( $iter ); - $this->assertEquals( array(), $items, "Directory listing is empty." ); + $this->assertEquals( [], $items, "Directory listing is empty." ); } /** @@ -2298,7 +2298,7 @@ class FileBackendTest extends MediaWikiTestCase { private function doTestLockCalls() { $backendName = $this->backendClass(); - $paths = array( + $paths = [ "test1.txt", "test2.txt", "test3.txt", @@ -2319,29 +2319,29 @@ class FileBackendTest extends MediaWikiTestCase { "subdir2/subdir/sub", "subdir2/subdir/sub/test0.txt", "subdir2/subdir/sub/120-px-file.txt", - ); + ]; 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 ), + $this->assertEquals( print_r( [], true ), print_r( $status->errors, true ), "Locking of files succeeded ($backendName) ($i)." ); $this->assertEquals( true, $status->isOK(), "Locking of files succeeded with OK status ($backendName) ($i)." ); $status = $this->backend->lockFiles( $paths, LockManager::LOCK_SH ); - $this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ), + $this->assertEquals( print_r( [], true ), print_r( $status->errors, true ), "Locking of files succeeded ($backendName) ($i)." ); $this->assertEquals( true, $status->isOK(), "Locking of files succeeded with OK status ($backendName) ($i)." ); $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_SH ); - $this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ), + $this->assertEquals( print_r( [], true ), print_r( $status->errors, true ), "Locking of files succeeded ($backendName) ($i)." ); $this->assertEquals( true, $status->isOK(), "Locking of files succeeded with OK status ($backendName) ($i)." ); $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_EX ); - $this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ), + $this->assertEquals( print_r( [], true ), print_r( $status->errors, true ), "Locking of files succeeded ($backendName). ($i)" ); $this->assertEquals( true, $status->isOK(), "Locking of files succeeded with OK status ($backendName) ($i)." ); @@ -2349,25 +2349,25 @@ class FileBackendTest extends MediaWikiTestCase { # # Flip the acquire/release ordering around ## $status = $this->backend->lockFiles( $paths, LockManager::LOCK_SH ); - $this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ), + $this->assertEquals( print_r( [], true ), print_r( $status->errors, true ), "Locking of files succeeded ($backendName) ($i)." ); $this->assertEquals( true, $status->isOK(), "Locking of files succeeded with OK status ($backendName) ($i)." ); $status = $this->backend->lockFiles( $paths, LockManager::LOCK_EX ); - $this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ), + $this->assertEquals( print_r( [], true ), print_r( $status->errors, true ), "Locking of files succeeded ($backendName) ($i)." ); $this->assertEquals( true, $status->isOK(), "Locking of files succeeded with OK status ($backendName) ($i)." ); $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_EX ); - $this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ), + $this->assertEquals( print_r( [], true ), print_r( $status->errors, true ), "Locking of files succeeded ($backendName). ($i)" ); $this->assertEquals( true, $status->isOK(), "Locking of files succeeded with OK status ($backendName) ($i)." ); $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_SH ); - $this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ), + $this->assertEquals( print_r( [], true ), print_r( $status->errors, true ), "Locking of files succeeded ($backendName) ($i)." ); $this->assertEquals( true, $status->isOK(), "Locking of files succeeded with OK status ($backendName) ($i)." ); @@ -2377,7 +2377,7 @@ class FileBackendTest extends MediaWikiTestCase { $sl = $this->backend->getScopedFileLocks( $paths, LockManager::LOCK_EX, $status ); $this->assertInstanceOf( 'ScopedLock', $sl, "Scoped locking of files succeeded ($backendName)." ); - $this->assertEquals( array(), $status->errors, + $this->assertEquals( [], $status->errors, "Scoped locking of files succeeded ($backendName)." ); $this->assertEquals( true, $status->isOK(), "Scoped locking of files succeeded with OK status ($backendName)." ); @@ -2385,7 +2385,7 @@ class FileBackendTest extends MediaWikiTestCase { ScopedLock::release( $sl ); $this->assertEquals( null, $sl, "Scoped unlocking of files succeeded ($backendName)." ); - $this->assertEquals( array(), $status->errors, + $this->assertEquals( [], $status->errors, "Scoped unlocking of files succeeded ($backendName)." ); $this->assertEquals( true, $status->isOK(), "Scoped unlocking of files succeeded with OK status ($backendName)." ); @@ -2398,12 +2398,12 @@ class FileBackendTest extends MediaWikiTestCase { global $IP; $be = TestingAccessWrapper::newFromObject( new MemoryFileBackend( - array( + [ 'name' => 'testing', 'class' => 'MemoryFileBackend', 'wikiId' => 'meow', 'mimeCallback' => $mimeCallback - ) + ] ) ); $dst = 'mwstore://testing/container/path/to/file_no_ext'; @@ -2421,97 +2421,97 @@ class FileBackendTest extends MediaWikiTestCase { } public static function provider_testGetContentType() { - return array( - array( null, false ), - array( array( FileBackendGroup::singleton(), 'guessMimeInternal' ), true ) - ); + return [ + [ null, false ], + [ [ FileBackendGroup::singleton(), 'guessMimeInternal' ], true ] + ]; } public function testReadAffinity() { $be = TestingAccessWrapper::newFromObject( - new FileBackendMultiWrite( array( + new FileBackendMultiWrite( [ 'name' => 'localtesting', 'wikiId' => wfWikiId() . mt_rand(), - 'backends' => array( - array( // backend 0 + 'backends' => [ + [ // backend 0 'name' => 'multitesting0', 'class' => 'MemoryFileBackend', 'isMultiMaster' => false, 'readAffinity' => true - ), - array( // backend 1 + ], + [ // backend 1 'name' => 'multitesting1', 'class' => 'MemoryFileBackend', 'isMultiMaster' => true - ) - ) - ) ) + ] + ] + ] ) ); $this->assertEquals( 1, - $be->getReadIndexFromParams( array( 'latest' => 1 ) ), + $be->getReadIndexFromParams( [ 'latest' => 1 ] ), 'Reads with "latest" flag use backend 1' ); $this->assertEquals( 0, - $be->getReadIndexFromParams( array( 'latest' => 0 ) ), + $be->getReadIndexFromParams( [ 'latest' => 0 ] ), 'Reads without "latest" flag use backend 0' ); $p = 'container/test-cont/file.txt'; - $be->backends[0]->quickCreate( array( - 'dst' => "mwstore://multitesting0/$p", 'content' => 'cattitude' ) ); - $be->backends[1]->quickCreate( array( - 'dst' => "mwstore://multitesting1/$p", 'content' => 'princess of power' ) ); + $be->backends[0]->quickCreate( [ + 'dst' => "mwstore://multitesting0/$p", 'content' => 'cattitude' ] ); + $be->backends[1]->quickCreate( [ + 'dst' => "mwstore://multitesting1/$p", 'content' => 'princess of power' ] ); $this->assertEquals( 'cattitude', - $be->getFileContents( array( 'src' => "mwstore://localtesting/$p" ) ), + $be->getFileContents( [ 'src' => "mwstore://localtesting/$p" ] ), "Non-latest read came from backend 0" ); $this->assertEquals( 'princess of power', - $be->getFileContents( array( 'src' => "mwstore://localtesting/$p", 'latest' => 1 ) ), + $be->getFileContents( [ 'src' => "mwstore://localtesting/$p", 'latest' => 1 ] ), "Latest read came from backend1" ); } public function testAsyncWrites() { $be = TestingAccessWrapper::newFromObject( - new FileBackendMultiWrite( array( + new FileBackendMultiWrite( [ 'name' => 'localtesting', 'wikiId' => wfWikiId() . mt_rand(), - 'backends' => array( - array( // backend 0 + 'backends' => [ + [ // backend 0 'name' => 'multitesting0', 'class' => 'MemoryFileBackend', 'isMultiMaster' => false - ), - array( // backend 1 + ], + [ // backend 1 'name' => 'multitesting1', 'class' => 'MemoryFileBackend', 'isMultiMaster' => true - ) - ), + ] + ], 'replication' => 'async' - ) ) + ] ) ); $this->setMwGlobals( 'wgCommandLineMode', false ); $p = 'container/test-cont/file.txt'; - $be->quickCreate( array( - 'dst' => "mwstore://localtesting/$p", 'content' => 'cattitude' ) ); + $be->quickCreate( [ + 'dst' => "mwstore://localtesting/$p", 'content' => 'cattitude' ] ); $this->assertEquals( false, - $be->backends[0]->getFileContents( array( 'src' => "mwstore://multitesting0/$p" ) ), + $be->backends[0]->getFileContents( [ 'src' => "mwstore://multitesting0/$p" ] ), "File not yet written to backend 0" ); $this->assertEquals( 'cattitude', - $be->backends[1]->getFileContents( array( 'src' => "mwstore://multitesting1/$p" ) ), + $be->backends[1]->getFileContents( [ 'src' => "mwstore://multitesting1/$p" ] ), "File already written to backend 1" ); @@ -2519,34 +2519,34 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertEquals( 'cattitude', - $be->backends[0]->getFileContents( array( 'src' => "mwstore://multitesting0/$p" ) ), + $be->backends[0]->getFileContents( [ 'src' => "mwstore://multitesting0/$p" ] ), "File now written to backend 0" ); } public function testSanitizeOpHeaders() { - $be = TestingAccessWrapper::newFromObject( new MemoryFileBackend( array( + $be = TestingAccessWrapper::newFromObject( new MemoryFileBackend( [ 'name' => 'localtesting', 'wikiId' => wfWikiID() - ) ) ); + ] ) ); $name = wfRandomString( 300 ); - $input = array( - 'headers' => array( + $input = [ + 'headers' => [ 'content-Disposition' => FileBackend::makeContentDisposition( 'inline', $name ), 'Content-dUration' => 25.6, 'X-LONG-VALUE' => str_pad( '0', 300 ), 'CONTENT-LENGTH' => 855055, - ) - ); - $expected = array( - 'headers' => array( + ] + ]; + $expected = [ + 'headers' => [ 'content-disposition' => FileBackend::makeContentDisposition( 'inline', $name ), 'content-duration' => 25.6, 'content-length' => 855055 - ) - ); + ] + ]; MediaWiki\suppressWarnings(); $actual = $be->sanitizeOpHeaders( $input ); @@ -2569,11 +2569,11 @@ class FileBackendTest extends MediaWikiTestCase { private function create( array $params ) { $params['op'] = 'create'; - return $this->backend->doQuickOperations( array( $params ) ); + return $this->backend->doQuickOperations( [ $params ] ); } function tearDownFiles() { - $containers = array( 'unittest-cont1', 'unittest-cont2', 'unittest-cont-bad' ); + $containers = [ 'unittest-cont1', 'unittest-cont2', 'unittest-cont-bad' ]; foreach ( $containers as $container ) { $this->deleteFiles( $container ); } @@ -2581,15 +2581,15 @@ class FileBackendTest extends MediaWikiTestCase { private function deleteFiles( $container ) { $base = self::baseStorePath(); - $iter = $this->backend->getFileList( array( 'dir' => "$base/$container" ) ); + $iter = $this->backend->getFileList( [ 'dir' => "$base/$container" ] ); if ( $iter ) { foreach ( $iter as $file ) { - $this->backend->quickDelete( array( 'src' => "$base/$container/$file" ) ); + $this->backend->quickDelete( [ 'src' => "$base/$container/$file" ] ); } // free the directory, to avoid Permission denied under windows on rmdir unset( $iter ); } - $this->backend->clean( array( 'dir' => "$base/$container", 'recursive' => 1 ) ); + $this->backend->clean( [ 'dir' => "$base/$container", 'recursive' => 1 ] ); } function assertBackendPathsConsistent( array $paths ) { @@ -2600,6 +2600,6 @@ class FileBackendTest extends MediaWikiTestCase { } function assertGoodStatus( $status, $msg ) { - $this->assertEquals( print_r( array(), 1 ), print_r( $status->errors, 1 ), $msg ); + $this->assertEquals( print_r( [], 1 ), print_r( $status->errors, 1 ), $msg ); } }