From 1ba1653265069360ae414dd79961ffca3cf516ed Mon Sep 17 00:00:00 2001 From: Phillip Davis Date: Thu, 16 Jul 2026 16:11:23 +0930 Subject: [PATCH] test: enhance the Storage directory test output This unit test has a lot of assertions about the directory-under-test as it is created, deleted etc. Currently, if the test fails then there is just a message like "Failed asserting that false is true." This change adds descriptive messages for each unit test assertion. That will make it easier to know at which step the test failed. Signed-off-by: Phillip Davis --- tests/lib/Files/Storage/Storage.php | 72 +++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 13 deletions(-) diff --git a/tests/lib/Files/Storage/Storage.php b/tests/lib/Files/Storage/Storage.php index 7de43918e08c..dbe8ae79f78e 100644 --- a/tests/lib/Files/Storage/Storage.php +++ b/tests/lib/Files/Storage/Storage.php @@ -66,17 +66,51 @@ public function testTestFunction() { * @dataProvider directoryProvider */ public function testDirectories($directory) { - $this->assertFalse($this->instance->file_exists('/' . $directory)); + $this->assertFalse( + $this->instance->file_exists('/' . $directory), + "The folder '$directory' already exists at the start of the test" + ); - $this->assertTrue($this->instance->mkdir('/' . $directory)); + $this->assertTrue( + $this->instance->mkdir('/' . $directory), + "The folder '$directory' could not be created" + ); - $this->assertTrue($this->instance->file_exists('/' . $directory)); - $this->assertTrue($this->instance->is_dir('/' . $directory)); - $this->assertFalse($this->instance->is_file('/' . $directory)); - $this->assertEquals('dir', $this->instance->filetype('/' . $directory)); - $this->assertEquals(0, $this->instance->filesize('/' . $directory)); - $this->assertTrue($this->instance->isReadable('/' . $directory)); - $this->assertTrue($this->instance->isUpdatable('/' . $directory)); + $this->assertTrue( + $this->instance->file_exists('/' . $directory), + "The folder '$directory' does not exist" + ); + $this->assertTrue( + $this->instance->is_dir('/' . $directory), + "The folder '$directory' is not a directory" + ); + $this->assertFalse( + $this->instance->is_file('/' . $directory), + "The folder '$directory' is actually a file" + ); + $fileType = $this->instance->filetype('/' . $directory); + if ($fileType === false) { + $this->fail("The file type of folder '$directory' could not be determined"); + } + $this->assertEquals( + 'dir', + $fileType, + "The folder '$directory' is file type $fileType, not 'dir'" + ); + $fileSize = $this->instance->filesize('/' . $directory); + $this->assertEquals( + 0, + $fileSize, + "The empty folder '$directory' has non-zero size " . (string) $fileSize + ); + $this->assertTrue( + $this->instance->isReadable('/' . $directory), + "The folder '$directory' is not readable" + ); + $this->assertTrue( + $this->instance->isUpdatable('/' . $directory), + "The folder '$directory' is not updatable" + ); $dh = $this->instance->opendir('/'); $content = []; @@ -87,13 +121,25 @@ public function testDirectories($directory) { } $this->assertEquals([$directory], $content); - $this->assertFalse($this->instance->mkdir('/' . $directory)); //can't create existing folders - $this->assertTrue($this->instance->rmdir('/' . $directory)); + $this->assertFalse( + $this->instance->mkdir('/' . $directory), + "The folder '$directory' could be created again when it already exists" + ); //can't create existing folders + $this->assertTrue( + $this->instance->rmdir('/' . $directory), + "The folder '$directory' could not be deleted" + ); $this->wait(); - $this->assertFalse($this->instance->file_exists('/' . $directory)); + $this->assertFalse( + $this->instance->file_exists('/' . $directory), + "The folder '$directory' still exists after deleting it" + ); - $this->assertFalse($this->instance->rmdir('/' . $directory)); //can't remove non existing folders + $this->assertFalse( + $this->instance->rmdir('/' . $directory), + "The folder '$directory' could be deleted again even though it was just deleted" + ); //can't remove non-existing folders $dh = $this->instance->opendir('/'); $content = [];