From d7d5fb81b5e8186b9c6c9c4850e41e7c59434a42 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Tue, 20 Aug 2019 11:22:31 +0300 Subject: [PATCH] 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 --- tests/common/TestsAutoLoader.php | 3 ++ .../fsfile/TempFSFileIntegrationTest.php | 9 ++++ .../fsfile/TempFSFileTestTrait.php | 54 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 tests/phpunit/includes/libs/filebackend/fsfile/TempFSFileIntegrationTest.php create mode 100644 tests/phpunit/unit/includes/libs/filebackend/fsfile/TempFSFileTestTrait.php 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(); + } +} -- 2.20.1