filerepo: Use standard method for creating temp dir in unit test
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 10 Feb 2015 07:55:43 +0000 (07:55 +0000)
committerKrinkle <krinklemail@gmail.com>
Wed, 11 Feb 2015 01:42:12 +0000 (01:42 +0000)
Previously, the unittests-thumb directory (and its hashed subdirectories,
and the .htaccess and index.html files) were being left behind.

While that may be a bug in the FileBackend class, the unit test
shouldn't rely on that for its teardown. If we want to assert that,
that can be a separate test.

Bug: T89085
Change-Id: Ided46b71ace82159864145b76d98bb10da5d0311

tests/phpunit/includes/filerepo/StoreBatchTest.php

index 9cc2efb..86bfe12 100644 (file)
@@ -16,7 +16,7 @@ class StoreBatchTest extends MediaWikiTestCase {
                parent::setUp();
 
                # Forge a FSRepo object to not have to rely on local wiki settings
-               $tmpPrefix = wfTempDir() . '/storebatch-test-' . time() . '-' . mt_rand();
+               $tmpPrefix = $this->getNewTempDirectory();
                if ( $this->getCliArg( 'use-filebackend' ) ) {
                        $name = $this->getCliArg( 'use-filebackend' );
                        $useConfig = array();
@@ -35,10 +35,10 @@ class StoreBatchTest extends MediaWikiTestCase {
                                'name' => 'local-testing',
                                'wikiId' => wfWikiID(),
                                'containerPaths' => array(
-                                       'unittests-public' => "{$tmpPrefix}-public",
-                                       'unittests-thumb' => "{$tmpPrefix}-thumb",
-                                       'unittests-temp' => "{$tmpPrefix}-temp",
-                                       'unittests-deleted' => "{$tmpPrefix}-deleted",
+                                       'unittests-public' => "{$tmpPrefix}/public",
+                                       'unittests-thumb' => "{$tmpPrefix}/thumb",
+                                       'unittests-temp' => "{$tmpPrefix}/temp",
+                                       'unittests-deleted' => "{$tmpPrefix}/deleted",
                                )
                        ) );
                }
@@ -52,13 +52,8 @@ class StoreBatchTest extends MediaWikiTestCase {
        }
 
        protected function tearDown() {
-               $this->repo->cleanupBatch( $this->createdFiles ); // delete files
-               foreach ( $this->createdFiles as $tmp ) { // delete dirs
-                       $tmp = $this->repo->resolveVirtualUrl( $tmp );
-                       while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) {
-                               $this->repo->getBackend()->clean( array( 'dir' => $tmp ) );
-                       }
-               }
+               // Delete files
+               $this->repo->cleanupBatch( $this->createdFiles );
                parent::tearDown();
        }