aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/filebackend/FileBackendTest.php
Commit message (Collapse)AuthorAgeFilesLines
* Unit tests for FileBackendAryeh Gregor2019-10-301-2776/+0
| | | | | | | | | | | Currently 62.79% coverage, 108/172 lines. One oddity discovered during testing was that the "quick" variants of most methods don't have an $opts parameter. It seems like just an oversight, so I added it. Bug: T234227 Change-Id: If2978065392cd6dcf693a588bb1ce6b5d43828f2
* Convert FileBackendGroup to serviceAryeh Gregor2019-10-251-1/+4
| | | | | Bug: T234228 Change-Id: I25575f565eba122cdf971a5945572811d17fa3e1
* Add public as visibility in tests folderUmherirrender2019-10-101-2/+2
| | | | | | | Add public, protected or private to function missing a visibility Enable the tests folder for the phpcs sniff Change-Id: Ibefce76ea9984c47e08c94889ea2eafca7565e2c
* tests: Replace PHPUnit's loose assertEquals(false) with assertFalse()Thiemo Kreuz2019-10-041-20/+19
| | | | | | | | | | | | | assertEquals( false, … ) still succeeds when the actual value is 0, null, an empty string, even an empty array. All these should be reported as a failure, I would argue. Note this patch previously also touched assertSame( false ). I reverted these. The only benefit would have been consistency within this codebase, but there is no strict reason to prefer one over the other. assertFalse() and assertSame( false ) are functionally identical. Change-Id: Ic5f1c7d504e7249002d3184520012e03313137b4
* Expand testDoQuickOperations() tests for FileBackendAaron Schulz2019-09-291-57/+117
| | | | Change-Id: I0633f13f07b5a3234b9bbae4840b064972f68fd9
* tests: Replace PHPUnit's loose assertEquals(null) with assertNull()Thiemo Kreuz2019-09-271-3/+3
| | | | | | | | | | | | | assertEquals( null, … ) still succeeds when the actual value is 0, false, an empty string, even an empty array. All these should be reported as a failure, I would argue. Note this patch previously also touched assertSame( null ). I reverted these. The only benefit would have been consistency within this codebase, but there is no strict reason to prefer one over the other. assertNull() and assertSame( null ) are functionally identical. Change-Id: I92102e833a8bc6af90b9516826abf111e2b79aac
* tests: Prefer assertSame() when comparing the integer 0Thiemo Kreuz2019-09-191-1/+1
| | | | | | | assertSame() is guaranteed to not do any type conversion. This can be critical when acciden tially comparing, for example, 0 to 0.0. Change-Id: Iffcc9bda69573623ba14af655dcd697d0fcce525
* Make doTestLockCalls() fasterAaron Schulz2019-09-131-1/+1
| | | | | | | This was mostly doing many runs just to test for random lock errors in versions of Windows from a few years back. Just do three quick rounds. Change-Id: I2ec2a8ce66a5c14bfc9338b60f8a57b2de8eaece
* filebackend: optimize 'move' in FSFileBackend to avoid is_file() callsAaron Schulz2019-09-071-7/+16
| | | | | | Also, remove clearstatcache() call that is redundant with moveInternal() Change-Id: I56e6c3d91427e7d0b49011f884b77daa5eb0b61c
* filebackend: optimize 'delete' for FSFileBackend to avoid is_file() callsAaron Schulz2019-09-071-5/+6
| | | | | | This also should reduce the chance of warnings due to race conditions Change-Id: I06b6bcc5e0f009bb3d5135591d13ff098710a5b3
* filebackend: improve internal use of FileBackend constantsAaron Schulz2019-09-031-197/+261
| | | | | | | | | | | | | | | | | | | | | | Add more result constants and split up FileBackend::UNKNOWN for clarity. This follows up 5719815f3b, which added that constant. Make internal FileBackendStore::doGet* methods distinguish I/O errors from missing files; the return types of public FileBackend methods are unchanged. Avoid process caching any mtime/size/sha1 values in the case of I/O errors. Use error constants consistently for stat methods when given invalid paths. Also: * Factor out FileBackendStore::processCacheAndPersistStatEntries() method to reduce significant code duplication. * Consolidate duplicated isPathUsable() checks in FileOp subclasses to FileOp::precheck(). * Remove null process cache value check from FileBackend::getFileStat() as null values are never stored in the process cache to begin with. * Reformat some oddly wrapped lines to look cleaner. Change-Id: Id0e4b0da0bb2ed3184847b35142d587c7f3d953d
* FileJournal testsAryeh Gregor2019-09-031-2/+0
| | | | | | | | | | | | | 100% unit test coverage for FileJournal and NullFileJournal. 100% integration test coverage for DBFileJournal. Unit tests for DBFileJournal once it supports injection. I removed FileJournal and NullFileJournal from the list of classes that FileBackendTest tests. It doesn't actually test them, it just happens to run code from them without checking its correctness at all. Depends-On: Ic22075bb5e81b7c2c4c1b8647547aa55306a10a7 Change-Id: I46d10ab7b87c23937aa04d7ec1922abfcf3bd611
* tests: Remove use of wfRandomString() for test fixturesTimo Tijhof2019-05-061-5/+3
| | | | | | | | | | | | | | | | | | | | | | | This reduces confidence in the test. There is no guruantee that it won't return the same value twice during the duration of a full PHPUnit run of all test suites, whether twice in a row or 20 minutes apart. For a test that needs a string of any kind, use an explicit, consinstent and cheap literal value. For a test that specifically needs some kind of uniqueness compared to something else within the same test case, do so explicitly. Tests that require something globally unique (for some undefined/vague definition of "global") were not found, and should not exist anyway. Also, in libs/objectcache tests, fix order of parameters in some assertions (expected first, then actual), and use assertFalse/assertSame instead of assertEqual for cases where false is expected to remove tolerance of other loosely equal values. Change-Id: Ifc60e88178da471330b94bfbf12e2731d2efc77d
* Deprecate the Http classAryeh Gregor2019-05-061-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | All methods got moved to HttpRequestFactory or MWHttpRequest or dropped. I made the return value of the new HttpRequestFactory::request/get/post methods null on error instead of false, so that when we drop PHP 7 support, we can use a "?string" return value. This could theoretically change behavior of code that was switched from the old Http methods, but probably won't. I kept the old behavior for the deprecated methods. I changed the default value of $wgHTTPProxy from false to ''. This way it should be usable directly without a trivial wrapper method. For the benefit of anyone who might have set it to false in LocalSettings.php, I also recommend casting to string just in case. Http::$httpEngine is deprecated. Eventually it will be removed along with the curl and PHP engines, leaving only the Guzlle engine. I also added deprecation of MWHttpRequest::factory, which occurred in 1.31, to the release notes for 1.34. Now hopefully we can hard-deprecate it in another couple of versions. Bug: T214390 Change-Id: I2a316a758d793857f248bd251b90f5e9a6440e3a
* Remove a few obscure "done" and "empty" commentsThiemo Kreuz2019-01-301-2/+2
| | | | | | | These don't add any knowledge to what is already obvious from the code, I find. Change-Id: Ia613b6a059f78dbeefdfd020899bd1a6e239a731
* Disallow empty paths in LockManagerAaron Schulz2018-07-261-20/+21
| | | | | | Fix broken FileBackend test that had paths normalizing to null. Change-Id: I8a7e88ae44118cc9578e1b306a5a008ccefc23af
* Update suppressWarning()/restoreWarning() callsReedy2018-02-101-2/+2
| | | | | Bug: T182273 Change-Id: I9e1b628fe5949ca54258424c2e45b2fb6d491d0f
* Use ::class to resolve class names in testsUmherirrender2018-01-261-8/+8
| | | | | | | This helps to find renamed or misspelled classes earlier. Phan will check the class names Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c
* Switch to librarized version of TestingAccessWrapperGergő Tisza2017-04-201-0/+2
| | | | | | | | | | | | | | | Replaces \TestingAccessWrapper (defined in core) with \Wikimedia\TestingAccessWrapper (defined in the composer package wikimedia/testing-access-wrapper). See https://gerrit.wikimedia.org/r/#/q/topic:librarize-testing-access-wrapper for downstream patches. The core version of the class is kept around for a while to avoid circular dependency problems. Bug: T163434 Change-Id: I52cc257e593da3d6c3b01a909e554a950225aec8
* Fix @covers for FileBackendTim Starling2017-02-271-52/+38
| | | | | | | | | | | | | It's up to the developer to choose the level of granularity they are aspiring for in their test coverage. But that granularity level should be reflected in @covers. When you have hundreds of lines of code testing a single-line function (FileBackend::doOperation), that's a good hint that something went wrong. FileBackendTest is 2700 lines of code and appears to be aiming to test the whole filebackend module. So I adjusted @covers to reflect that. Change-Id: Iacd8cf475d1761c3b32c739983343619a9509d6b
* Merge "FSFile and TempFSFile cleanups"jenkins-bot2016-09-201-4/+4
|\
| * FSFile and TempFSFile cleanupsAaron Schulz2016-09-191-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | * Remove wf* function dependencies. This includes wfTempDir(). Callers now should specify the directory, though it will try to do most of the wfTempDir() logic anyway if they do not. * Update callers to inject wfTempDir() so $wgTmpDirectory is used by TempFSFile instead of it probing to find a valid directory itself. * Move most of the wfTempDir() logic to TempFSFile::getUsableTempDirectory(). * Remove unused getMimeType() method. Change-Id: Idd55936b07f9448a6c90577708722b7b52b8fe66
* | Move some FileBackend related classes to /libsAaron Schulz2016-09-191-13/+13
|/ | | | Change-Id: I0c3a84c2ed8b869519f4d38475a77539c24a88a8
* Added Range support to FileBackend::streamFile()Aaron Schulz2016-06-041-9/+57
| | | | | | | | | | | | | | | | | * Added HTTP options headers parameter to streamFile(). * Refactored doStreamFile() to either call StreamFile::stream() or delagate that to the subclass. SwiftFileBackend now relays the full Swift response rather than manually making the headers. This also makes Range headers easy to support. * Made use of this in img_auth.php for performance on private wikis. * Elimate stat call in streamFile() for Swift if "headers" is empty. * Refactored StreamFile a bit to inject request headers instead of using the $_SERVER global. A header options parameter is used instead, which also supports Range. * Removed now unused prepareForStream(). * Cleaned up streamFile() unit tests. Change-Id: I2ccbcbca6caabb8cf65bd6b3084cede2e6ea628a
* Many more function case mismatchesReedy2016-03-191-2/+2
| | | | Change-Id: I5d3a5eb8adea1ecbf136415bb9fd7a162633ccca
* Fix numerous class/function casingReedy2016-03-181-1/+1
| | | | Change-Id: I23982bfa0548c9ea3bdb432be7982f1563930715
* Convert all array() syntax to []Kunal Mehta2016-02-171-539/+539
| | | | | | | | | | Per wikitech-l consensus: https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html Notes: * Disabled CallTimePassByReference due to false positives (T127163) Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
* Merge "tests: Clean up use of mt_rand()"jenkins-bot2015-12-061-2/+1
|\
| * tests: Clean up use of mt_rand()Timo Tijhof2015-12-031-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | * ApiQueryTest: One random is enough. * FileBackendTest: More consistent and idiomatic via wfRandomString() * MigrateFileRepoLayoutTest: Use getNewTempDirectory(). Similar to what FileBackendTest used already. * UploadFromUrlTestSuite: Use getNewTempDirectory(). Change-Id: I772de2134be41506d8ed08367be8c18f354bfc72
* | Remove DeferredUpdates::forceDeferral() testing hackAaron Schulz2015-12-041-7/+1
|/ | | | Change-Id: I7f2ad8190e1a746b6c39190b86fa9c83c5b921fe
* Replace wfBaseConvert with Wikimedia\base_convertReedy2015-11-241-3/+3
| | | | Change-Id: Iadab3d018c3559daf79be90edb23d131729bdb68
* Merge "Improve MIME detection in FileBackend"jenkins-bot2015-11-031-0/+36
|\
| * Improve MIME detection in FileBackendAaron Schulz2015-11-021-0/+36
| | | | | | | | | | | | | | | | | | The content type detector will now inspect the file contents to better handle extensionless files. Also dependency inject the callback and make the default one use FileInfo. Change-Id: Iad59bf6c6a416b706f976a4c425763fd30e2debb
* | Normalize header case for FileBackend operationsAaron Schulz2015-10-271-0/+31
|/ | | | | | | | Normalize all headers to lower case at the start of the FileBackend operation methods. This makes it easy for subclasses to check for certain headers, e.g. content-type. Change-Id: Ia69976326d17a51bcaa61f2781aa669ae7bd9c28
* Added replication=async option to FileBackendMultiWriteAaron Schulz2015-10-011-0/+53
| | | | | | | | * This will defer writes to non-master backends till the end up the web request. This is useful for multi-DC setups. Bug: T112708 Change-Id: I118c07764dd4a4f4f2590d4548238df12860e750
* Fix issues identified by SpaceBeforeSingleLineComment sniffVivek Ghaisas2015-09-261-2/+2
| | | | Change-Id: I048ccb1fa260e4b7152ca5f09b053defdd72d8f9
* Added read affinity tests for FileBackendMultiWriteAaron Schulz2015-09-211-0/+50
| | | | Change-Id: I1407273175396d4d3631531ff0ca0afa3009913e
* Replace use of assertType with assertInternalType and assertInstanceOfaude2015-04-091-1/+1
| | | | | | | | | | | | | | | | These are available in phpunit since 3.5.0, which I think is reasonable to expect people to have at this point, especially when we actually require 3.7.0 or higher in phpunit.php: Use assertSame instead of assertArrayEquals in UIDGeneratorTest. assertSame (and assertEqual) care about sortorder of the array, and is perfectly sufficient in this case to check they array is correct. if ( $puVersion !== '@package_version@' && version_compare( $puVersion, '3.7.0', '<' ) ) { die( "PHPUnit 3.7.0 or later required; you have {$puVersion}.\n" ); } Change-Id: Ic32ab45110e4c4304ef046ae8d0e98c741255559
* Profile all external HTTP requests from MWChad Horohoe2015-03-031-1/+1
| | | | Change-Id: Ie980b080da2ef21ec7d9fc32f1accc55710de140
* Use MediaWikiTestCase methods for tempdir in unit testsTimo Tijhof2015-02-111-48/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Use MediaWikiTestCase::getNewTempFile and getNewTempDirectory instead of wfTempDir(). The upload api tests wrote a tempnam() file directly (where wfTempDir() is typically shared with other systems and concurrent runs). Use MediaWikiTestCase::getNewTempFile and getNewTempDirectory instead. This also ensures its removal by the teardown handler without needing manual unlink() calls. And it doesn't rely on the test passing. (Many unlink calls where at the bottom of tests, which wouldn't be reached in case of failure). * For the upload test, the presistent storing of 'Oberaargletscher_from_Oberaar.jpg' (downloaded from Commons) was removed. Note that this didn't work for Jenkins builds anyway as Jenkins builds set $wgTmpDirectory to a unique directory in tmpfs associated with an individual build. * For filebackend tests, moved directory creation from the dataProvider to the main test. Implemented addTmpFiles() to allow subclasses to register additional files (created by other means) to be cleaned up also. Removed unused $tmpName and $toPath parameters in data provider for FileBackendTest::testStore. And fixed weird double $op2 variable name to be called $op3. * Skipped parserTest.inc, MockFileBackend.php, and UploadFromUrlTestSuite.php as those don't use MediaWikiTestCase. Change-Id: Ic7feb06ef0c1006eb99485470a1a59419f972545
* Remove MediaWikiPHPUnitCommandaddshore2014-08-021-2/+2
| | | | | | All functionality has been moved to other places Change-Id: I6b6b0ef846bc63108c4dff9e17098432fd9d1697
* Pass phpcs-strict on some test files (7/11)Siebrand Mazeland2014-04-241-17/+78
| | | | Change-Id: Ia0ceea60e7ef43959f868378f3fcd463a3adf782
* Fixed broken filebackend test for "describe"Aaron Schulz2014-04-151-0/+1
| | | | Change-Id: I30e3cfc29a1db92e7f1b85af54db778ee639e016
* Fixed wrong usage of $tmpFile in Swift backendAaron Schulz2014-01-151-2/+2
| | | | Change-Id: I21293be38c53b4dca3030c26a201f70d8ed243f3
* Merge "filebackend: Added supported for retrieving file metadata/headers"jenkins-bot2014-01-091-3/+35
|\
| * filebackend: Added supported for retrieving file metadata/headersAaron Schulz2014-01-081-3/+35
| | | | | | | | | | | | | | * This can be useful for carrying over metadata when copying files around * Also fixed a bug in sanitizeHdrs() for Swift (broken content-disposition) Change-Id: I4534e9acac2b306086797b3677f85c05b98e39fc
* | Fixed minor unit test dir leakageAaron Schulz2014-01-081-1/+1
|/ | | | Change-Id: I78cf483dde5078d4fad4e1738d8bb8a8f634e3b1
* Removed cloudfiles dependency in SwiftFileBackendAaron Schulz2014-01-071-2/+22
| | | | | | | | | | | | | | | | | | | | | | | * Added a new curl multi wrapper under libs/. * Used the new MultiHttpClient class instead of CloudFiles * Removed CDN related config and code as it does not work. well due to mutating files and tiny purge rate limits by CDNs. * Also removed the unused and esoteric 'swiftAnonUser' parameter. * Support concurrent 'describe' operations. * Set ACLs on containers on intial PUT instead of in two steps. Previously if the second step failed, prepare() would never set the ACLs correctly since it aborts if the container exists. * Improve token deletion to only trigger on 401s rather than other random errors like 50X timeouts. * Removed duplicative getResponse* code by just using one closure called for both the concurrent and serial cases. Both cases are now funneled through doExecuteOpHandlesInternal(). * Add the MD5 to stat info, as it might be useful for speeding up the copy scripts in some cases (when both backends have md5 set). * Avoid use of trigger_error() since there is a swift log group. * A few other small code cleanups. Change-Id: I1adb3e2df6df8cf01d3ad74158de96ea9a79da2e
* Fixed undefined variable errors that made tests failAaron Schulz2013-12-181-1/+3
| | | | Change-Id: Ic004e0d8d8efe3e4b313b737479b8098aa0048bc
* Added streamFile() unit testsAaron Schulz2013-12-171-0/+51
| | | | Change-Id: I2ef5680829048ab4fcc0a9f7ff9064d016800217