From: Aryeh Gregor Date: Tue, 20 Aug 2019 08:22:31 +0000 (+0300) Subject: Tests for TempFSFile X-Git-Tag: 1.34.0-rc.0~669^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=d7d5fb81b5e8186b9c6c9c4850e41e7c59434a42;p=lhc%2Fweb%2Fwiklou.git Tests for TempFSFile These are in preparation for making a TempFSFileFactory service, thus the odd break-up into two files. I split it into a separate commit so that we could verify that the same tests pass before and after the conversion to service. Tests cover everything except getUsableTempDirectory() (which I don't see how to test), and register_shutdown_function()-related stuff (which seems actually impossible to test without starting a new PHP process). Change-Id: If61b7ea3e332adc2bceefc8e6879a9e9443c99dd --- diff --git a/tests/common/TestsAutoLoader.php b/tests/common/TestsAutoLoader.php index fd418f7bef..e71cc88b3e 100644 --- a/tests/common/TestsAutoLoader.php +++ b/tests/common/TestsAutoLoader.php @@ -217,6 +217,9 @@ $wgAutoloadClasses += [ 'MockSearchResultSet' => "$testDir/phpunit/mocks/search/MockSearchResultSet.php", 'MockSearchResult' => "$testDir/phpunit/mocks/search/MockSearchResult.php", + # tests/phpunit/unit/includes/libs/filebackend/fsfile + 'TempFSFileTestTrait' => "$testDir/phpunit/unit/includes/libs/filebackend/fsfile/TempFSFileTestTrait.php", + # tests/suites 'ParserTestFileSuite' => "$testDir/phpunit/suites/ParserTestFileSuite.php", 'ParserTestTopLevelSuite' => "$testDir/phpunit/suites/ParserTestTopLevelSuite.php", diff --git a/tests/phpunit/includes/libs/filebackend/fsfile/TempFSFileIntegrationTest.php b/tests/phpunit/includes/libs/filebackend/fsfile/TempFSFileIntegrationTest.php new file mode 100644 index 0000000000..42805b2db2 --- /dev/null +++ b/tests/phpunit/includes/libs/filebackend/fsfile/TempFSFileIntegrationTest.php @@ -0,0 +1,9 @@ +newFile(); + $this->assertTrue( file_exists( $file->getPath() ) ); + $file->purge(); + $this->assertFalse( file_exists( $file->getPath() ) ); + } + + /** + * @covers TempFSFile::__construct + * @covers TempFSFile::bind + * @covers TempFSFile::autocollect + * @covers TempFSFile::__destruct + */ + public function testBind() { + $file = $this->newFile(); + $path = $file->getPath(); + $this->assertTrue( file_exists( $path ) ); + $obj = new stdclass; + $file->bind( $obj ); + unset( $file ); + $this->assertTrue( file_exists( $path ) ); + unset( $obj ); + $this->assertFalse( file_exists( $path ) ); + } + + /** + * @covers TempFSFile::__construct + * @covers TempFSFile::preserve + * @covers TempFSFile::__destruct + */ + public function testPreserve() { + $file = $this->newFile(); + $path = $file->getPath(); + $this->assertTrue( file_exists( $path ) ); + $file->preserve(); + unset( $file ); + $this->assertTrue( file_exists( $path ) ); + Wikimedia\suppressWarnings(); + unlink( $path ); + Wikimedia\restoreWarnings(); + } +}