aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files/Storage/Storage.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Files/Storage/Storage.php')
-rw-r--r--tests/lib/Files/Storage/Storage.php136
1 files changed, 61 insertions, 75 deletions
diff --git a/tests/lib/Files/Storage/Storage.php b/tests/lib/Files/Storage/Storage.php
index 0a170a0e7d5..51bb5b7c8ad 100644
--- a/tests/lib/Files/Storage/Storage.php
+++ b/tests/lib/Files/Storage/Storage.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -8,6 +9,8 @@
namespace Test\Files\Storage;
use OC\Files\Cache\Watcher;
+use OC\Files\Storage\Wrapper\Wrapper;
+use OCP\Files\Storage\IStorage;
use OCP\Files\Storage\IWriteStreamStorage;
abstract class Storage extends \Test\TestCase {
@@ -30,7 +33,7 @@ abstract class Storage extends \Test\TestCase {
/**
* the root folder of the storage should always exist, be readable and be recognized as a directory
*/
- public function testRoot() {
+ public function testRoot(): void {
$this->assertTrue($this->instance->file_exists('/'), 'Root folder does not exist');
$this->assertTrue($this->instance->isReadable('/'), 'Root folder is not readable');
$this->assertTrue($this->instance->is_dir('/'), 'Root folder is not a directory');
@@ -44,14 +47,12 @@ abstract class Storage extends \Test\TestCase {
/**
* Check that the test() function works
*/
- public function testTestFunction() {
+ public function testTestFunction(): void {
$this->assertTrue($this->instance->test());
}
- /**
- * @dataProvider directoryProvider
- */
- public function testDirectories($directory) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('directoryProvider')]
+ public function testDirectories($directory): void {
$this->assertFalse($this->instance->file_exists('/' . $directory));
$this->assertTrue($this->instance->mkdir('/' . $directory));
@@ -66,7 +67,7 @@ abstract class Storage extends \Test\TestCase {
$dh = $this->instance->opendir('/');
$content = [];
- while ($file = readdir($dh)) {
+ while (($file = readdir($dh)) !== false) {
if ($file != '.' and $file != '..') {
$content[] = $file;
}
@@ -99,7 +100,7 @@ abstract class Storage extends \Test\TestCase {
$dh = $this->instance->opendir('/');
$content = [];
- while ($file = readdir($dh)) {
+ while (($file = readdir($dh)) !== false) {
if ($file != '.' and $file != '..') {
$content[] = $file;
}
@@ -107,7 +108,7 @@ abstract class Storage extends \Test\TestCase {
$this->assertEquals([], $content);
}
- public function fileNameProvider() {
+ public static function fileNameProvider(): array {
return [
['file.txt'],
[' file.txt'],
@@ -118,7 +119,7 @@ abstract class Storage extends \Test\TestCase {
];
}
- public function directoryProvider() {
+ public static function directoryProvider(): array {
return [
['folder'],
[' folder'],
@@ -129,7 +130,7 @@ abstract class Storage extends \Test\TestCase {
];
}
- public function loremFileProvider() {
+ public static function loremFileProvider(): array {
$root = \OC::$SERVERROOT . '/tests/data/';
return [
// small file
@@ -141,10 +142,9 @@ abstract class Storage extends \Test\TestCase {
/**
* test the various uses of file_get_contents and file_put_contents
- *
- * @dataProvider loremFileProvider
*/
- public function testGetPutContents($sourceFile) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('loremFileProvider')]
+ public function testGetPutContents($sourceFile): void {
$sourceText = file_get_contents($sourceFile);
//fill a file with string data
@@ -160,7 +160,7 @@ abstract class Storage extends \Test\TestCase {
/**
* test various known mimetypes
*/
- public function testMimeType() {
+ public function testMimeType(): void {
$this->assertEquals('httpd/unix-directory', $this->instance->getMimeType('/'));
$this->assertEquals(false, $this->instance->getMimeType('/non/existing/file'));
@@ -178,7 +178,7 @@ abstract class Storage extends \Test\TestCase {
}
- public function copyAndMoveProvider() {
+ public static function copyAndMoveProvider(): array {
return [
['/source.txt', '/target.txt'],
['/source.txt', '/target with space.txt'],
@@ -209,10 +209,8 @@ abstract class Storage extends \Test\TestCase {
);
}
- /**
- * @dataProvider copyAndMoveProvider
- */
- public function testCopy($source, $target) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')]
+ public function testCopy($source, $target): void {
$this->initSourceAndTarget($source);
$this->instance->copy($source, $target);
@@ -222,10 +220,8 @@ abstract class Storage extends \Test\TestCase {
$this->assertTrue($this->instance->file_exists($source), $source . ' was deleted');
}
- /**
- * @dataProvider copyAndMoveProvider
- */
- public function testMove($source, $target) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')]
+ public function testMove($source, $target): void {
$this->initSourceAndTarget($source);
$this->instance->rename($source, $target);
@@ -236,10 +232,8 @@ abstract class Storage extends \Test\TestCase {
$this->assertSameAsLorem($target);
}
- /**
- * @dataProvider copyAndMoveProvider
- */
- public function testCopyOverwrite($source, $target) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')]
+ public function testCopyOverwrite($source, $target): void {
$this->initSourceAndTarget($source, $target);
$this->instance->copy($source, $target);
@@ -250,10 +244,8 @@ abstract class Storage extends \Test\TestCase {
$this->assertSameAsLorem($source);
}
- /**
- * @dataProvider copyAndMoveProvider
- */
- public function testMoveOverwrite($source, $target) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')]
+ public function testMoveOverwrite($source, $target): void {
$this->initSourceAndTarget($source, $target);
$this->instance->rename($source, $target);
@@ -263,7 +255,7 @@ abstract class Storage extends \Test\TestCase {
$this->assertSameAsLorem($target);
}
- public function testLocal() {
+ public function testLocal(): void {
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));
$localFile = $this->instance->getLocalFile('/lorem.txt');
@@ -290,7 +282,7 @@ abstract class Storage extends \Test\TestCase {
$this->assertEquals(file_get_contents($localFile), 'foo');
}
- public function testStat() {
+ public function testStat(): void {
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$ctimeStart = time();
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));
@@ -325,8 +317,8 @@ abstract class Storage extends \Test\TestCase {
* Test whether checkUpdate properly returns false when there was
* no change.
*/
- public function testCheckUpdate() {
- if ($this->instance instanceof \OC\Files\Storage\Wrapper\Wrapper) {
+ public function testCheckUpdate(): void {
+ if ($this->instance instanceof Wrapper) {
$this->markTestSkipped('Cannot test update check on wrappers');
}
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
@@ -337,7 +329,7 @@ abstract class Storage extends \Test\TestCase {
$this->assertFalse($watcher->checkUpdate('/lorem.txt'), 'No update');
}
- public function testUnlink() {
+ public function testUnlink(): void {
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));
@@ -349,10 +341,8 @@ abstract class Storage extends \Test\TestCase {
$this->assertFalse($this->instance->file_exists('/lorem.txt'));
}
- /**
- * @dataProvider fileNameProvider
- */
- public function testFOpen($fileName) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('fileNameProvider')]
+ public function testFOpen($fileName): void {
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$fh = @$this->instance->fopen($fileName, 'r');
@@ -372,14 +362,14 @@ abstract class Storage extends \Test\TestCase {
$this->assertEquals(file_get_contents($textFile), $content);
}
- public function testTouchCreateFile() {
+ public function testTouchCreateFile(): void {
$this->assertFalse($this->instance->file_exists('touch'));
// returns true on success
$this->assertTrue($this->instance->touch('touch'));
$this->assertTrue($this->instance->file_exists('touch'));
}
- public function testRecursiveRmdir() {
+ public function testRecursiveRmdir(): void {
$this->instance->mkdir('folder');
$this->instance->mkdir('folder/bar');
$this->wait();
@@ -393,14 +383,14 @@ abstract class Storage extends \Test\TestCase {
$this->assertFalse($this->instance->file_exists('folder'));
}
- public function testRmdirEmptyFolder() {
+ public function testRmdirEmptyFolder(): void {
$this->assertTrue($this->instance->mkdir('empty'));
$this->wait();
$this->assertTrue($this->instance->rmdir('empty'));
$this->assertFalse($this->instance->file_exists('empty'));
}
- public function testRecursiveUnlink() {
+ public function testRecursiveUnlink(): void {
$this->instance->mkdir('folder');
$this->instance->mkdir('folder/bar');
$this->instance->file_put_contents('folder/asd.txt', 'foobar');
@@ -413,7 +403,7 @@ abstract class Storage extends \Test\TestCase {
$this->assertFalse($this->instance->file_exists('folder'));
}
- public function hashProvider() {
+ public static function hashProvider(): array {
return [
['Foobar', 'md5'],
['Foobar', 'sha1'],
@@ -421,16 +411,14 @@ abstract class Storage extends \Test\TestCase {
];
}
- /**
- * @dataProvider hashProvider
- */
- public function testHash($data, $type) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('hashProvider')]
+ public function testHash($data, $type): void {
$this->instance->file_put_contents('hash.txt', $data);
$this->assertEquals(hash($type, $data), $this->instance->hash($type, 'hash.txt'));
$this->assertEquals(hash($type, $data, true), $this->instance->hash($type, 'hash.txt', true));
}
- public function testHashInFileName() {
+ public function testHashInFileName(): void {
$this->instance->file_put_contents('#test.txt', 'data');
$this->assertEquals('data', $this->instance->file_get_contents('#test.txt'));
@@ -449,14 +437,14 @@ abstract class Storage extends \Test\TestCase {
$this->assertEquals(['test.txt'], $content);
}
- public function testCopyOverWriteFile() {
+ public function testCopyOverWriteFile(): void {
$this->instance->file_put_contents('target.txt', 'foo');
$this->instance->file_put_contents('source.txt', 'bar');
$this->instance->copy('source.txt', 'target.txt');
$this->assertEquals('bar', $this->instance->file_get_contents('target.txt'));
}
- public function testRenameOverWriteFile() {
+ public function testRenameOverWriteFile(): void {
$this->instance->file_put_contents('target.txt', 'foo');
$this->instance->file_put_contents('source.txt', 'bar');
$this->instance->rename('source.txt', 'target.txt');
@@ -464,7 +452,7 @@ abstract class Storage extends \Test\TestCase {
$this->assertFalse($this->instance->file_exists('source.txt'));
}
- public function testRenameDirectory() {
+ public function testRenameDirectory(): void {
$this->instance->mkdir('source');
$this->instance->file_put_contents('source/test1.txt', 'foo');
$this->instance->file_put_contents('source/test2.txt', 'qwerty');
@@ -492,7 +480,7 @@ abstract class Storage extends \Test\TestCase {
$this->assertEquals('bar', $this->instance->file_get_contents('target/subfolder/test.txt'));
}
- public function testRenameOverWriteDirectory() {
+ public function testRenameOverWriteDirectory(): void {
$this->instance->mkdir('source');
$this->instance->file_put_contents('source/test1.txt', 'foo');
@@ -508,7 +496,7 @@ abstract class Storage extends \Test\TestCase {
$this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt'), 'target/test1.txt has not been overwritten');
}
- public function testRenameOverWriteDirectoryOverFile() {
+ public function testRenameOverWriteDirectoryOverFile(): void {
$this->instance->mkdir('source');
$this->instance->file_put_contents('source/test1.txt', 'foo');
@@ -521,7 +509,7 @@ abstract class Storage extends \Test\TestCase {
$this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt'));
}
- public function testCopyDirectory() {
+ public function testCopyDirectory(): void {
$this->instance->mkdir('source');
$this->instance->file_put_contents('source/test1.txt', 'foo');
$this->instance->file_put_contents('source/test2.txt', 'qwerty');
@@ -546,7 +534,7 @@ abstract class Storage extends \Test\TestCase {
$this->assertEquals('bar', $this->instance->file_get_contents('target/subfolder/test.txt'));
}
- public function testCopyOverWriteDirectory() {
+ public function testCopyOverWriteDirectory(): void {
$this->instance->mkdir('source');
$this->instance->file_put_contents('source/test1.txt', 'foo');
@@ -556,11 +544,11 @@ abstract class Storage extends \Test\TestCase {
$this->instance->copy('source', 'target');
- $this->assertFalse($this->instance->file_exists('target/test2.txt'));
+ $this->assertFalse($this->instance->file_exists('target/test2.txt'), 'File target/test2.txt should no longer exist, but does');
$this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt'));
}
- public function testCopyOverWriteDirectoryOverFile() {
+ public function testCopyOverWriteDirectoryOverFile(): void {
$this->instance->mkdir('source');
$this->instance->file_put_contents('source/test1.txt', 'foo');
@@ -571,16 +559,14 @@ abstract class Storage extends \Test\TestCase {
$this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt'));
}
- public function testInstanceOfStorage() {
- $this->assertTrue($this->instance->instanceOfStorage('\OCP\Files\Storage'));
+ public function testInstanceOfStorage(): void {
+ $this->assertTrue($this->instance->instanceOfStorage(IStorage::class));
$this->assertTrue($this->instance->instanceOfStorage(get_class($this->instance)));
$this->assertFalse($this->instance->instanceOfStorage('\OC'));
}
- /**
- * @dataProvider copyAndMoveProvider
- */
- public function testCopyFromSameStorage($source, $target) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')]
+ public function testCopyFromSameStorage($source, $target): void {
$this->initSourceAndTarget($source);
$this->instance->copyFromStorage($this->instance, $source, $target);
@@ -590,32 +576,32 @@ abstract class Storage extends \Test\TestCase {
$this->assertTrue($this->instance->file_exists($source), $source . ' was deleted');
}
- public function testIsCreatable() {
+ public function testIsCreatable(): void {
$this->instance->mkdir('source');
$this->assertTrue($this->instance->isCreatable('source'));
}
- public function testIsReadable() {
+ public function testIsReadable(): void {
$this->instance->mkdir('source');
$this->assertTrue($this->instance->isReadable('source'));
}
- public function testIsUpdatable() {
+ public function testIsUpdatable(): void {
$this->instance->mkdir('source');
$this->assertTrue($this->instance->isUpdatable('source'));
}
- public function testIsDeletable() {
+ public function testIsDeletable(): void {
$this->instance->mkdir('source');
$this->assertTrue($this->instance->isDeletable('source'));
}
- public function testIsShareable() {
+ public function testIsShareable(): void {
$this->instance->mkdir('source');
$this->assertTrue($this->instance->isSharable('source'));
}
- public function testStatAfterWrite() {
+ public function testStatAfterWrite(): void {
$this->instance->file_put_contents('foo.txt', 'bar');
$stat = $this->instance->stat('foo.txt');
$this->assertEquals(3, $stat['size']);
@@ -628,13 +614,13 @@ abstract class Storage extends \Test\TestCase {
$this->assertEquals(6, $stat['size']);
}
- public function testPartFile() {
+ public function testPartFile(): void {
$this->instance->file_put_contents('bar.txt.part', 'bar');
$this->instance->rename('bar.txt.part', 'bar.txt');
$this->assertEquals('bar', $this->instance->file_get_contents('bar.txt'));
}
- public function testWriteStream() {
+ public function testWriteStream(): void {
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
if (!$this->instance->instanceOfStorage(IWriteStreamStorage::class)) {
@@ -651,7 +637,7 @@ abstract class Storage extends \Test\TestCase {
$this->assertEquals('resource (closed)', gettype($source));
}
- public function testFseekSize() {
+ public function testFseekSize(): void {
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$this->instance->file_put_contents('bar.txt', file_get_contents($textFile));