diff --git a/src/Wrapper/SplFileInfo.php b/src/Wrapper/SplFileInfo.php index 1dac665..52619fa 100644 --- a/src/Wrapper/SplFileInfo.php +++ b/src/Wrapper/SplFileInfo.php @@ -40,8 +40,11 @@ public static function of(string $file, string $relativePath, string $relativePa public function toLog(): array { return [ - 'pathname' => $this->pathname(), + 'filename' => $this->filename()->toString(), + 'extension' => $this->extension()->toString(), 'size' => $this->size()->humanReadable(), + 'relativePath' => $this->relativePath()->toString(), + 'relativePathname' => $this->relativePathname()->toString(), ]; } diff --git a/tests/Unit/Wrapper/SplFileInfoTest.php b/tests/Unit/Wrapper/SplFileInfoTest.php new file mode 100644 index 0000000..c8fabf1 --- /dev/null +++ b/tests/Unit/Wrapper/SplFileInfoTest.php @@ -0,0 +1,102 @@ +toLog(); + self::assertArrayHasKey('filename', $result, 'toLog() must contain filename key'); + } + + public function testToLogReturnsArrayWithExtensionKey(): void + { + $file = SplFileInfo::of(__FILE__, '', ''); + $result = $file->toLog(); + self::assertArrayHasKey('extension', $result, 'toLog() must contain extension key'); + } + + public function testToLogReturnsArrayWithSizeKey(): void + { + $file = SplFileInfo::of(__FILE__, '', ''); + $result = $file->toLog(); + self::assertArrayHasKey('size', $result, 'toLog() must contain size key'); + } + + public function testToLogReturnsArrayWithRelativePathKey(): void + { + $file = SplFileInfo::of(__FILE__, '', ''); + $result = $file->toLog(); + self::assertArrayHasKey('relativePath', $result, 'toLog() must contain relativePath key'); + } + + public function testToLogReturnsArrayWithRelativePathnameKey(): void + { + $file = SplFileInfo::of(__FILE__, '', ''); + $result = $file->toLog(); + self::assertArrayHasKey('relativePathname', $result, 'toLog() must contain relativePathname key'); + } + + public function testToLogFilenameIsString(): void + { + $file = SplFileInfo::of(__FILE__, '', ''); + $result = $file->toLog(); + self::assertIsString($result['filename'], 'filename must be a string'); + } + + public function testToLogExtensionIsString(): void + { + $file = SplFileInfo::of(__FILE__, '', ''); + $result = $file->toLog(); + self::assertIsString($result['extension'], 'extension must be a string'); + } + + public function testToLogSizeIsString(): void + { + $file = SplFileInfo::of(__FILE__, '', ''); + $result = $file->toLog(); + self::assertIsString($result['size'], 'size must be a string'); + } + + public function testToLogRelativePathIsString(): void + { + $file = SplFileInfo::of(__FILE__, '', ''); + $result = $file->toLog(); + self::assertIsString($result['relativePath'], 'relativePath must be a string'); + } + + public function testToLogRelativePathnameIsString(): void + { + $file = SplFileInfo::of(__FILE__, '', ''); + $result = $file->toLog(); + self::assertIsString($result['relativePathname'], 'relativePathname must be a string'); + } + + public function testToLogFilenameMatchesActualFilename(): void + { + $file = SplFileInfo::of(__FILE__, '', ''); + $result = $file->toLog(); + self::assertEquals('SplFileInfoTest.php', $result['filename'], 'filename must match actual filename'); + } + + public function testToLogExtensionMatchesActualExtension(): void + { + $file = SplFileInfo::of(__FILE__, '', ''); + $result = $file->toLog(); + self::assertEquals('php', $result['extension'], 'extension must match php'); + } + + public function testToLogSizeContainsUnit(): void + { + $file = SplFileInfo::of(__FILE__, '', ''); + $result = $file->toLog(); + self::assertMatchesRegularExpression('/\d+(\.\d+)?\s*(B|KB|MB|GB)/', $result['size'], 'size must contain unit'); + } +}