From 282554eb33e72cf2fefecef86b8c7edf83456d6c Mon Sep 17 00:00:00 2001 From: Christian Aistleitner Date: Tue, 10 Apr 2012 16:57:15 +0200 Subject: [PATCH] Employing MediaWikiTestCase's temporary file methods Change-Id: Ide86541abf6642791c1466a2075436a9df6bdbed --- .../includes/media/ExifRotationTest.php | 18 ++--------- tests/phpunit/maintenance/DumpTestCase.php | 32 ------------------- 2 files changed, 2 insertions(+), 48 deletions(-) diff --git a/tests/phpunit/includes/media/ExifRotationTest.php b/tests/phpunit/includes/media/ExifRotationTest.php index 25149a0573..1e2d1bb7fe 100644 --- a/tests/phpunit/includes/media/ExifRotationTest.php +++ b/tests/phpunit/includes/media/ExifRotationTest.php @@ -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(); } /** diff --git a/tests/phpunit/maintenance/DumpTestCase.php b/tests/phpunit/maintenance/DumpTestCase.php index a6fe5497dd..2f8c2321e6 100644 --- a/tests/phpunit/maintenance/DumpTestCase.php +++ b/tests/phpunit/maintenance/DumpTestCase.php @@ -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. * -- 2.20.1