Employing MediaWikiTestCase's temporary file methods
authorChristian Aistleitner <christian@quelltextlich.at>
Tue, 10 Apr 2012 14:57:15 +0000 (16:57 +0200)
committerChristian Aistleitner <christian@quelltextlich.at>
Tue, 10 Apr 2012 15:08:06 +0000 (17:08 +0200)
Change-Id: Ide86541abf6642791c1466a2075436a9df6bdbed

tests/phpunit/includes/media/ExifRotationTest.php
tests/phpunit/maintenance/DumpTestCase.php

index 25149a0..1e2d1bb 100644 (file)
@@ -5,16 +5,12 @@
  */
 class ExifRotationTest extends MediaWikiTestCase {
 
-       /** track directories creations. Content will be deleted. */
-       private $createdDirs = array();
-
        function setUp() {
                parent::setUp();
                $this->handler = new BitmapHandler();
                $filePath = dirname( __FILE__ ) . '/../../data/media';
 
-               $tmpDir = wfTempDir() . '/exif-test-' . time() . '-' . mt_rand();
-               $this->createdDirs[] = $tmpDir;
+               $tmpDir = $this->getNewTempDirectory();
 
                $this->repo = new FSRepo( array(
                        'name'            => 'temp',
@@ -42,17 +38,7 @@ class ExifRotationTest extends MediaWikiTestCase {
                $wgShowEXIF = $this->show;
                $wgEnableAutoRotation = $this->oldAuto;
 
-               $this->tearDownFiles();
-       }
-
-       private function tearDownFiles() {
-               foreach( $this->createdDirs as $dir ) {
-                       wfRecursiveRemoveDir( $dir );
-               }
-       }
-
-       function __destruct() {
-               $this->tearDownFiles();
+               parent::tearDown();
        }
 
        /**
index a6fe549..2f8c232 100644 (file)
@@ -69,19 +69,6 @@ abstract class DumpTestCase extends MediaWikiTestCase {
                        file_put_contents( $fname, $contents ), "# bytes written" );
        }
 
-       /**
-        * obtains a new temporary file name
-        *
-        * The obtained filename is enlisted to be removed upon tearDown
-        *
-        * @returns string: absolute name of the temporary file
-        */
-       protected function getNewTempFile() {
-               $fname = tempnam( wfTempDir(), 'MW_PHPUnit_' . get_class( $this ) . '_' );
-               $this->tmpfiles[] = $fname;
-               return $fname;
-       }
-
        /**
         * Default set up function.
         *
@@ -97,29 +84,10 @@ abstract class DumpTestCase extends MediaWikiTestCase {
                if ( $this->exceptionFromAddDBData !== null ) {
                        throw $this->exceptionFromAddDBData;
                }
-               $this->tmpfiles = array();
 
                $wgUser = new User();
        }
 
-       /**
-        * Default tear down function
-        *
-        * Removes all files that have been allocated via self::getNewTempFile, even if
-        * they turn out to be (empty or non-empty) directories now.
-        */
-       function tearDown() {
-               foreach ( $this->tmpfiles as $fname ) {
-                       if ( is_file( $fname ) || ( is_link( $fname ) ) ) {
-                               unlink( $fname );
-                       } elseif ( is_dir( $fname ) ) {
-                               wfRecursiveRemoveDir( $fname );
-                       }
-               }
-               parent::tearDown();
-       }
-
-
        /**
         * Step the current XML reader until node end of given name is found.
         *