avoid exif tests file leakage
authorAntoine Musso <hashar@users.mediawiki.org>
Fri, 24 Feb 2012 15:43:11 +0000 (15:43 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Fri, 24 Feb 2012 15:43:11 +0000 (15:43 +0000)
Exif test are leaking files heavily on our test server. This quick patch make
it sure we delete temporary files.

Ideally, we should have something like a temporary filesystem backend that
would self destruct :-D

requires r112326: wfRecursiveRemoveDir()

tests/phpunit/includes/media/ExifRotationTest.php

index a703493..25149a0 100644 (file)
@@ -5,11 +5,17 @@
  */
 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;
+
                $this->repo = new FSRepo( array(
                        'name'            => 'temp',
                        'url'             => 'http://localhost/thumbtest',
@@ -30,10 +36,23 @@ class ExifRotationTest extends MediaWikiTestCase {
                $this->oldAuto = $wgEnableAutoRotation;
                $wgEnableAutoRotation = true;
        }
+
        public function tearDown() {
                global $wgShowEXIF, $wgEnableAutoRotation;
                $wgShowEXIF = $this->show;
                $wgEnableAutoRotation = $this->oldAuto;
+
+               $this->tearDownFiles();
+       }
+
+       private function tearDownFiles() {
+               foreach( $this->createdDirs as $dir ) {
+                       wfRecursiveRemoveDir( $dir );
+               }
+       }
+
+       function __destruct() {
+               $this->tearDownFiles();
        }
 
        /**